Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:50:02

0001 #! /usr/bin/env python3
0002 #Script cloned from cmsTiming_parser.py
0003 
0004 from __future__ import print_function
0005 def get_max(data,index=1):
0006     max_score=-1
0007     for el in data:
0008         sec=el[index]
0009         if max_score<sec:
0010             max_score=sec
0011     return max_score
0012 
0013 def get_min(data,index=1):
0014     min_score=1e20
0015     for el in data:
0016         sec=el[index]
0017         if min_score>sec:
0018             min_score=sec
0019     return min_score    
0020     
0021 def manipulate_log(outdir,logfile_name,secsperbin):
0022 
0023     import time
0024     import sys
0025     import ROOT       
0026     
0027     # the fundamental structure: the key is the evt number the value is a list containing
0028     # Composite Score
0029     data=[]
0030     
0031     # open file and read it and fill the structure!
0032     logfile=open(logfile_name,'r')
0033     logfile_lines=logfile.readlines()
0034     if not logfile_lines:
0035         print("The logfile %s is empty! Exiting now."%logfile_name)
0036         sys.exit()
0037     logfile.close()
0038 
0039     # we get the info we need!
0040     i=0
0041     bench_number=0;
0042     while i < len(logfile_lines):
0043         line=logfile_lines[i]
0044         #if 'TimeEvent>' in line:
0045         if 'Composite Score:' in line:
0046             line=line[:-1] #no \n!
0047             line_content_list=line.split()
0048             #event_number=int(line_content_list[1])
0049             #seconds=float(line_content_list[3])
0050             composite_score=float(line_content_list[2])
0051             #data.append((event_number,seconds))
0052             bench_number+=1
0053             data.append((bench_number,composite_score))
0054         i+=1
0055                                               
0056     # init Graph and histo
0057     
0058     # The Graphs 
0059     __argv=sys.argv # trick for a strange behaviour of the TApp..
0060     sys.argv=sys.argv[:1]
0061     ROOT.gROOT.SetStyle("Plain") # style paranoia
0062     sys.argv=__argv
0063     #Cannot use this option when the logfile includes ~2000
0064     #Composite Scores or more... PyRoot seg-faults.
0065     #Set ROOT in batch mode to avoid canvases popping up!
0066     #ROOT.gROOT.SetBatch(1)
0067 
0068     # Save in file
0069     rootfilename='%s/graphs.root' %outdir
0070     myfile=ROOT.TFile(rootfilename,'RECREATE')   
0071     
0072     
0073     # Set fancy limits
0074     min_val=get_min(data,1)
0075     max_val=get_max(data,1)
0076     interval=int(max_val-min_val)
0077     
0078     min_val=min_val-interval*0.2
0079     max_val=max_val+interval*0.2
0080     interval=int(max_val-min_val)
0081     
0082     nbins=int(interval/secsperbin)
0083     
0084     print('Minval=',min_val,' maxval=',max_val, ' interval=',interval)
0085     
0086     histo=ROOT.TH1F('Composite Score(Mflops)','Composite Score (Mflops)',nbins,min_val,max_val)
0087     histo.GetXaxis().SetTitle("Mflops")    
0088     
0089     npoints=len(data)   
0090     
0091     graph=ROOT.TGraph(npoints)
0092     graph.SetMarkerStyle(8)
0093     graph.SetMarkerSize(.7)
0094     graph.SetMarkerColor(1)
0095     graph.SetLineWidth(3)
0096     graph.SetLineColor(2)        
0097     graph.SetTitle('Composite Score')
0098     graph.SetName('Composite Score')    
0099     graph.GetXaxis().SetTitle("Benchmark sequential number")
0100     
0101     last_event=data[-1][0]
0102     print('last event =',last_event)
0103     graph.GetXaxis().SetLimits(0,last_event)
0104         
0105     graph.GetYaxis().SetTitleOffset(1.3)
0106     graph.GetYaxis().SetTitle("Mflops")
0107     graph.GetYaxis().SetRangeUser(min_val,max_val)
0108 
0109     
0110     
0111     # Fill them
0112     
0113     evt_counter=0
0114     for bench_number,composite_score in data:
0115         graph.SetPoint(evt_counter,bench_number,composite_score)
0116         histo.Fill(composite_score)
0117         evt_counter+=1
0118                 
0119     #A line which represents the average is drawn in the TGraph
0120     avg=histo.GetMean()
0121     avg_line=ROOT.TLine(1,avg,last_event,avg)
0122     avg_line.SetLineColor(4)
0123     avg_line.SetLineWidth(2)
0124         
0125     # draw and save!
0126     graph_canvas=ROOT.TCanvas('graph_canvas')
0127     graph_canvas.cd()
0128     graph.Draw("ALP")
0129     avg_line.Draw("Same")
0130     
0131     graph_canvas.Print("%s/graph.png" %outdir,"png")
0132     
0133     # write it on file
0134     graph.Write()
0135     graph_canvas.Write()    
0136 
0137     histo_canvas=ROOT.TCanvas('histo_canvas')
0138     histo_canvas.cd()
0139     histo.Draw('')
0140 
0141     histo_canvas.Print("%s/histo.png" %outdir,"png")
0142     
0143     # write it on file
0144     histo.Write()
0145     histo_canvas.Write() 
0146     
0147     myfile.Close()   
0148                     
0149     # The html page!------------------------------------------------------------------------------
0150     
0151     titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
0152                                    %(os.environ['CMSSW_VERSION'],time.asctime())
0153         
0154     html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])# a way to say the string until its last but 4th char
0155     html_file=open(html_file_name,'w')
0156     html_file.write('<html>\n<body>\n'+\
0157                     titlestring)
0158     html_file.write('<table>\n'+\
0159                     '<tr><td><img  src=graph.png></img></td></tr>'+\
0160                     '<tr><td><img  src=histo.png></img></td></tr>'+\
0161                     '</table>\n')
0162     html_file.write('\n</body>\n</html>')
0163     html_file.close()    
0164     
0165     
0166 #################################################################################################    
0167         
0168 if __name__ == '__main__':
0169     
0170     import optparse
0171     import os
0172     
0173     # Here we define an option parser to handle commandline options..
0174     usage='cmsScimarkParser.py <options>'
0175     parser = optparse.OptionParser(usage)
0176     parser.add_option('-i', '--in_  profile',
0177                       help='The profile to manipulate' ,
0178                       default='',
0179                       dest='profile')
0180                       
0181     parser.add_option('-o', '--outdir',
0182                       help='The directory of the output' ,
0183                       default='',
0184                       dest='outdir')
0185 
0186     parser.add_option('-n', 
0187                       help='Number of secs per bin. Default is 1.' ,
0188                       default='1',
0189                       dest='startevt')                      
0190                                             
0191     (options,args) = parser.parse_args()
0192     
0193     # Now some fault control..If an error is found we raise an exception
0194     if options.profile=='' or\
0195        options.outdir=='':
0196         raise('Please select a profile and an output dir!')
0197     
0198     if not os.path.exists(options.profile) or\
0199        not os.path.exists(options.outdir):
0200         raise ('Outdir or input profile not present!')
0201     
0202     try:
0203         startevt=float(options.startevt)        
0204     except ValueError:
0205          print('Problems in convertng starting event value!')
0206          
0207             
0208     #launch the function!
0209     manipulate_log(options.outdir,options.profile,startevt)
0210     
0211