00001
00002
00003
00004 def get_max(data,index=1):
00005 max_score=-1
00006 for el in data:
00007 sec=el[index]
00008 if max_score<sec:
00009 max_score=sec
00010 return max_score
00011
00012 def get_min(data,index=1):
00013 min_score=1e20
00014 for el in data:
00015 sec=el[index]
00016 if min_score>sec:
00017 min_score=sec
00018 return min_score
00019
00020 def manipulate_log(outdir,logfile_name,secsperbin):
00021
00022 import time
00023 import sys
00024 import ROOT
00025
00026
00027
00028 data=[]
00029
00030
00031 logfile=open(logfile_name,'r')
00032 logfile_lines=logfile.readlines()
00033 if not logfile_lines:
00034 print "The logfile %s is empty! Exiting now."%logfile_name
00035 sys.exit()
00036 logfile.close()
00037
00038
00039 i=0
00040 bench_number=0;
00041 while i < len(logfile_lines):
00042 line=logfile_lines[i]
00043
00044 if 'Composite Score:' in line:
00045 line=line[:-1]
00046 line_content_list=line.split()
00047
00048
00049 composite_score=float(line_content_list[2])
00050
00051 bench_number+=1
00052 data.append((bench_number,composite_score))
00053 i+=1
00054
00055
00056
00057
00058 __argv=sys.argv
00059 sys.argv=sys.argv[:1]
00060 ROOT.gROOT.SetStyle("Plain")
00061 sys.argv=__argv
00062
00063
00064
00065
00066
00067
00068 rootfilename='%s/graphs.root' %outdir
00069 myfile=ROOT.TFile(rootfilename,'RECREATE')
00070
00071
00072
00073 min_val=get_min(data,1)
00074 max_val=get_max(data,1)
00075 interval=int(max_val-min_val)
00076
00077 min_val=min_val-interval*0.2
00078 max_val=max_val+interval*0.2
00079 interval=int(max_val-min_val)
00080
00081 nbins=int(interval/secsperbin)
00082
00083 print 'Minval=',min_val,' maxval=',max_val, ' interval=',interval
00084
00085 histo=ROOT.TH1F('Composite Score(Mflops)','Composite Score (Mflops)',nbins,min_val,max_val)
00086 histo.GetXaxis().SetTitle("Mflops")
00087
00088 npoints=len(data)
00089
00090 graph=ROOT.TGraph(npoints)
00091 graph.SetMarkerStyle(8)
00092 graph.SetMarkerSize(.7)
00093 graph.SetMarkerColor(1)
00094 graph.SetLineWidth(3)
00095 graph.SetLineColor(2)
00096 graph.SetTitle('Composite Score')
00097 graph.SetName('Composite Score')
00098 graph.GetXaxis().SetTitle("Benchmark sequential number")
00099
00100 last_event=data[-1][0]
00101 print 'last event =',last_event
00102 graph.GetXaxis().SetLimits(0,last_event)
00103
00104 graph.GetYaxis().SetTitleOffset(1.3)
00105 graph.GetYaxis().SetTitle("Mflops")
00106 graph.GetYaxis().SetRangeUser(min_val,max_val)
00107
00108
00109
00110
00111
00112 evt_counter=0
00113 for bench_number,composite_score in data:
00114 graph.SetPoint(evt_counter,bench_number,composite_score)
00115 histo.Fill(composite_score)
00116 evt_counter+=1
00117
00118
00119 avg=histo.GetMean()
00120 avg_line=ROOT.TLine(1,avg,last_event,avg)
00121 avg_line.SetLineColor(4)
00122 avg_line.SetLineWidth(2)
00123
00124
00125 graph_canvas=ROOT.TCanvas('graph_canvas')
00126 graph_canvas.cd()
00127 graph.Draw("ALP")
00128 avg_line.Draw("Same")
00129
00130 graph_canvas.Print("%s/graph.gif" %outdir,"gif")
00131
00132
00133 graph.Write()
00134 graph_canvas.Write()
00135
00136 histo_canvas=ROOT.TCanvas('histo_canvas')
00137 histo_canvas.cd()
00138 histo.Draw('')
00139
00140 histo_canvas.Print("%s/histo.gif" %outdir,"gif")
00141
00142
00143 histo.Write()
00144 histo_canvas.Write()
00145
00146 myfile.Close()
00147
00148
00149
00150 titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00151 %(os.environ['CMSSW_VERSION'],time.asctime())
00152
00153 html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])
00154 html_file=open(html_file_name,'w')
00155 html_file.write('<html>\n<body>\n'+\
00156 titlestring)
00157 html_file.write('<table>\n'+\
00158 '<tr><td><img src=graph.gif></img></td></tr>'+\
00159 '<tr><td><img src=histo.gif></img></td></tr>'+\
00160 '</table>\n')
00161 html_file.write('\n</body>\n</html>')
00162 html_file.close()
00163
00164
00165
00166
00167 if __name__ == '__main__':
00168
00169 import optparse
00170 import os
00171
00172
00173 usage='cmsScimarkParser.py <options>'
00174 parser = optparse.OptionParser(usage)
00175 parser.add_option('-i', '--in_ profile',
00176 help='The profile to manipulate' ,
00177 default='',
00178 dest='profile')
00179
00180 parser.add_option('-o', '--outdir',
00181 help='The directory of the output' ,
00182 default='',
00183 dest='outdir')
00184
00185 parser.add_option('-n',
00186 help='Number of secs per bin. Default is 1.' ,
00187 default='1',
00188 dest='startevt')
00189
00190 (options,args) = parser.parse_args()
00191
00192
00193 if options.profile=='' or\
00194 options.outdir=='':
00195 raise('Please select a profile and an output dir!')
00196
00197 if not os.path.exists(options.profile) or\
00198 not os.path.exists(options.outdir):
00199 raise ('Outdir or input profile not present!')
00200
00201 try:
00202 startevt=float(options.startevt)
00203 except ValueError:
00204 print 'Problems in convertng starting event value!'
00205
00206
00207
00208 manipulate_log(options.outdir,options.profile,startevt)
00209
00210