📄 np_tcp_window.py
字号:
# if p.wrel != None: #print '#%d WREL %s' % (p.indx, Longstring(p.wrel)) if way == CLIENT: if p.markers & P_REL_BOSS_CWND: col = crelcol_conwin else: col = crelcol_flowwin if creling: #extend if ccurrely > self.info_yht: LINE(crelx, ccurrely, x, ccurrely, fill=ccurrelcol, tag='crel') # increase? #if not seq_gt(p.wrel, ccurrel): if p.wrel <= ccurrel: print '#%d Goof client ACK rel increase not increasing' % (p.indx) y = self.yorg - int((p.wrel - self.sseqbase)*self.sscalef) LINE(x, MAX(ccurrely, self.info_yht), x, MAX(y, self.info_yht), fill=col, tag='crel') # if small x increase mark with tic if x - crelx < 10 and ccurrely > self.info_yht: LINE(x-5, ccurrely, x+5, ccurrely, fill=ccurrelcol, tag='crel') ty = (ccurrely+y)/2 if ty > self.info_yht: TEXT(x+2, ty, fill=col, anchor=W, font=PKT_LABEL_FONT, text='+%d' % (int(p.wrel-ccurrel)), tag='crel') ccurrely = y else: ccurrely = self.yorg - int((p.wrel - self.sseqbase)*self.sscalef) ccurrel = p.wrel creling = 1 crelx = x ccurrelcol = col if way == SERVER: if p.markers & P_REL_BOSS_CWND: col = srelcol_conwin else: col = srelcol_flowwin if sreling: #extend if scurrely > self.info_yht: LINE(srelx, scurrely, x, scurrely, fill=scurrelcol, tag='srel') # increase? #if not seq_gt(p.wrel, scurrel): if p.wrel <= scurrel: print '#%d Goof server ACK rel increase not increasing' % (p.indx) y = self.yorg - int((p.wrel - self.cseqbase)*self.sscalef) LINE(x, MAX(scurrely, self.info_yht), x, MAX(y, self.info_yht), fill=col, tag='srel') # if small x increase mark with tic if x - srelx < 10: LINE(x-5, scurrely, x+5, scurrely, fill=scurrelcol, tag='srel') scurrely = y else: scurrely = self.yorg - int((p.wrel - self.cseqbase)*self.sscalef) scurrel = p.wrel sreling = 1 srelx = x scurrelcol = col ############################################################################### # # Find current rtts - return -1 if none # def find_curr_rtts(self, plist, indx, dirn='before'): i = indx si = ci = ti = -1 got = 0 if dirn == 'before': inc = -1 else: inc = 1 topi = len(plist) #print 'find_curr_rtts %s #%d' % (dirn, indx) while 1: i = i + inc if i < 0 or i >= topi or got == 3: #print 'si = %d ci = %d ti = %d' % (si, ci, ti) return (si, ci, ti) p = plist[i] way = p.dir if si < 0: if way == SERVER and p.prtt != 0: si = i got = got + 1 if ci < 0: if way == CLIENT and p.prtt != 0: ci = i got = got + 1 if ti < 0 and p.trtt != 0: ti = i got = got + 1 ############################################################################### # # Draw the RTT graph # def draw_rtts(self): self.draw_rtt_axes() self.draw_rtt_ytics() smin = self.smin_rtt_curr cmin = self.cmin_rtt_curr plist = self.pktlist i1 = self.indx1 i2 = self.indx2 LINE = self.canv.create_line TEXT = self.canv.create_text #RECT = self.canv.create_rectangle srtting = 0 crtting = 0 rtting = 0 #srttx = crttx = rttx = self.xorg si, ci, ri = self.find_curr_rtts(plist, i1) if si >= 0: p = plist[si] srtting = 1 scurrtt = p.prtt scurrttx = self.xorg + int((p.tm-self.tbase)*self.tscalef) scurrtty = self.rtt_yorg - int((scurrtt-smin)*self.srscalef) if ci >= 0: p = plist[ci] crtting = 1 ccurrtt = p.prtt ccurrttx = self.xorg + int((p.tm-self.tbase)*self.tscalef) ccurrtty = self.rtt_yorg - int((ccurrtt-cmin)*self.crscalef) if ri >= 0: p = plist[ri] rtting = 1 currtt = p.trtt currttx = self.xorg + int((p.tm-self.tbase)*self.tscalef) currtty = self.rtt_yorg - int(currtt*self.srscalef) for p in plist[i1:i2+1]: way = p.dir x = self.xorg + int((p.tm-self.tbase)*self.tscalef) if p.prtt: if way == CLIENT: y = self.rtt_yorg - int((p.prtt-cmin)*self.crscalef) col=C_SEG_COL if crtting: try: x1, y1, x2, y2 = endpoints(ccurrttx, ccurrtty, x, y, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=col, tag=('rtt','c')) except Nodraw: pass if not (p.trig & TRIG_RTT): col = LOW_ATTENTION_COL if inside(x, y, self.rtt_bounds): self.rtthandles.append((p, self.draw_blob(x, y, col, tag=('rtt','c')))) ccurrttx = x ccurrtty = y crtting =1 else: y = self.rtt_yorg - int((p.prtt-smin)*self.srscalef) col=S_SEG_COL if srtting: try: x1, y1, x2, y2 = endpoints(scurrttx, scurrtty, x, y, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=col, tags=('rtt','s')) except Nodraw: pass if not (p.trig & TRIG_RTT): col = LOW_ATTENTION_COL if inside(x, y, self.rtt_bounds): self.rtthandles.append((p, self.draw_blob(x, y, col, tag=('rtt','s')))) scurrttx = x scurrtty = y srtting =1 if p.trtt: y = self.rtt_yorg - int(p.trtt*self.srscalef) col='blue' if rtting: if currttx < self.xorg: currtty = self.interpy_l(x, y, currttx, currtty, self.xorg) LINE(currttx, currtty, x, y, fill=col, tag='rtt') self.rtthandles.append((p, RECT(x-2, y-2, x+2, y+2, outline='', fill=col, tag='rtt'))) currttx = x currtty = y rtting =1 if p.delay: if way == CLIENT: col=C_SEG_COL y = ccurrtty - int(p.delay*self.crscalef) try: x1, y1, x2, y2 = endpoints(x, ccurrtty, x, y, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=col, tags=('rtt','c')) if p.delay < 0: sz = MAX((y1-y2)/2, 5) ya = (y1+y2)/2 self.canv.create_oval(x-sz, ya-sz, x+sz, ya+sz, outline=ATTENTION_COL, tags=('rtt','c')) if y2 !=y and y1 > self.rtt_bounds[2]: TEXT(x, y2, fill=col, anchor=CENTER, font=("helvetica", 10), text='/', tags=('rtt','c')) except Nodraw: pass if way == SERVER: col=S_SEG_COL y = scurrtty - int(p.delay*self.srscalef) try: x1, y1, x2, y2 = endpoints(x, scurrtty, x, y, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=col, tags=('rtt','s')) if p.delay < 0: sz = MAX((y1-y2)/2, 5) ya = (y1+y2)/2 self.canv.create_oval(x-sz, ya-sz, x+sz, ya+sz, outline=ATTENTION_COL, tags=('rtt','s')) if y2 !=y and y1 > self.rtt_bounds[2]: TEXT(x, y2, fill=col, anchor=CENTER, font=("helvetica", 10), text='/', tags=('rtt','s')) except Nodraw: pass # # Extend rtt graph towards any following points # si, ci, ri = self.find_curr_rtts(plist, i2, dirn = 'after') if si > 0 and srtting: p = plist[si] xnew = self.xorg + int((p.tm-self.tbase)*self.tscalef) ynew = self.rtt_yorg - int((p.prtt-smin)*self.srscalef) #y = self.interpy_l(scurrttx, scurrtty, xnew, ynew, self.xorg+self.xwi) try: x1, y1, x2, y2 = endpoints(scurrttx, scurrtty, xnew, ynew, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=S_SEG_COL, tags=('rtt','s')) except Nodraw: pass if ci > 0 and crtting: p = plist[ci] xnew = self.xorg + int((p.tm-self.tbase)*self.tscalef) ynew = self.rtt_yorg - int((p.prtt-cmin)*self.crscalef) #y = self.interpy_l(ccurrttx, ccurrtty, xnew, ynew, self.xorg+self.xwi) #LINE(ccurrttx, ccurrtty, x, y, fill= C_SEG_COL, tag='rtt') try: x1, y1, x2, y2 = endpoints(ccurrttx, ccurrtty, xnew, ynew, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=C_SEG_COL, tags=('rtt','c')) except Nodraw: pass if ri > 0 and rtting: p = plist[ri] xnew = self.xorg + int((p.tm-self.tbase)*self.tscalef) ynew = self.rtt_yorg - int(p.trtt*self.srscalef) #y = self.interpy_l(currttx, currtty, xnew, ynew, self.xorg+self.xwi) #LINE(currttx, currtty, x, y, fill= TOT_RTT_COL, tag='rtt') try: x1, y1, x2, y2 = endpoints(currttx, currtty, xnew, ynew, self.rtt_bounds) LINE(x1, y1, x2, y2, fill=C_SEG_COL, tag='rtt') except Nodraw: pass ############################################################################## def calc_ticfacts(self, minx, scalef, range): try: t = int(minx/scalef) except OverflowError: #print 'range = %d scalef = %f' % (range, scalef) inc = range xinc = inc*scalef return inc = 1 while 1: if inc > t: break inc = inc*10 lastdelta = abs(inc - t) lastinc = inc for scale in [2,4,10]: thisinc = inc/scale delta = abs(thisinc - t) if delta > lastdelta or round(thisinc) != thisinc: break lastdelta = delta #inc = thisinc lastinc = thisinc inc = lastinc if inc == 0: inc = 1 #? xinc = inc*scalef return (xinc, inc) ############################################################################### def draw_xtics(self, y, tbase): LINE = self.canv.create_line TEXT = self.canv.create_text scalef = self.tscalef x = self.xorg xinc, tinc = self.calc_ticfacts(self.min_xtic_wi, scalef, self.dur) tm = tbase xadj = 0 # get the first tic to a sensible value baseadj = tbase%tinc if baseadj: tm = tbase-baseadj + tinc # offset the tics xadj = int(baseadj*self.tscalef) x = x - xadj + xinc n = self.dur/tinc if not n: n = 1 y0 = y y1 = y0+5 while x < self.xorg+self.xwi: LINE(x, y0, x, y1, fill=self.fgcol) if modf(tinc/1000.00)[0] == 0: sstr = '%d' % (tm/1000) else: sstr = '%.3f' % (tm/1000.0) #print sstr TEXT(x, y1, text = sstr, fill=self.fgcol, anchor = N, font=TIC_FONT) x = x+xinc tm = tm+tinc ############################################################################### def draw_ytics(self, side, x, base): LINE = self.canv.create_line TEXT = self.canv.create_text scalef = self.sscalef y = self.yorg yinc, sinc = self.calc_ticfacts(self.min_ytic_hi, scalef, self.seqrange) # get the first tic to a sensible value baseadj = base%sinc seq = base-baseadj n = self.seqrange/sinc if not n: n = 1 if side == 'left': xoff = -5 anch = E col = S_SEG_COL else: xoff = 5 anch = W col = C_SEG_COL x0 = x x1 = x0 + xoff for l in range(n+1): LINE(x0, y, x1, y, fill=col) sstr = '%d' % (seq) #print sstr TEXT(x1, y, text = sstr, fill=col, anchor = anch, font=("helvetica", 8)) y = y-yinc seq = seq+sinc if side == 'left': # flight canvas #print 'Flight range %d scalef %f' % (self.max_inflight, self.fscalef) lab = 0 y = self.flight_yorg yinc = int(self.fscalef) for i in range(self.max_inflight+1): LINE(x0, y, x1, y, fill=self.fgcol) fstr = '%d' % (i) TEXT(x1, y, text=fstr, fill=self.fgcol, anchor=E, font=TIC_FONT) y = y-yinc # let caller know base adj required return baseadj ############################################################################## def draw_rtt_ytics(self): LINE = self.canv.create_line TEXT = self.canv.create_text # LH yaxis for server rtts min = self.smin_rtt max = self.smax_rtt r = max - min #print 'srtt min %.3f max %.3f range %.3f' % (min/1000.0, max/1000.0, r/1000.0) x0 = self.xaxposl x1 = x0-5 y = self.rtt_yorg yinc, sinc = self.calc_ticfacts(self.min_ytic_hi/2, self.srscalef, r) #print 'yinc = %d sinc = %d' % (yinc, sinc) # get the first tic to a sensible value baseadj = min%sinc self.smin_rtt_curr = self.smin_rtt-baseadj seq = min-baseadj n = self.rtt_yht/yinc if not n: n = 1 for l in range(n+1): LINE(x0, y, x1, y, fill=S_SEG_COL, tag='rtt_tic') fstr = '%.3f' % (seq/1000.0) TEXT(x1, y, text=fstr, fill=S_SEG_COL, anchor=E, font=TIC_FONT, tag='rtt_tic') y = y-yinc seq = seq + sinc # RH yaxis for client rtts min = self.cmin_rtt max = self.cmax_rtt r = max - min #print 'crtt min %.3f max %.3f range %.3f' % (min/1000.0, max/1000.0, r/1000.0) x0 = self.xaxposr x1 = x0+5 y = self.rtt_yorg yinc, sinc = self.calc_ticfacts(self.min_ytic_hi/2, self.crscalef, r) #print 'yinc = %d sinc = %d' % (yinc, sinc) # get the first tic to a sensible value baseadj = min%sinc self.cmin_rtt_curr = self.cmin_rtt-baseadj seq = min-baseadj n = self.rtt_yht/yinc if not n: n = 1 for l in range(n+1): LINE(x0, y, x1, y, fill=C_SEG_COL, tag='rtt_tic') fstr = '%.3f' % (seq/1000.0) TEXT(x1, y, text=fstr, fill=C_SEG_COL, anchor=W, font=TIC_FONT, tag='rtt_tic') y = y-yinc seq = seq + sinc ############################################################################### def draw_rtt_axes(self): LINE = self.canv.create_line TEXT = self.canv.create_text xposl = self.xaxposl xposr = self.xaxposr ypos = self.rtt_yorg LINE(xposr, ypos, xposl, ypos, fill=self.fgcol) LINE(xposl, self.rtt_yorg, xposl, self.rtt_yorg-self.rtt_yht, fill=S_SEG_COL) TEXT(xposl, self.rtt_yorg-self.rtt_yht-5, text='server\nprtt ms', fill=S_SEG_COL, anchor = SE, font=("helvetica", 8)) LINE(xposr, self.rtt_yorg, xposr, self.rtt_yorg-self.rtt_yht, fill=C_SEG_COL) TEXT(xposr, self.rtt_yorg-self.rtt_yht-5, text='client\nprtt ms', fill=C_SEG_COL, anchor = SW, font=("helvetica", 8)) ############################################################################### def draw_axes(self): LINE = self.canv.create_line TEXT = self.canv.create_text xaxposl = self.xaxposl = self.xorg-5 xaxposr = self.xaxposr = self.xorg+self.xwi+5 yaxpos = self.yaxpos = self.yorg+5 # server y axis LINE(xaxposl, self.yorg, xaxposl, self.yorg-self.yht, fill=S_SEG_COL, width=1) TEXT(xaxposl, self.yorg-self.yht-5, text='server\nsequence', fill=S_SEG_COL, anchor = SE, font=("helvetica", 8)) # client y axis LINE(xaxposr, self.yorg, xaxposr, self.yorg-self.yht, fill=C_SEG_COL, width=1) TEXT(xaxposr, self.yorg-self.yht-5, text='client\nsequence', fill=C_SEG_COL, anchor = SW, font=("helvetica", 8)) # x axis LINE(self.xorg, yaxpos, self.xorg+self.xwi, yaxpos, fill=self.fgcol, width=1) TEXT(self.xorg+self.xwi, yaxpos+5, text='ms', fill=self.fgcol, anchor = NW, font=("helvetica", 8)) xadj = self.draw_xtics(yaxpos, self.tbase) ## LINE(self.xorg, yaxpos, self.xorg-xadj, yaxpos, ## fill=self.fgcol, width=1) adj = self.draw_ytics('left', xaxposl, self.sseqbase-self.conn.sseqbase) self.sseqbase = self.sseqbase - adj adj = self.draw_ytics('right', xaxposr, self.cseqbase-self.conn.cseqbase) self.cseqbase = self.cseqbase - adj # flight canvas LINE(xaxposl, self.flight_yorg, xaxposl, self.flight_yorg-self.flight_yht, fill=self.fgcol) LINE(xaxposl, self.flight_yorg, xaxposr, self.flight_yorg, fill=self.fgcol) TEXT(xaxposl, self.flight_yorg-self.flight_yht-5, text='pkts in\nflight', fill=FG_COL1, anchor = SE, font=("helvetica", 8))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -