The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
plotClonesPyRoot.py
Go to the documentation of this file.
11import re
12import sys
13
14from ROOT import TCanvas, TGraph, TLatex, kBlue, kFullStar
15
16"""
17Prepare the clones plot.
18Parses the end of the output file, printed by the destructors of the CPUCruncher.
19A line with the pattern "Summary: name=" is looked for.
20The number of Events in flight is parsed as well.
21"""
22
23# configure
24Color = kBlue
25MarkerStyle = kFullStar
26MarkerSize = 3.8
27
28NEventsInFlight = 0
29NThreads = -1
30
31
32def parseLog(logfilename):
33 global NEventsInFlight
34 global NThreads
35 ifile = open(logfilename, "r")
36 lines = ifile.readlines()
37 vals = []
38 for line in lines:
39 if "Summary: name=" in line:
40 runtime_nclones = map(
41 float,
42 re.match(
43 ".* avg_runtime= ([0-9]*.[0-9]*|[0-9]*.[0-9]*e-[0-9]*) n_clones= ([0-9]).*",
44 line,
45 ).groups(),
46 )
47 vals.append(runtime_nclones)
48 elif "Running with" in line:
49 NEventsInFlight, NThreads = map(
50 int,
51 re.match(
52 ".* Running with ([0-9]*) parallel events.*algorithms, ([0-9]*) threads",
53 line,
54 ).groups(),
55 )
56
57 return vals
58
59
60def createGraph(vals):
61 graph = TGraph(len(vals))
62 counter = 0
63 for runtime, nclones in vals:
64 graph.SetPoint(counter, runtime, nclones)
65 counter += 1
66
67 graph.SetMarkerStyle(MarkerStyle)
68 graph.SetMarkerSize(MarkerSize)
69 graph.SetMarkerColor(Color)
70 graph.SetTitle(
71 "GaudiHive Speedup (Brunel, 100 evts);Algorithm Runtime [s];Number of Clones"
72 )
73 return graph
74
75
76def getText(x, y, text, scale, angle, colour, font, NDC=False):
77 lat = TLatex(
78 float(x),
79 float(y),
80 "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text),
81 )
82
83 lat.SetNDC(NDC)
84 if angle != 0.0:
85 lat.SetTextAngle(angle)
86 return lat
87
88
89def getCountLatexes(vals, xmax):
90 # print vals
91 def getNclones(runtime_nclones):
92 return runtime_nclones[1]
93
94 max_nclones = int(max(vals, key=getNclones)[1])
95
96 latexes = []
97 for i in range(1, max_nclones + 1):
98 n_algos = len(filter(lambda runtime_nclones: runtime_nclones[1] == i, vals))
99 latexes.append(getText(xmax * 1.01, i, n_algos, 0.7, 0, 600, 12))
100
101 label = getText(0.95, 0.55, "Total", 0.8, 270, 600, 12, True)
102
103 latexes.append(label)
104
105 return latexes
106
107
108def doPlot(logfilename):
109 global NEventsInFlight
110 global NThreads
111 vals = parseLog(logfilename)
112 graph = createGraph(vals)
113 nalgorithms = len(vals)
114
115 canvas = TCanvas("Clones", "Clones", 1024, 768)
116 canvas.cd()
117 canvas.SetGrid()
118 graph.Draw("AP")
119
120 # Latex
121
122 countLatexes = getCountLatexes(vals, graph.GetXaxis().GetXmax())
123 map(lambda latex: latex.Draw(), countLatexes)
124 evtsIf = getText(
125 0.6,
126 0.365,
127 "#splitline{#splitline{%s Simultaneous Events}{%s Threads}}{%s Algorithms}"
128 % (NEventsInFlight, NThreads, nalgorithms),
129 0.8,
130 0,
131 2,
132 12,
133 True,
134 )
135 evtsIf.Draw()
136
137 input("press enter to continue")
138 canvas.Print("PlotClones.png")
139
140
141if __name__ == "__main__":
142 argc = len(sys.argv)
143 if argc != 2:
144 print("Usage: plotClonesPyRoot.py logfilename")
145 sys.exit(1)
146 doPlot(sys.argv[1])
parseLog(logfilename)
getCountLatexes(vals, xmax)
getText(x, y, text, scale, angle, colour, font, NDC=False)