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 usecs = int (m.group (3))
53 start = int (m.group (4))
56 minor_pausetimes.append (usecs)
59 major_pausetimes.append (usecs)
64 rec = (generation, start, start + usecs, kind)
71 pausetimes += minor_pausetimes
73 pausetimes += major_pausetimes
74 plt.hist (pausetimes, 100)
76 data = np.array (data, dtype = [('caption', '|S20'), ('start', int), ('stop', int), ('kind', '|S20')])
77 cap, start, stop=data['caption'], data['start'], data['stop']
79 #Check the status, because we paint all lines with the same color
81 is_sync= (data['kind']=='SYNC')
82 not_sync=np.logical_not(is_sync)
84 #Get unique captions and there indices and the inverse mapping
85 captions, unique_idx, caption_inv=np.unique(cap, 1,1)
88 #Build y values from the number of unique captions.
89 y=(caption_inv+1)/float(len(captions)+1)
92 def timelines(y, xstart, xstop,color='b'):
93 """Plot timelines at y from xstart to xstop with given color."""
94 plt.hlines(y,xstart,xstop,color,lw=4)
95 plt.vlines(xstart, y+0.03,y-0.03,color,lw=2)
96 plt.vlines(xstop, y+0.03,y-0.03,color,lw=2)
99 timelines(y[is_sync],start[is_sync],stop[is_sync],'r')
101 timelines(y[not_sync],start[not_sync],stop[not_sync],'k')
106 #myFmt = DateFormatter('%H:%M:%S')
107 #ax.xaxis.set_major_formatter(myFmt)
108 #ax.xaxis.set_major_locator(SecondLocator(0,interval=20))
110 #To adjust the xlimits a timedelta is needed.
111 delta=(stop.max()-start.min())/10
113 plt.yticks(y[unique_idx],captions)
115 plt.xlim(start.min()-delta, stop.max()+delta)