CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Attributes

TimerStack Class Reference

#include <TimerStack.h>

List of all members.

Classes

class  Timer
 TTimer is a container for a timer name and associated timers (TimeReport::Item's) More...

Public Types

enum  Status { AlwaysActive, Disableable }
enum  Type { DetailedMonitoring, FastMonitoring }

Public Member Functions

void benchmark (std::string name, int n=1000000)
 measure time to perform a number of floating point multiplications (FLOPs)
void clear_stack ()
 stop all timers in the stack and clear it.
PentiumTimeType pentiumTime ()
 get access to the cpu clock counter on Intel and AMD cpus
void pop ()
 stop the last timer and remove it from the stack
void pop_and_push (std::string name, Type type=FastMonitoring)
void pop_and_push (Timer &, Type type=FastMonitoring)
void push (std::string name, Type type=FastMonitoring)
 start a timer and add it to the stack
void push (Timer &, Type type=FastMonitoring)
 TimerStack ()
 TimerStack (Status status)
 ~TimerStack ()

Private Attributes

std::stack< TimeMe * > stack
Status status_

Detailed Description

Definition at line 19 of file TimerStack.h.


Member Enumeration Documentation

Enumerator:
AlwaysActive 
Disableable 

Definition at line 35 of file TimerStack.h.

Types of time interval measurements used in TimeReport:

  • cpu clock counter called "real". It is fast, high precision, but CPU load from other processes can affect the result
  • system process time (/proc/"process id"/stat) called "cpu", is slow (few ms per call), but CPU load from other processes is factored out. FastMonitoring uses only the first one and DetailedMonitoring uses both. Recommend usage:
  • slow code fragments (> 10 ms) - DetailedMonitoring
  • fast code fragments (microseconds) - FastMonitoring
Enumerator:
DetailedMonitoring 
FastMonitoring 

Definition at line 34 of file TimerStack.h.


Constructor & Destructor Documentation

TimerStack::TimerStack ( ) [inline]

Definition at line 53 of file TimerStack.h.

TimerStack::TimerStack ( Status  status) [inline]

Definition at line 54 of file TimerStack.h.

TimerStack::~TimerStack ( ) [inline]

Definition at line 56 of file TimerStack.h.

References clear_stack().

{ clear_stack(); }

Member Function Documentation

void TimerStack::benchmark ( std::string  name,
int  n = 1000000 
)

measure time to perform a number of floating point multiplications (FLOPs)

Definition at line 38 of file TimerStack.cc.

References a, b, FastMonitoring, i, n, pop(), and push().

{
   push(name,FastMonitoring);
   float a(1.0009394);
   float b(0.000123);
   for(int i=0; i < n; i++) b *= a;
   pop();
}
void TimerStack::clear_stack ( )

stop all timers in the stack and clear it.

Definition at line 25 of file TimerStack.cc.

References pop(), and stack.

Referenced by ~TimerStack().

                            {
   while(!stack.empty()) pop();
}
PentiumTimeType TimerStack::pentiumTime ( ) [inline]

get access to the cpu clock counter on Intel and AMD cpus

Definition at line 75 of file TimerStack.h.

References rdtscPentium().

{return rdtscPentium();}
void TimerStack::pop ( )

stop the last timer and remove it from the stack

Definition at line 18 of file TimerStack.cc.

References stack.

Referenced by benchmark(), clear_stack(), and pop_and_push().

                     {
   if (!stack.empty()) {
      delete stack.top();
      stack.pop();
   }
}
void TimerStack::pop_and_push ( TimerStack::Timer timer,
Type  type = FastMonitoring 
)

Definition at line 33 of file TimerStack.cc.

References pop(), and push().

                                                                 {
   pop();
   push(timer,type);
}
void TimerStack::pop_and_push ( std::string  name,
Type  type = FastMonitoring 
)

stop the last timer and remove it from the stack, than start a new timer and add it to the stack (convinient way of timing sequential code fragments)

Definition at line 29 of file TimerStack.cc.

References pop(), and push().

                                                        {
   pop();
   push(name,type);
}
void TimerStack::push ( std::string  name,
Type  type = FastMonitoring 
)

start a timer and add it to the stack

Definition at line 2 of file TimerStack.cc.

References TimingReport::current(), DetailedMonitoring, mergeVDriftHistosByStation::name, and stack.

Referenced by benchmark(), and pop_and_push().

                                                {
   bool linuxCpuOn = (type == DetailedMonitoring);
   if( (*TimingReport::current())["firstcall_"+name].counter == 0)
     stack.push(new TimeMe("firstcall_"+name,linuxCpuOn));
   else
     stack.push(new TimeMe(name,linuxCpuOn));
}
void TimerStack::push ( TimerStack::Timer timer,
Type  type = FastMonitoring 
)

Definition at line 44 of file MethodSetter.cc.

References error, Exception, reco::findDataMember(), reco::findMethod(), reco::parser::kIsNotConst, reco::parser::kIsNotPublic, reco::parser::kIsStatic, reco::parser::kNameDoesNotExist, reco::parser::kWrongArgumentType, reco::parser::kWrongNumberOfArguments, mem, push(), and reco::returnType().

Referenced by push().

                                                                                                                      {
  Type type = typeStack_.back();
  vector<AnyMethodArgument> fixups;
  int error;
  pair<Member, bool> mem = reco::findMethod(type, name, args, fixups,begin,error);
  if(mem.first) {
     Type retType = reco::returnType(mem.first);
     if(!retType) {
        throw Exception(begin)
        << "member \"" << mem.first.Name() << "\" return type is invalid:\n" 
        << "  member type: \"" <<  mem.first.TypeOf().Name() << "\"\n"
        << "  return type: \"" << mem.first.TypeOf().ReturnType().Name() << "\"\n";
        
     }
     typeStack_.push_back(retType);
     // check for edm::Ref, edm::RefToBase, edm::Ptr
     if(mem.second) {
        //std::cout << "Mem.second, so book " << mem.first.Name() << " without fixups." << std::endl;
        methStack_.push_back(MethodInvoker(mem.first));
        if (deep) push(name, args,begin); // note: we have not found the method, so we have not fixupped the arguments
        else return false;
      } else {
        //std::cout << "Not mem.second, so book " << mem.first.Name() << " with #args = " << fixups.size() << std::endl;
        methStack_.push_back(MethodInvoker(mem.first, fixups));
      }
  } else {
     if(error != reco::parser::kNameDoesNotExist) {
        switch(error) {
           case reco::parser::kIsNotPublic:
            throw Exception(begin)
              << "method named \"" << name << "\" for type \"" 
              <<type.Name() << "\" is not publically accessible.";
            break;
           case reco::parser::kIsStatic:
             throw Exception(begin)
               << "method named \"" << name << "\" for type \"" 
               <<type.Name() << "\" is static.";
             break;
           case reco::parser::kIsNotConst:
              throw Exception(begin)
                << "method named \"" << name << "\" for type \"" 
                <<type.Name() << "\" is not const.";
              break;
           case reco::parser::kWrongNumberOfArguments:
               throw Exception(begin)
                 << "method named \"" << name << "\" for type \"" 
                 <<type.Name() << "\" was passed the wrong number of arguments.";
               break;
           case reco::parser::kWrongArgumentType:
               throw Exception(begin)
                     << "method named \"" << name << "\" for type \"" 
                     <<type.Name() << "\" was passed the wrong types of arguments.";
               break;
           default:  
            throw Exception(begin)
             << "method named \"" << name << "\" for type \"" 
             <<type.Name() << "\" is not usable in this context.";
        }
     }
     //see if it is a member data
     int error;
     Member member = reco::findDataMember(type,name,error);
     if(!member) {
        switch(error) {
           case reco::parser::kNameDoesNotExist:
            throw Exception(begin)
               << "no method or data member named \"" << name << "\" found for type \"" 
               <<type.Name() << "\"";
            break;
           case reco::parser::kIsNotPublic:
            throw Exception(begin)
              << "data member named \"" << name << "\" for type \"" 
              <<type.Name() << "\" is not publically accessible.";
            break;
           default:
           throw Exception(begin)
             << "data member named \"" << name << "\" for type \"" 
             <<type.Name() << "\" is not usable in this context.";
           break;
        }
     }
     typeStack_.push_back(member.TypeOf());
     methStack_.push_back(MethodInvoker(member));
  }
  return true;
}

Member Data Documentation

std::stack<TimeMe*> TimerStack::stack [private]

Definition at line 78 of file TimerStack.h.

Referenced by clear_stack(), pop(), and push().

Definition at line 79 of file TimerStack.h.