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