CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
TimerStack Class Reference

#include <TimerStack.h>

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) More...
 
void clear_stack ()
 stop all timers in the stack and clear it. More...
 
PentiumTimeType pentiumTime ()
 get access to the cpu clock counter on Intel and AMD cpus More...
 
void pop ()
 stop the last timer and remove it from the stack More...
 
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 More...
 
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.

54 :status_(status) {}
Status status_
Definition: TimerStack.h:79
tuple status
Definition: ntuplemaker.py:245
TimerStack::~TimerStack ( )
inline

Definition at line 56 of file TimerStack.h.

References clear_stack().

56 { clear_stack(); }
void clear_stack()
stop all timers in the stack and clear it.
Definition: TimerStack.cc:25

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().

39 {
41  float a(1.0009394);
42  float b(0.000123);
43  for(int i=0; i < n; i++) b *= a;
44  pop();
45 }
int i
Definition: DBlmapReader.cc:9
void pop()
stop the last timer and remove it from the stack
Definition: TimerStack.cc:18
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void push(std::string name, Type type=FastMonitoring)
start a timer and add it to the stack
Definition: TimerStack.cc:2
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().

25  {
26  while(!stack.empty()) pop();
27 }
void pop()
stop the last timer and remove it from the stack
Definition: TimerStack.cc:18
std::stack< TimeMe * > stack
Definition: TimerStack.h:78
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().

75 {return rdtscPentium();}
PentiumTimeType rdtscPentium()
Definition: PentiumTimer.h:13
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().

18  {
19  if (!stack.empty()) {
20  delete stack.top();
21  stack.pop();
22  }
23 }
std::stack< TimeMe * > stack
Definition: TimerStack.h:78
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().

29  {
30  pop();
31  push(name,type);
32 }
type
Definition: HCALResponse.h:22
void pop()
stop the last timer and remove it from the stack
Definition: TimerStack.cc:18
void push(std::string name, Type type=FastMonitoring)
start a timer and add it to the stack
Definition: TimerStack.cc:2
void TimerStack::pop_and_push ( TimerStack::Timer timer,
Type  type = FastMonitoring 
)

Definition at line 33 of file TimerStack.cc.

References pop(), and push().

33  {
34  pop();
35  push(timer,type);
36 }
type
Definition: HCALResponse.h:22
void pop()
stop the last timer and remove it from the stack
Definition: TimerStack.cc:18
void push(std::string name, Type type=FastMonitoring)
start a timer and add it to the stack
Definition: TimerStack.cc:2
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().

2  {
3  bool linuxCpuOn = (type == DetailedMonitoring);
4  if( (*TimingReport::current())["firstcall_"+name].counter == 0)
5  stack.push(new TimeMe("firstcall_"+name,linuxCpuOn));
6  else
7  stack.push(new TimeMe(name,linuxCpuOn));
8 }
type
Definition: HCALResponse.h:22
std::stack< TimeMe * > stack
Definition: TimerStack.h:78
static TimingReport * current()
Definition: TimingReport.cc:21
void TimerStack::push ( TimerStack::Timer timer,
Type  type = FastMonitoring 
)

Definition at line 10 of file TimerStack.cc.

References TimingReport::Item::counter, DetailedMonitoring, TimerStack::Timer::first(), TimerStack::Timer::main(), and stack.

10  {
11  bool linuxCpuOn = (type == DetailedMonitoring);
12  if( timer.first().counter == 0)
13  stack.push(new TimeMe(timer.first(), linuxCpuOn));
14  else
15  stack.push(new TimeMe(timer.main(), linuxCpuOn));
16 }
type
Definition: HCALResponse.h:22
TimingReport::Item & first()
Definition: TimerStack.h:44
std::stack< TimeMe * > stack
Definition: TimerStack.h:78
TimingReport::Item & main()
Definition: TimerStack.h:45

Member Data Documentation

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

Definition at line 78 of file TimerStack.h.

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

Status TimerStack::status_
private

Definition at line 79 of file TimerStack.h.