#!/bin/sh # # Script to process diagnostic debug (TSC) from xorp. # Each event is a pair of 32-bit numbers, first one is the timestamp, second one is # class:4 unit:4 event:8 argument:16 # while [ true ] ; do case $1 in -us) # compute times in microseconds VARS="${VARS} -v use_us=1 -v cpuspeed=$2" shift ;; *) #unrecognised break 2 ;; esac shift done if [ "$1" = dump ] ; then # tsc.sh dump ssh flag@$2 sysctl -b debug.timestamp > $3 exit 0 elif [ -f "$1" ] ; then SRC="cat $1" else SRC="ssh root@$1 sysctl -b debug.timestamp" fi eval ${SRC} | hexdump -e '"%15u %15u\n"' | \ awk ${VARS} ' BEGIN { do_skip=0 # set if you want to skip some events hs="0123456789abcdef"; # hex string #cpuspeed=750 # cpu speed in MHz theclass[0] = "kernel"; # misc kernel tasks ev[0,1] = "INTR-beg"; # global intr start ev[0,2] = "INTR-bef-call"; # global intr end ev[0,3] = "INTR-aft-call"; ev[0,4] = "INTR-end"; ev[0,5] = "INTR-start"; ev[0,6] = "INTR-end"; ev[0,7] = "lapic-beg"; ev[0,8] = "lapic-end"; ev[0,9] = "atpic-beg"; ev[0,10] = "atpic-end"; ev[0,11] = "intr_exech-beg"; ev[0,12] = "intr_exech-end"; ev[0,17] = "intr_sched-beg"; ev[0,18] = "intr_sched-end"; ev[0,19] = "intr_pdis-beg" ev[0,20] = "intr_pdis-end" ev[0,21] = "intr_peoi-beg" ev[0,22] = "intr_peoi-end" ev[0,23] = "mi_swi-beg" ev[0,24] = "mi_swi-end" ev[0,25] = "mi_swi_sw-beg" ev[0,26] = "mi_swi_sw-end" ev[0,27] = "mi_swi_binu-beg" ev[0,28] = "mi_swi_binu-end" ev[0,29] = "rq-beg" ev[0,30] = "rq_sadd-beg" ev[0,31] = "rq_sadd-end" ev[0,32] = "rq_-mid" ev[0,33] = "rq_-mid2" ev[0,34] = "rq_mid3" ev[0,35] = "rq_end" ev[0,36] = "sadd_smp-beg" ev[0,37] = "sadd_smp-end" ev[0,38] = "sadd_smp-38" ev[0,39] = "sadd_smp-39" ev[0,40] = "sadd_smp-40" ev[0,41] = "sadd_smp-41" ev[0,42] = "sadd_smp-42" ev[0,43] = "sadd_smp-43" ev[0,44] = "sadd_smp-44" ev[0,45] = "sadd_smp-45" ev[0,46] = "sadd_smp-46" ev[0,47] = "sadd_smp-47" ev[0,48] = "sadd_smp-48" ev[0,49] = "sadd_smp-49" ev[0,50] = "sadd_smp-50" ev[0,51] = "sadd_smp-51" ev[0,52] = "sadd_smp-52" ev[0,53] = "sadd_uni-beg" ev[0,54] = "sadd_uni-end" ev[0,55] = "sadd_uni-55" ev[0,56] = "sadd_uni-56" ev[0,57] = "sadd_uni-57" ev[0,58] = "sadd_uni-58" ev[0,59] = "sadd_uni-59" ev[0,60] = "mpree-beg" ev[0,61] = "mpree-end" ev[0,62] = "mpree-62" ev[0,63] = "mpree-63" ev[0,64] = "mpree-64" ev[0,65] = "mpree-65" ev[0,66] = "mpree-66" ev[0,67] = "mpree-67" ev[0,68] = "mpree-68" ev[0,69] = "idloop-beg" # idle thread ev[0,70] = "idloop-end" ev[0,71] = "idloop-aft-srun" ev[0,72] = "idloop-aft-cidle" ev[0,73] = "idloop-mid" ev[0,74] = "idloop-bef-mswi" ev[0,75] = "idloop-aft-mswi" ev[0,76] = "itloop-beg" # ithread loop ev[0,77] = "itloop-end" ev[0,78] = "itloop-exec-beg" ev[0,79] = "itloop-exec-end" ev[0,80] = "cidle-aft-dintr" ev[0,81] = "cidle-aft-eintr" ev[0,82] = "cidle-aft-ihook" ev[0,83] = "ack-mask-int" ev[0,84] = "unmask-int" theclass[1] = "net"; # misc net/* ev[1,20] = "udp_send start"; ev[1,21] = "udp_output end"; ev[1,22] = "udp_output error"; ev[1,30] = "ip_output start"; ev[1,31] = "ip_output done"; ev[1,32] = "ip_output before ipfw"; ev[1,33] = "ip_output after ipfw"; ev[1,40] = "sosend start"; ev[1,41] = "sosend end"; theclass[2] = "dc"; ev[2,0] = "_intr begin" ; ev[2,1] = "_intr post CSR_READ" ; ev[2,3] = "_intr pre-dc_start" ; ev[2,4] = "_intr loop, status=" ; ev[2,5] = "_intr txidle, tx_cnt=" ; ev[2,7] = "_intr pre_ei" ; ev[2,8] = "_intr post_ei, txcnt=" ; ev[2,9] = "_intr end" ; ev[2,10] = "_start begin ifq_len="; ev[2,11] = "_start begin idx="; ev[2,12] = "_start encap_fail,txfull cnt="; ev[2,13] = "_txeof !OACTIVE cnt="; ev[2,18] = "_start end, nosent"; ev[2,19] = "_start end, sent="; ev[2,20] = "_txeof begin tx_cnt="; ev[2,21] = "_txeof loop idx="; skip[2,21]=1; ev[2,22] = "_txeof txstat="; ev[2,23] = "_txeof DC_OWN="; ev[2,24] = "_txeof !DC_OWN="; ev[2,24] = "_txeof DC_OWN end i="; ev[2,28] = "_txeof end, cnt="; ev[2,29] = "_txeof end, drained="; ev[2,30] = "_rx_resync begin pos="; ev[2,31] = "_rx_resync end, pos="; ev[2,34] = "_poll start"; ev[2,35] = "_poll rxdrop1"; ev[2,36] = "_poll rxdrop2"; ev[2,37] = "_poll nomoretx"; ev[2,38] = "_poll nomorerx"; ev[2,39] = "_rxeof begin have"; ev[2,40] = "_rxeof begin prod="; ev[2,41] = "_rxeof loop prod="; ev[2,42] = "_rxeof bef. eth_input"; ev[2,43] = "_rxeof bef. devget"; ev[2,44] = "_rxeof bef. newbuf"; ev[2,45] = "_rxeof aft. newbuf"; ev[2,49] = "_rxeof end, prod="; ev[2,50] = "_encap shiftback "; ev[2,51] = "_encap move "; ev[2,52] = "_encap frag busy="; ev[2,60] = "_coal size="; ev[2,71] = "_newbuf before MGETHDR"; ev[2,72] = "_newbuf before MCLGET"; ev[2,73] = "_newbuf before m_adj"; ev[2,74] = "_newbuf before vtophys"; ev[2,75] = "_newbuf end"; theclass[3] = "fxp"; ev[3,1] = "fxp_intr-start" ; ev[3,2] = "fxp_intr-stop" ; ev[3,3] = "fxp_intr-body-start" ; ev[3,4] = "fxp_intr-body-stop" ; ev[3,5] = "fxp_intr-send-start" ; ev[3,6] = "fxp_intr-send-stop" ; ev[3,7] = "fxp_intr-recv-start" ; ev[3,8] = "fxp_intr-recv-stop" ; ev[3,9] = "fxp-if_input-start" ; ev[3,10] = "fxp-if_input-stop" ; theclass[4] = "em"; ev[4,1] = "em_poll, tx_avail" ; ev[4,10] = "em_lcl begin" ; ev[4,11] = "em_lcl link" ; ev[4,12] = "em_lcl pr_link" ; ev[4,13] = "em_lcl stats" ; ev[4,14] = "em_lcl done" ; ev[4,20] = "em_start start_pkt" ; ev[4,21] = "em_start end_pkt" ; ev[4,22] = "em_start OACTIVE" ; ev[4,23] = "em_encap start, avail=" ; ev[4,24] = "em_encap end, dup=" ; theclass[5] = "ed"; ev[5,1] = "ed-beg" ; ev[5,2] = "ed-end" ; #ev[5,3] = "edintr-intr_loop-start" ; #ev[5,4] = "edintr-intr_loop-stop" ; ev[5,5] = "ed_txeof-beg" ; ev[5,6] = "ed_txeof-end" ; ev[5,7] = "ed_rxeof-beg" ; ev[5,8] = "ed_rxeof-beg" ; #ev[5,9] = "ed_rint-start" ; #ev[5,10] = "ed_rint-stop" ; theclass[6] = "bfe"; ev[6,1] = "bfe-beg" ; ev[6,2] = "bfe-end" ; ev[6,5] = "bfe_txeof-beg" ; ev[6,6] = "bfe_txeof-end" ; ev[6,7] = "bfe_rxeof-beg" ; ev[6,8] = "bfe_rxeof-end" ; ev[6,9] = "bfe-mid" ev[6,10] = "bfe-pg1" ev[6,11] = "bfe-ag1" ev[6,12] = "bfe-pg2" ev[6,13] = "bfe-ag2" isrc[0] = "timer" isrc[1] = "kbd" isrc[3] = "sio1" isrc[4] = "sio0" #isrc[5] = "vga,dc0" isrc[6] = "fdc0" isrc[7] = "lpt0" #isrc[10] = "fxp0,dc2" isrc[11] = "fxp1,usb,dc3" #isrc[12] = "fxp2,fxp3,dc1" basetime= -1; i=0; } function hexs(a, i, j) { j="" ; for (i=0; i<8 ; i++) { j = substr(hs, 1 + (a % 16), 1) "" j; if (i==3 || i==5 || i==6) j = "." j ; a = int(a / 16) ; } return j; } { _t[i] = $1 ; _ev[i] = $2 ; i++ } END { lines = i ; basetime = _t[0] ; for (i = 0; i < lines ; i++) { if (_t[i] < basetime && _t[i] != 0) { basetime = _t[i] ; basepos = i ; } } printf "### basepos %d basetime %d\n", basepos, basetime; for (_i = 0 ; _i < lines ; _i++ ) { i = int ( ( _i + basepos) % lines ) ; if (_t[i] == 0) { printf "---------------------------------------------\n"; continue; } thet = _t[i] - basetime; theev = _ev[i]; x = theev ; par = x % 65536 ; x = int(x / 65536); event = x % 256 ; x = int(x / 256); unit = x % 16 ; x =int(x / 16); class = x % 16 ; x =int(x / 16); if (do_skip && skip[class,event]==1) continue; if (prev == -1) prev = thet ; t = thet - prev ; prev = thet ; if (use_us==1) { abst= sprintf("%8.3f", thet / cpuspeed); # abs time in microseconds absdtprev= sprintf("%8.3f", (thet-prevt[class,unit,event])/cpuspeed ); } else { absdtprev= sprintf("%12u", thet-prevt[class,unit,event] ); abst= sprintf("%12u", thet); # abs time in ticks } # absdt= sprintf("%8.3f", t / cpuspeed); # delta t in microseconds absdt= sprintf("%12u", t ); # delta t in ticks # record delta from previous event in same class,unit,ev prevt[class,unit,event]= thet; # printf "%s %14d class %4d unit %4d ev %4d par %4d\n", # hexs(theev), theev, class, unit, event, par ; # printf "%10s %-22s cnt[%d]\n", absdt, ev[class,event], par if (theev == 0) { printf "------------------------------------------------------\n"; } else if (class > 0) { # printf "%10s %10s %10s %3s%-2d %-22s %5u %25s\n", abst, absdtprev, absdt, # theclass[class], unit, ev[class,event], par, hexs(theev) printf "%10s %10s %10s %3s%-2d %-22s %5u %25s %d\n", abst, absdtprev, absdt, theclass[class], unit, ev[class,event], par, hexs(theev), par } else { # printf "%10s %10s %10s intr %-8s %2d[%d] %s %25s\n", abst, absdtprev, absdt, # ev[class,event], unit, par, isrc[unit], hexs(theev) printf "%10s %10s %10s intr %-8s %2d[%d] %s %25s %d\n", abst, absdtprev, absdt, ev[class,event], unit, par, isrc[unit], hexs(theev), par } } # end for } '