CMS 3D CMS Logo

cmsScimarkParser.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 #Script cloned from cmsTiming_parser.py
3 
4 from __future__ import print_function
5 def get_max(data,index=1):
6  max_score=-1
7  for el in data:
8  sec=el[index]
9  if max_score<sec:
10  max_score=sec
11  return max_score
12 
13 def get_min(data,index=1):
14  min_score=1e20
15  for el in data:
16  sec=el[index]
17  if min_score>sec:
18  min_score=sec
19  return min_score
20 
21 def manipulate_log(outdir,logfile_name,secsperbin):
22 
23  import time
24  import sys
25  import ROOT
26 
27  # the fundamental structure: the key is the evt number the value is a list containing
28  # Composite Score
29  data=[]
30 
31  # open file and read it and fill the structure!
32  logfile=open(logfile_name,'r')
33  logfile_lines=logfile.readlines()
34  if not logfile_lines:
35  print("The logfile %s is empty! Exiting now."%logfile_name)
36  sys.exit()
37  logfile.close()
38 
39  # we get the info we need!
40  i=0
41  bench_number=0;
42  while i < len(logfile_lines):
43  line=logfile_lines[i]
44  #if 'TimeEvent>' in line:
45  if 'Composite Score:' in line:
46  line=line[:-1] #no \n!
47  line_content_list=line.split()
48  #event_number=int(line_content_list[1])
49  #seconds=float(line_content_list[3])
50  composite_score=float(line_content_list[2])
51  #data.append((event_number,seconds))
52  bench_number+=1
53  data.append((bench_number,composite_score))
54  i+=1
55 
56  # init Graph and histo
57 
58  # The Graphs
59  __argv=sys.argv # trick for a strange behaviour of the TApp..
60  sys.argv=sys.argv[:1]
61  ROOT.gROOT.SetStyle("Plain") # style paranoia
62  sys.argv=__argv
63  #Cannot use this option when the logfile includes ~2000
64  #Composite Scores or more... PyRoot seg-faults.
65  #Set ROOT in batch mode to avoid canvases popping up!
66  #ROOT.gROOT.SetBatch(1)
67 
68  # Save in file
69  rootfilename='%s/graphs.root' %outdir
70  myfile=ROOT.TFile(rootfilename,'RECREATE')
71 
72 
73  # Set fancy limits
74  min_val=get_min(data,1)
75  max_val=get_max(data,1)
76  interval=int(max_val-min_val)
77 
78  min_val=min_val-interval*0.2
79  max_val=max_val+interval*0.2
80  interval=int(max_val-min_val)
81 
82  nbins=int(interval/secsperbin)
83 
84  print('Minval=',min_val,' maxval=',max_val, ' interval=',interval)
85 
86  histo=ROOT.TH1F('Composite Score(Mflops)','Composite Score (Mflops)',nbins,min_val,max_val)
87  histo.GetXaxis().SetTitle("Mflops")
88 
89  npoints=len(data)
90 
91  graph=ROOT.TGraph(npoints)
92  graph.SetMarkerStyle(8)
93  graph.SetMarkerSize(.7)
94  graph.SetMarkerColor(1)
95  graph.SetLineWidth(3)
96  graph.SetLineColor(2)
97  graph.SetTitle('Composite Score')
98  graph.SetName('Composite Score')
99  graph.GetXaxis().SetTitle("Benchmark sequential number")
100 
101  last_event=data[-1][0]
102  print('last event =',last_event)
103  graph.GetXaxis().SetLimits(0,last_event)
104 
105  graph.GetYaxis().SetTitleOffset(1.3)
106  graph.GetYaxis().SetTitle("Mflops")
107  graph.GetYaxis().SetRangeUser(min_val,max_val)
108 
109 
110 
111  # Fill them
112 
113  evt_counter=0
114  for bench_number,composite_score in data:
115  graph.SetPoint(evt_counter,bench_number,composite_score)
116  histo.Fill(composite_score)
117  evt_counter+=1
118 
119  #A line which represents the average is drawn in the TGraph
120  avg=histo.GetMean()
121  avg_line=ROOT.TLine(1,avg,last_event,avg)
122  avg_line.SetLineColor(4)
123  avg_line.SetLineWidth(2)
124 
125  # draw and save!
126  graph_canvas=ROOT.TCanvas('graph_canvas')
127  graph_canvas.cd()
128  graph.Draw("ALP")
129  avg_line.Draw("Same")
130 
131  graph_canvas.Print("%s/graph.png" %outdir,"png")
132 
133  # write it on file
134  graph.Write()
135  graph_canvas.Write()
136 
137  histo_canvas=ROOT.TCanvas('histo_canvas')
138  histo_canvas.cd()
139  histo.Draw('')
140 
141  histo_canvas.Print("%s/histo.png" %outdir,"png")
142 
143  # write it on file
144  histo.Write()
145  histo_canvas.Write()
146 
147  myfile.Close()
148 
149  # The html page!------------------------------------------------------------------------------
150 
151  titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
152  %(os.environ['CMSSW_VERSION'],time.asctime())
153 
154  html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])# a way to say the string until its last but 4th char
155  html_file=open(html_file_name,'w')
156  html_file.write('<html>\n<body>\n'+\
157  titlestring)
158  html_file.write('<table>\n'+\
159  '<tr><td><img src=graph.png></img></td></tr>'+\
160  '<tr><td><img src=histo.png></img></td></tr>'+\
161  '</table>\n')
162  html_file.write('\n</body>\n</html>')
163  html_file.close()
164 
165 
166 
167 
168 if __name__ == '__main__':
169 
170  import optparse
171  import os
172 
173  # Here we define an option parser to handle commandline options..
174  usage='cmsScimarkParser.py <options>'
175  parser = optparse.OptionParser(usage)
176  parser.add_option('-i', '--in_ profile',
177  help='The profile to manipulate' ,
178  default='',
179  dest='profile')
180 
181  parser.add_option('-o', '--outdir',
182  help='The directory of the output' ,
183  default='',
184  dest='outdir')
185 
186  parser.add_option('-n',
187  help='Number of secs per bin. Default is 1.' ,
188  default='1',
189  dest='startevt')
190 
191  (options,args) = parser.parse_args()
192 
193  # Now some fault control..If an error is found we raise an exception
194  if options.profile=='' or\
195  options.outdir=='':
196  raise('Please select a profile and an output dir!')
197 
198  if not os.path.exists(options.profile) or\
199  not os.path.exists(options.outdir):
200  raise ('Outdir or input profile not present!')
201 
202  try:
203  startevt=float(options.startevt)
204  except ValueError:
205  print('Problems in convertng starting event value!')
206 
207 
208  #launch the function!
209  manipulate_log(options.outdir,options.profile,startevt)
210 
211 
def get_max(data, index=1)
def get_min(data, index=1)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def manipulate_log(outdir, logfile_name, secsperbin)