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