00001 #include "StiTimer.h"
00002 #include "TList.h"
00003 #include "TNamed.h"
00004 #include "StMessMgr.h"
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <assert.h>
00008
00009
00010 TStopwatch *StiTimer::fgFindTimer=0;
00011 int StiTimer::fgFindTally=0;
00012 TList *StiTimer::fgList=0;
00013
00014 class MyHolder : public TNamed
00015 {
00016 public:
00017 MyHolder(){}
00018 ~MyHolder(){ delete fSW; }
00019 TStopwatch *fSW;
00020 int *fTally;
00021 };
00022
00023
00024 void StiTimer::Init(const char *name,TStopwatch *&sw,int &tally)
00025 {
00026 if (!fgList) {fgList= new TList; fgList->SetOwner();}
00027 MyHolder *mh = (MyHolder*)fgList->FindObject(name);
00028 assert(!mh);
00029 mh = new MyHolder();
00030 sw = new TStopwatch();
00031 sw->Stop();
00032 mh->fSW = sw;
00033 tally = 0;
00034 mh->fTally = &tally;
00035 mh->SetName(name);
00036 fgList->Add(mh);
00037 }
00038
00039
00040 void StiTimer::Clear(const char *)
00041 {
00042 delete fgList; fgList=0;
00043 }
00044
00045
00046 void StiTimer::Print(const char *option)
00047 {
00048
00049 LOG_DEBUG << Form("**** StiTimer::Print ****")<<endm;
00050 TListIter next(fgList);
00051 MyHolder *mh=0;
00052 int n = 0;
00053 while ((mh=(MyHolder*)next())) {
00054 n++;
00055 int tally = mh->fTally[0];
00056 if (tally<=0) continue;
00057
00058 double cpu = mh->fSW->CpuTime()/tally;
00059 double rte = mh->fSW->RealTime()/tally;
00060
00061 LOG_DEBUG << Form("StiTimer for <%s> Evts =%d CPU/Evts = %g Time/Evts = %g"
00062 ,mh->GetName(),tally,cpu,rte) << endm;
00063 mh->fSW->Print("u");
00064
00065 }
00066 }
00067
00068
00069
00070