Gaudi Framework, version v24r2

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

Generated at Wed Dec 4 2013 14:33:07 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004