| The Gaudi Framework v32r1 (f65d50dc)

plotBacklogPyRoot.py
Go to the documentation of this file.
1 from ROOT import *
2 import sys
3 import re
4 """
5 Produces the backlog plot, parsing the output of the EventLoopManager.
6 Lines with the pattern "Event backlog" are looked for.
7 Events in flight are looked for as well.
8 """
9
10 # configuration
11
12 NEventsInFlight = -1
13 NThreads = -1
14
15 LineStyles = [1, 2]
16 LineWidth = 3
17 Colors = [kBlue, kGreen + 2]
18 MarkerStyles = [kOpenCircle, kFullCircle]
19 MarkesSize = 1.5
20
21 graphCounter = 0
22 maxY = -1
23
24 LegendDrawOpts = "lp"
25
26
27 def parseLog(logfilename):
28 # a line looks like
29 #"HiveSlimEventLoopMgr SUCCESS Event backlog (max= 3, min= 0 ) = 3"
30 global NEventsInFlight
31 global NThreads
32 ifile = open(logfilename, "r")
33 lines = ifile.readlines()
34 ifile.close()
35 content = []
36 for line in lines:
37 if "Event backlog" in line:
38 content.append(
39 re.match(".* \(max= ([0-9]*), min= ([0-9]*) \) = ([0-9]*).*",
40 line).groups())
41 elif "Running with" in line:
42 NEventsInFlight, NThreads = map(
43 int,
44 re.match(".*Running with ([0-9]*).* ([0-9]*) threads",
45 line).groups())
46
47 return content
48
49
50 def createGraph(max_min_blog_vals):
51 global graphCounter
52 global maxY
53 graph = TGraph(len(max_min_blog_vals))
54 counter = 0
55 for maxn, minn, blog in max_min_blog_vals:
56 blog = float(blog)
57 graph.SetPoint(counter, counter + 1, float(blog))
58 if maxY < blog:
59 maxY = blog
60 counter += 1
61
62 graph.SetMarkerSize(MarkesSize)
63 graph.SetMarkerStyle(MarkerStyles[graphCounter])
64 graph.SetMarkerColor(Colors[graphCounter])
65 graph.SetLineWidth(LineWidth)
66 graph.SetLineColor(Colors[graphCounter])
67 graph.SetLineStyle(LineStyles[graphCounter])
68
69 graphCounter += 1
70
71 return graph
72
73
74 def createInFlightGraph(nevts):
75 global NEventsInFlight
76 graph = TGraph(2)
77 graph.SetPoint(0, 0., float(NEventsInFlight))
78 graph.SetPoint(1, float(nevts) + 1, float(NEventsInFlight))
79 graph.SetLineWidth(3)
80 graph.SetLineColor(kRed)
81 graph.SetLineStyle(2)
82 graph.SetTitle(
83 "GaudiHive Backlog (Brunel, 100 evts);Events Finished;Event Backlog")
84 print NEventsInFlight
85 return graph
86
87
88 def getText(x, y, text, scale, angle, colour, font, NDC=False):
89 lat = TLatex(
90 float(x), float(y),
91 "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text))
92 if (NDC):
93 lat.SetNDC()
94 if angle != 0.:
95 lat.SetTextAngle(angle)
96 return lat
97
98
99 def doPlot(logfilename, logfilename_copy):
100 global NEventsInFlight
101 global maxY
102 global NThreads
103 vals = parseLog(logfilename)
104 vals_c = parseLog(logfilename_copy)
105 n_vals = len(vals)
106 inFlightgraph = createInFlightGraph(n_vals)
107 graph = createGraph(vals)
108 graph_c = createGraph(vals_c)
109
110 canvas = TCanvas("Backlog", "Backlog", 1100, 900)
111 canvas.cd()
112 canvas.SetGrid()
113 inFlightgraph.Draw("APL")
114 inFlightgraph.GetYaxis().SetRangeUser(0., maxY * 1.2)
115 inFlightgraph.GetXaxis().SetRangeUser(0., float(n_vals + 1))
116 graph.Draw("PLSame")
117 graph_c.Draw("PLSame")
118
119 # Labels
120 eventInFlightLabel = getText(
121 float(n_vals + 1) * 1.03, NEventsInFlight,
122 "#splitline{# Simultaneous}{ Events}", .6, 270, 2, 12)
123 eventInFlightLabel.Draw()
124 nThreadsLabel = getText(.15, .7, "%s Threads" % NThreads, .6, 0, 2, 12,
125 True)
126 nThreadsLabel.Draw()
127
128 # Build a Legend
129 legend = TLegend(.7, .75, .9, .9)
130 legend.SetFillColor(kWhite)
131 legend.SetHeader("Algo Management")
132 legend.AddEntry(graph, "No Cloning", LegendDrawOpts)
133 legend.AddEntry(graph_c, "Cloning enabled", LegendDrawOpts)
134 legend.Draw()
135
136 a = raw_input("press enter to continue")
137
138 canvas.Print("EventBacklog.png")
139
140
141 if __name__ == "__main__":
142 argc = len(sys.argv)
143 if argc != 3:
144 print "Usage: plotBacklogPyRoot.py logfilename logfilename_copy"
145 sys.exit(1)
146 doPlot(sys.argv[1], sys.argv[2])
plotBacklogPyRoot.getText
def getText(x, y, text, scale, angle, colour, font, NDC=False)
Definition: plotBacklogPyRoot.py:88
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:25
plotBacklogPyRoot.parseLog
def parseLog(logfilename)
Definition: plotBacklogPyRoot.py:27
plotBacklogPyRoot.createInFlightGraph
def createInFlightGraph(nevts)
Definition: plotBacklogPyRoot.py:74
plotBacklogPyRoot.doPlot
def doPlot(logfilename, logfilename_copy)
Definition: plotBacklogPyRoot.py:99
plotBacklogPyRoot.createGraph
def createGraph(max_min_blog_vals)
Definition: plotBacklogPyRoot.py:50