Draw_PerfProfiles.C

Go to the documentation of this file.
00001 void Build_Timing_Tree(TFile * f, const Char_t *pattern, Int_t& max_slaves);
00002 
00003 void Draw_PerfProfiles(const Char_t* filename) {
00004    // Plots total processing time as a function of number of slaves
00005    // using each of the 3 selectors.
00006 
00007    // filename: name of file that Run_Node_Tests.C wrote its output into
00008 
00009    gROOT->SetStyle("Plain");
00010    gStyle->SetOptStat(0);
00011    gStyle->SetNdivisions(505);
00012    gStyle->SetTitleFontSize(0.07);
00013 
00014    if(!TString(gSystem->GetLibraries()).Contains("Proof"))
00015       gSystem->Load("libProof.so");
00016    
00017    TFile f(filename);
00018    if (f.IsZombie()) {
00019       cout << "file " << filename << " cannot be opened" << endl;
00020       return;
00021    }
00022 
00023    TString perfstats_name = "PROOF_PerfStats";
00024 
00025    Int_t ns_holder;
00026    Int_t run_holder;
00027    Float_t time_holder;
00028 
00029    Int_t procmax_slaves = 0;
00030    TTree* tt_proc    = Build_Timing_Tree(&f, perfstats_name+"_Proc_",
00031                                          procmax_slaves);
00032    tt_proc->SetMarkerStyle(4);
00033    //set branch addresses
00034    tt_proc->GetBranch("perfproctime")->GetLeaf("nslaves")->SetAddress(&ns_holder);
00035    tt_proc->GetBranch("perfproctime")->GetLeaf("run")->SetAddress(&run_holder);
00036    tt_proc->GetBranch("perfproctime")->GetLeaf("time")->SetAddress(&time_holder);
00037 
00038    Int_t procoptmax_slaves = 0;
00039    TTree* tt_procopt = Build_Timing_Tree(&f, perfstats_name+"_ProcOpt_",
00040                                          procoptmax_slaves);
00041    tt_procopt->SetMarkerStyle(5);
00042    //set branch addresses
00043    tt_procopt->GetBranch("perfproctime")->GetLeaf("nslaves")->SetAddress(&ns_holder);
00044    tt_procopt->GetBranch("perfproctime")->GetLeaf("run")->SetAddress(&run_holder);
00045    tt_procopt->GetBranch("perfproctime")->GetLeaf("time")->SetAddress(&time_holder);
00046 
00047    Int_t noprocmax_slaves = 0;
00048    TTree* tt_noproc  = Build_Timing_Tree(&f, perfstats_name+"_NoProc_",
00049                                          noprocmax_slaves);
00050    tt_noproc->SetMarkerStyle(6);
00051    //set branch addresses
00052    tt_noproc->GetBranch("perfproctime")->GetLeaf("nslaves")->SetAddress(&ns_holder);
00053    tt_noproc->GetBranch("perfproctime")->GetLeaf("run")->SetAddress(&run_holder);
00054    tt_noproc->GetBranch("perfproctime")->GetLeaf("time")->SetAddress(&time_holder);
00055 
00056    f.Close();
00057 
00058    Int_t nslaves = procmax_slaves>procoptmax_slaves?procmax_slaves:procoptmax_slaves;
00059    if (nslaves<noprocmax_slaves) nslaves=noprocmax_slaves;
00060    
00061    TProfile* procprof = new TProfile("procprof", "Total Processing Time",
00062                                      nslaves+1, 0, nslaves+1);
00063    procprof->SetMarkerStyle(26);
00064    tt_proc->Draw("time:nslaves>>procprof");
00065    procprof->GetXaxis()->SetTitle("Number of Slaves");
00066    procprof->GetYaxis()->SetTitle("Processing Time [s]");
00067 
00068    TProfile* procoptprof = new TProfile("procoptprof", "Total Processing Time",
00069                                         nslaves+1, 0, nslaves+1);
00070    procoptprof->SetMarkerStyle(25);
00071    tt_procopt->Draw("time:nslaves>>procoptprof","","same");
00072 
00073    TProfile* noprocprof = new TProfile("noprocprof", "Total Processing Time",
00074                                        nslaves+1, 0, nslaves+1);
00075    noprocprof->SetMarkerStyle(24);
00076    tt_noproc->Draw("time:nslaves>>noprocprof","","same");
00077 
00078    Float_t lm = gPad->GetLeftMargin();
00079    Float_t rm = gPad->GetRightMargin();
00080    Float_t tm = gPad->GetTopMargin();
00081    Float_t bm = gPad->GetBottomMargin();
00082 
00083    Float_t legxoffset = 0.1;
00084    Float_t legwidth = 0.2;
00085    Float_t legyoffset = 0.02;
00086    Float_t legheight = 0.15;
00087 
00088    TLegend* leg = new TLegend(lm+legxoffset*(1.0-lm-rm),
00089                               1.0-tm-(legyoffset+legheight)*(1.0-tm-bm),
00090                               lm+(legxoffset+legwidth)*(1.0-lm-rm),
00091                               1.0-tm-legyoffset*(1.0-tm-bm));
00092    leg->SetBorderSize(1); 
00093    leg->SetFillColor(0);
00094    leg->AddEntry(procprof,"Full Event","p");
00095    leg->AddEntry(procoptprof,"Partial Event","p");
00096    leg->AddEntry(noprocprof,"No Data","p");
00097    leg->Draw();
00098 
00099    gPad->Update();
00100    TPaveText* titlepave = dynamic_cast<TPaveText*>(gPad->GetListOfPrimitives()->FindObject("title"));
00101    if (titlepave) {
00102       Double_t x1ndc = titlepave->GetX1NDC();
00103       Double_t x2ndc = titlepave->GetX2NDC();
00104       titlepave->SetX1NDC((1.0-x2ndc+x1ndc)/2.);
00105       titlepave->SetX2NDC((1.0+x2ndc-x1ndc)/2.);
00106       titlepave->SetBorderSize(0);
00107       gPad->Update();
00108    }
00109    gPad->Modified();
00110 }
00111 
00112 TTree* Build_Timing_Tree(TFile * f, const Char_t *pattern, Int_t& max_slaves) {
00113 
00114    TTree* timing_tree = new TTree("Timing Tree", "Timing Tree");
00115    timing_tree->SetDirectory(0);
00116    Int_t ns_holder;
00117    Int_t run_holder;
00118    Float_t time_holder;
00119    TBranch* br = timing_tree->Branch("perfproctime", &ns_holder,
00120                                      "nslaves/I:run/I:time/F");
00121    br->GetLeaf("nslaves")->SetAddress(&ns_holder);
00122    br->GetLeaf("run")->SetAddress(&run_holder);
00123    br->GetLeaf("time")->SetAddress(&time_holder);
00124 
00125    // extract timing info
00126    max_slaves = 0;
00127    TIter NextKey(f->GetListOfKeys());
00128    TKey* key = 0;
00129    while (key = dynamic_cast<TKey*>(NextKey())) {
00130       if(!TString(key->GetName()).Contains(TRegexp(pattern)))
00131          continue;
00132 
00133       TObject* obj = key->ReadObj();
00134       TTree* t = dynamic_cast<TTree*>(obj);
00135       if (!t) {
00136          delete obj;
00137          continue;
00138       }
00139 
00140       //parse name to get number of slaves and run
00141       Int_t Index = 0;
00142       const Char_t *name = t->GetName();
00143       while (Index<strlen(name)) {
00144         if ( name[Index]>='0' && name[Index]<='9')
00145         break;
00146         Index++;
00147       }
00148 
00149       if (Index == strlen(name)) {
00150          delete t;
00151          continue;
00152       } else {
00153          // this should be the number of slaves
00154          ns_holder = atoi(name+Index);
00155       }
00156 
00157       // get past number of slaves
00158       while (Index<strlen(name)) {
00159         if ( name[Index]<'0' || name[Index]>'9')
00160         break;
00161         Index++;
00162       }
00163 
00164       if (Index == strlen(name)) {
00165          delete t;
00166          continue;
00167       }
00168 
00169       while (Index<strlen(name)) {
00170         if ( name[Index]>='0' && name[Index]<='9')
00171         break;
00172         Index++;
00173       }
00174 
00175       if (Index == strlen(name)) {
00176          delete t;
00177          continue;
00178       } else {
00179          // this should be the run number
00180          run_holder = atoi(name+Index);
00181       }
00182 
00183       if(!t->FindBranch("PerfEvents")) {
00184          delete t;
00185          continue;
00186       }
00187 
00188       // extract timing information
00189       TPerfEvent pe;
00190       TPerfEvent* pep = &pe;
00191       t->SetBranchAddress("PerfEvents",&pep);
00192       Long64_t entries = t->GetEntries();
00193       Double_t start, end;
00194       Bool_t started=kFALSE;
00195       for (Long64_t k=0; k<entries; k++) {
00196          t->GetEntry(k);
00197          if (!started) {
00198             if (pe.fType==TVirtualPerfStats::kPacket) {
00199                start = pe.fTimeStamp.GetSec()
00200                        + 1e-9*pe.fTimeStamp.GetNanoSec()
00201                        - pe.fProcTime;
00202                started=kTRUE;
00203             }
00204          } else {
00205             if (pe.fType==TVirtualPerfStats::kPacket) {
00206                end = pe.fTimeStamp.GetSec()
00207                      + 1e-9*pe.fTimeStamp.GetNanoSec();
00208             }
00209          }
00210       }
00211 
00212       time_holder = end-start;
00213       timing_tree->Fill();
00214       if (max_slaves<ns_holder) max_slaves=ns_holder;
00215 
00216       delete t;
00217    }
00218 
00219    return timing_tree;
00220 }

Generated on Tue Jul 5 15:15:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1