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