Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SequencerTimerTool.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // From ROOT
4 #include "TH1D.h"
5 
6 // from Gaudi
9 #include "GaudiUtils/Aida2ROOT.h"
10 
11 // local
12 #include "SequencerTimerTool.h"
13 
14 //-----------------------------------------------------------------------------
15 // Implementation file for class : SequencerTimerTool
16 //
17 // 2004-05-19 : Olivier Callot
18 //-----------------------------------------------------------------------------
19 
20 // Declaration of the Tool Factory
22 
23 //=============================================================================
24 // Standard constructor, initializes variables
25 //=============================================================================
27  const std::string& name,
28  const IInterface* parent )
29  : GaudiHistoTool ( type, name , parent )
30  , m_indent( 0 )
31  , m_normFactor( 0.001 )
32  , m_speedRatio(0)
33 {
35 
36  m_shots = 3500000 ; // 1s on 2.8GHz Xeon, gcc 3.2, -o2
37  declareProperty( "shots" , m_shots );
38  declareProperty( "Normalised" , m_normalised = false );
39  declareProperty( "GlobalTiming" , m_globalTiming = false );
40  declareProperty( "NameSize" , m_headerSize = 30,
41  "Number of characters to be used in algorithm name column" );
42  // Histograms are disabled by default in this tool.
43  setProperty("HistoProduce", false).ignore();
44 }
45 //=============================================================================
46 // Destructor
47 //=============================================================================
49 
50 
51 //=========================================================================
52 //
53 //=========================================================================
55 {
57  if ( sc.isFailure() ) return sc;
58  double sum = 0;
59  TimerForSequencer norm( "normalize", m_headerSize, m_normFactor );
60  norm.start();
61  IRndmGenSvc* rsvc = svc<IRndmGenSvc>( "RndmGenSvc", true );
62  { // Use dummy loop suggested by Vanya Belyaev:
64  gauss.initialize( rsvc , Rndm::Gauss(0.,1.0) ).ignore();
65  unsigned int shots = m_shots;
66  while( 0 < --shots ) { sum += gauss() * sum ; }
67  }
68  norm.stop();
69  double time = norm.lastCpu();
70  m_speedRatio = 1./time;
71  info() << "This machine has a speed about "
72  << format( "%6.2f", 1000.*m_speedRatio)
73  << " times the speed of a 2.8 GHz Xeon." << endmsg ;
74  if ( m_normalised ) {
76  }
77  return sc;
78 }
79 
80 //=========================================================================
81 // Finalize : Report timers
82 //=========================================================================
84 {
85 
86  std::string line(m_headerSize + 68, '-');
87  info() << line << endmsg
88  << "This machine has a speed about "
89  << format( "%6.2f", 1000.*m_speedRatio)
90  << " times the speed of a 2.8 GHz Xeon.";
91  if ( m_normalised ) info() <<" *** All times are renormalized ***";
93  << line << endmsg;
94 
95  std::string lastName = "";
96  for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ )
97  {
98  if ( lastName == m_timerList[kk].name() ) continue; // suppress duplicate
99  lastName = m_timerList[kk].name();
100  info() << m_timerList[kk] << endmsg;
101  }
102  info() << line << endmsg;
103 
104  return GaudiHistoTool::finalize();
105 }
106 
107 //=========================================================================
108 // Return the index of a specified name. Trailing and leading spaces ignored
109 //=========================================================================
110 int SequencerTimerTool::indexByName ( const std::string& name )
111 {
112  std::string::size_type beg = name.find_first_not_of(" \t");
113  std::string::size_type end = name.find_last_not_of(" \t");
114  std::string temp = name.substr( beg, end-beg+1 );
115  for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ ) {
116  beg = m_timerList[kk].name().find_first_not_of(" \t");
117  end = m_timerList[kk].name().find_last_not_of(" \t");
118  if ( m_timerList[kk].name().substr(beg,end-beg+1) == temp ) return kk;
119  }
120  return -1;
121 }
122 
123 //=========================================================================
124 // Build and save the histograms
125 //=========================================================================
127 {
128  if ( produceHistos() )
129  {
130  info() << "Saving Timing histograms" << endmsg;
131  const size_t bins = m_timerList.size();
132  AIDA::IHistogram1D* histoTime = book("ElapsedTime", 0, bins, bins);
133  AIDA::IHistogram1D* histoCPU = book("CPUTime", 0, bins, bins);
134  AIDA::IHistogram1D* histoCount = book("Count", 0, bins, bins);
135  TH1D* tHtime = Gaudi::Utils::Aida2ROOT::aida2root(histoTime);
136  TH1D* tHCPU = Gaudi::Utils::Aida2ROOT::aida2root(histoCPU);
137  TH1D* tHCount = Gaudi::Utils::Aida2ROOT::aida2root(histoCount);
138  for ( size_t kk = 0 ; bins > kk ; kk++ )
139  {
140  TimerForSequencer &tfsq = m_timerList[kk];
141  tHtime->Fill(tfsq.name().c_str(), tfsq.elapsedTotal());
142  tHCPU->Fill(tfsq.name().c_str(), tfsq.cpuTotal());
143  tHCount->Fill(tfsq.name().c_str(), tfsq.count());
144  }
145  }
146 }
147 
148 //=============================================================================
149 // Add a timer
150 //=============================================================================
151 int SequencerTimerTool::addTimer( const std::string& name )
152 {
153  std::string myName;
154  if ( 0 < m_indent )
155  {
156  const std::string prefix( m_indent, ' ' );
157  myName += prefix;
158  }
159  myName += name;
160  if ( myName.size() < m_headerSize )
161  {
162  const std::string space( m_headerSize - myName.size(), ' ' );
163  myName += space ;
164  }
165 
166  //myName = myName.substr( 0, m_headerSize );
167 
168  m_timerList.push_back( TimerForSequencer( myName,
169  m_headerSize,
170  m_normFactor ) );
171 
172  return m_timerList.size() - 1;
173 }
174 
175 //=============================================================================

Generated at Wed Jun 4 2014 14:48:55 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004