brianthelion

plot_lat.py

Aug 7th, 2011
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import numpy # sudo apt-get install python-numpy
  2. import pylab # sudo apt-get install python-matplotlib
  3. import argparse
  4.  
  5. def main() :
  6.    
  7.     parser = argparse.ArgumentParser()
  8.     parser.add_argument('file')
  9.     ns = parser.parse_args()
  10.     dt = numpy.dtype({'names':['rtime','stime','count','dst','lat'],'formats':[numpy.float,numpy.float,numpy.int64,'S100',numpy.float]})
  11.     data = numpy.loadtxt( open(ns.file), dtype=dt, delimiter='\t')
  12.    
  13.     for dst in numpy.unique( data['dst'] ) :
  14.         mask = (data['dst'] == dst)
  15.         total = sum(mask)
  16.         time    = data['stime'][mask]-min(data['stime'])
  17.         lat     = data['lat'][mask]
  18.         idx     = data['count'][mask]
  19.         idx_offset = idx[1:]-idx[:-1]
  20.         loss_mask = idx_offset > 1
  21.        
  22.         pylab.plot(time,lat,label="%s (%s recv'd)" % (dst[2:-2],total) )
  23.         pylab.plot(time[1:][loss_mask],lat[1:][loss_mask],'ro')
  24.    
  25.     pylab.plot([],[],'ro',label='Loss events')
  26.     pylab.legend()
  27.     pylab.xlabel('Time (s)')
  28.     pylab.ylabel('Latency (s)')
  29.     pylab.title(ns.file)
  30.     pylab.ylim(0,10)
  31.     pylab.show()
  32.  
  33. if __name__ == '__main__' : main()
  34. else : pass
Advertisement
Add Comment
Please, Sign In to add comment