2 import matplotlib.pyplot as plt
3 from matplotlib.dates import DateFormatter, MinuteLocator, SecondLocator
5 from StringIO import StringIO
9 from optparse import OptionParser
12 parser = OptionParser (usage = "Usage: %prog [options] BINARY-PROTOCOL")
13 parser.add_option ('--histogram', action = 'store_true', dest = 'histogram', help = "pause time histogram")
14 parser.add_option ('--minor', action = 'store_true', dest = 'minor', help = "only show minor collections in histogram")
15 parser.add_option ('--major', action = 'store_true', dest = 'major', help = "only show major collections in histogram")
16 (options, files) = parser.parse_args ()
18 show_histogram = False
30 script_path = os.path.realpath (__file__)
31 sgen_grep_path = os.path.join (os.path.dirname (script_path), 'sgen-grep-binprot')
33 if not os.path.isfile (sgen_grep_path):
34 sys.stderr.write ('Error: `%s` does not exist.\n' % sgen_grep_path)
45 grep_input = open (files [0])
46 proc = subprocess.Popen ([sgen_grep_path, '--pause-times'], stdin = grep_input, stdout = subprocess.PIPE)
47 for line in iter (proc.stdout.readline, ''):
48 m = re.match ('^pause-time (\d+) (\d+) (\d+) (\d+)', line)
50 generation = int (m.group (1))
51 concurrent = int (m.group (2))
52 msecs = int (m.group (3)) / 10.0 / 1000.0
53 start = int (m.group (4)) / 10.0 / 1000.0
56 minor_pausetimes.append (msecs)
59 major_pausetimes.append (msecs)
64 rec = (generation, start, start + msecs, kind)
71 pausetimes += minor_pausetimes
73 pausetimes += major_pausetimes
74 plt.hist (pausetimes, 100)
75 plt.xlabel ('Pause time in msec')
77 data = np.array (data, dtype = [('caption', '|S20'), ('start', int), ('stop', int), ('kind', '|S20')])
78 cap, start, stop=data['caption'], data['start'], data['stop']
80 #Check the status, because we paint all lines with the same color
82 is_sync= (data['kind']=='SYNC')
83 not_sync=np.logical_not(is_sync)
85 #Get unique captions and there indices and the inverse mapping
86 captions, unique_idx, caption_inv=np.unique(cap, 1,1)
89 #Build y values from the number of unique captions.
90 y=(caption_inv+1)/float(len(captions)+1)
93 def timelines(y, xstart, xstop,color='b'):
94 """Plot timelines at y from xstart to xstop with given color."""
95 plt.hlines(y,xstart,xstop,color,lw=4)
96 plt.vlines(xstart, y+0.03,y-0.03,color,lw=2)
97 plt.vlines(xstop, y+0.03,y-0.03,color,lw=2)
100 timelines(y[is_sync],start[is_sync],stop[is_sync],'r')
102 timelines(y[not_sync],start[not_sync],stop[not_sync],'k')
107 #myFmt = DateFormatter('%H:%M:%S')
108 #ax.xaxis.set_major_formatter(myFmt)
109 #ax.xaxis.set_major_locator(SecondLocator(0,interval=20))
111 #To adjust the xlimits a timedelta is needed.
112 delta=(stop.max()-start.min())/10
114 plt.yticks(y[unique_idx],captions)
116 plt.xlim(start.min()-delta, stop.max()+delta)