TDbiTimer.cxx

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////
00002 // $Id: TDbiTimer.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00003 //
00004 // TDbiTimer
00005 //
00006 // Package: TDbi (Database Interface).
00007 //
00008 // N. West 01/2002
00009 //
00010 // Concept: Simple timer record query progress and final times.
00011 //
00012 // Purpose: To find out why this is all soooo sssllloooowwww!
00013 //
00014 ///////////////////////////////////////////////////////////////////////
00015 
00016 #include "TDbiTimer.hxx"
00017 #include <MsgFormat.h>
00018 #include <TSK_DBI_Log.hxx>
00019 #include <MsgFormat.h>
00020 using std::endl;
00021 
00022 ClassImp(TDbiTimer)
00023 
00024 
00025 //   Definition of static data members
00026 //   *********************************
00027 
00028 
00029 // Definition of member functions (alphabetical order)
00030 // ***************************************************
00031 
00032 //.....................................................................
00033 
00034 TDbiTimer::TDbiTimer() :
00035 fCurSubWatch(0),
00036 fRowSize(0),
00037 fQueryStage(kPassive)
00038 {
00039 //
00040 //
00041 //  Purpose:  Default constructor
00042 //
00043 //  Contact:   N. West
00044 //
00045 
00046 
00047   SK_DBI_Trace( "Creating TDbiTimer" << "  ");
00048 
00049   fWatch.Stop();
00050   for ( int subWatch = 0; subWatch <  kMaxSubWatch; ++subWatch) {
00051     fSubWatches[subWatch].Stop();
00052   }
00053 
00054 }
00055 
00056 
00057 //.....................................................................
00058 
00059 TDbiTimer::~TDbiTimer() {
00060 //
00061 //
00062 //  Purpose: Destructor
00063 //
00064 //  Contact:   N. West
00065 //
00066 
00067 
00068   SK_DBI_Trace( "Destroying TDbiTimer" << "  ");
00069 
00070 }
00071 
00072 //.....................................................................
00073 
00074 void TDbiTimer::RecBegin(string tableName, UInt_t rowSize) {
00075 //
00076 //
00077 //  Purpose:  Record the start of initial query on supplied table.
00078 //
00079 //  Arguments:
00080 //    tableName    in    Name of table.
00081 //    rowSize      in    Size of row object
00082 //
00083 //  Contact:   N. West
00084 
00085   fQueryStage = kInitialQuery;
00086   fTableName = tableName;
00087   fRowSize = rowSize;
00088   fWatch.Start();
00089   for ( int subWatch = 0; subWatch <  kMaxSubWatch; ++subWatch) {
00090     // Use Start to reset the counter (Reset doesn't do this).
00091     fSubWatches[subWatch].Start();
00092     fSubWatches[subWatch].Stop();
00093   }
00094   if ( fCurSubWatch >= 0 ) this->StartSubWatch(0);
00095 
00096 }
00097 //.....................................................................
00098 
00099 void TDbiTimer::RecEnd(UInt_t numRows) {
00100 //
00101 //
00102 //  Purpose:  Record the end of query.
00103 //
00104 //  Arguments:
00105 //    numRows    in    Number of rows found in query
00106 //
00107 //  Contact:   N. West
00108 //
00109 //  Specification:-
00110 //  =============
00111 //
00112 //  o Record the end of query.  If query never reached the Main Query
00113 //    phase then quit as query must have been satisfied
00114 //    by the cache.
00115 //
00116 // o  If SubWatches enabled print them out if the main timer has
00117 //    recorded significant activity.
00118 
00119 //  None.
00120 
00121   if ( fQueryStage != kMainQuery ) return;
00122 
00123   Float_t tableSize = numRows * fRowSize/1.0e+3;
00124   string units = "Kb";
00125   if ( tableSize > 1000. ) {
00126     tableSize /= 1000.;
00127     units = "Mb";
00128   }
00129   MsgFormat ffmt("%6.1f");
00130 
00131   SK_DBI_Info( "TDbiTimer:" <<  fTableName
00132                         << ": Query done. "  << numRows
00133                         << "rows, " << ffmt(tableSize) << units
00134                         << " Cpu" << ffmt(fWatch.CpuTime())
00135                         << " , elapse" << ffmt(fWatch.RealTime())
00136                         << "  ");
00137 
00138   fWatch.Stop();
00139   fQueryStage = kPassive;
00140 
00141   if ( fCurSubWatch >= 0 && fWatch.RealTime() > 5. ) {
00142     for ( int subWatch = 0; subWatch <  kMaxSubWatch; ++subWatch) {
00143     static const Char_t* subWatchNames[kMaxSubWatch]
00144       = { "Query database     ",
00145           "Create row objects ",
00146           "Retrieve TSQL rows ",
00147           "Fill row objects   "};
00148        SK_DBI_Info(  "      SubWatch " <<  subWatchNames[subWatch]
00149             << ": Cpu" << ffmt(fSubWatches[subWatch].CpuTime())
00150             << " , elapse" << ffmt(fSubWatches[subWatch].RealTime())
00151             << " , Starts " << fSubWatches[subWatch].Counter()
00152             << "  ");
00153     }
00154   }
00155 }
00156 //.....................................................................
00157 
00158 void TDbiTimer::RecMainQuery() {
00159 //
00160 //
00161 //  Purpose:  Record the start of main query.
00162 //
00163 //  Contact:   N. West
00164 
00165   fQueryStage = kMainQuery;
00166 
00167 }
00168 //.....................................................................
00169 
00170 void TDbiTimer::RecFillAgg(Int_t /* aggNo */) {
00171 //
00172 //
00173 //  Purpose:  Record filling of aggregate.
00174 //
00175 //  Arguments:
00176 //    aggNo        in    Aggregate number.
00177 //
00178 //  Contact:   N. West
00179 
00180 }
00181 
00182 void TDbiTimer::Resume() {
00183 //
00184 //
00185 //  Purpose:  Resume timer and any partial timer.
00186 //
00187 //  Contact:   N. West
00188 
00189   if ( fCurSubWatch >= 0 ) fSubWatches[fCurSubWatch].Start(kFALSE);
00190   fWatch.Start(kFALSE);
00191 }
00192 
00193 //.....................................................................
00194 
00195 void TDbiTimer::StartSubWatch(UInt_t subWatch) {
00196 //
00197 //
00198 //  Purpose:  Start specified SubWatch if SubWatch timers enabled.
00199 //
00200 //  Arguments:
00201 //    subWatch     in    SubWatch number ( 0 .. kMaxSubWatch-1 ).
00202 //
00203 //  Contact:   N. West
00204 
00205   if (     fCurSubWatch < 0
00206         || subWatch >= kMaxSubWatch ) return;
00207 
00208   fSubWatches[fCurSubWatch].Stop();
00209   fCurSubWatch = subWatch;
00210   fSubWatches[fCurSubWatch].Start(kFALSE);
00211 
00212 }
00213 
00214 void TDbiTimer::Suspend() {
00215 //
00216 //
00217 //  Purpose:  Suspend timer and any partial timer.
00218 //
00219 //  Contact:   N. West
00220 
00221   if ( fCurSubWatch >= 0 ) fSubWatches[fCurSubWatch].Stop();
00222   fWatch.Stop();
00223 }
00224 
00225 /*    Template for New Member Function
00226 
00227 //.....................................................................
00228 
00229 TDbiTimer:: {
00230 //
00231 //
00232 //  Purpose:
00233 //
00234 //  Arguments:
00235 //    xxxxxxxxx    in    yyyyyy
00236 //
00237 //  Return:
00238 //
00239 //  Contact:   N. West
00240 //
00241 //  Specification:-
00242 //  =============
00243 //
00244 //  o
00245 
00246 //  Program Notes:-
00247 //  =============
00248 
00249 //  None.
00250 
00251 
00252 }
00253 
00254 */
00255 
00256 
00257 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1