test
CMS 3D CMS Logo

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