Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SequencerTimerTool.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // Include files
12 
13 // From ROOT
14 #include "TH1D.h"
15 
16 // from Gaudi
19 #include "GaudiUtils/Aida2ROOT.h"
20 
21 // local
22 #include "SequencerTimerTool.h"
23 
24 //-----------------------------------------------------------------------------
25 // Implementation file for class : SequencerTimerTool
26 //
27 // 2004-05-19 : Olivier Callot
28 //-----------------------------------------------------------------------------
29 
30 // Declaration of the Tool Factory
32 
33 //=============================================================================
34 // Standard constructor, initializes variables
35 //=============================================================================
36 SequencerTimerTool::SequencerTimerTool( const std::string& type, const std::string& name, const IInterface* parent )
37  : GaudiHistoTool( type, name, parent ) {
38  declareInterface<ISequencerTimerTool>( this );
39 
40  // Histograms are disabled by default in this tool.
41  setProperty( "HistoProduce", false ).ignore();
42 }
43 //=========================================================================
44 //
45 //=========================================================================
48  if ( sc.isFailure() ) return sc;
49  double sum = 0;
50  TimerForSequencer norm( "normalize", m_headerSize, m_normFactor );
51  norm.start();
52  IRndmGenSvc* rsvc = svc<IRndmGenSvc>( "RndmGenSvc", true );
53  { // Use dummy loop suggested by Vanya Belyaev:
55  gauss.initialize( rsvc, Rndm::Gauss( 0., 1.0 ) ).ignore();
56  unsigned int shots = m_shots;
57  while ( 0 < --shots ) { sum += gauss() * sum; }
58  }
59  norm.stop();
60  double time = norm.lastCpu();
61  m_speedRatio = 1. / time;
62  info() << "This machine has a speed about " << format( "%6.2f", 1000. * m_speedRatio )
63  << " times the speed of a 2.8 GHz Xeon." << endmsg;
65  return sc;
66 }
67 
68 //=========================================================================
69 // Finalize : Report timers
70 //=========================================================================
72 
73  if ( !m_timerList.empty() ) {
74  std::string line( m_headerSize + 68, '-' );
75  info() << line << endmsg << "This machine has a speed about " << format( "%6.2f", 1000. * m_speedRatio )
76  << " times the speed of a 2.8 GHz Xeon.";
77  if ( m_normalised ) info() << " *** All times are renormalized ***";
79 
80  std::string lastName;
81  for ( const auto& timr : m_timerList ) {
82  if ( lastName == timr.name() ) continue; // suppress duplicate
83  lastName = timr.name();
84  info() << timr << endmsg;
85  }
86  info() << line << endmsg;
87  }
88  return GaudiHistoTool::finalize();
89 }
90 
91 //=========================================================================
92 // Return the index of a specified name. Trailing and leading spaces ignored
93 //=========================================================================
95  auto beg = name.find_first_not_of( " \t" );
96  auto end = name.find_last_not_of( " \t" );
97  auto temp = name.substr( beg, end - beg + 1 );
98  auto i = std::find_if( std::begin( m_timerList ), std::end( m_timerList ), [&]( const TimerForSequencer& timer ) {
99  beg = timer.name().find_first_not_of( " \t" );
100  end = timer.name().find_last_not_of( " \t" );
101  return timer.name().compare( beg, end - beg + 1, temp ) == 0;
102  } );
103  return i != std::end( m_timerList ) ? std::distance( std::begin( m_timerList ), i ) : -1;
104 }
105 
106 //=========================================================================
107 // Build and save the histograms
108 //=========================================================================
110  if ( produceHistos() ) {
111  info() << "Saving Timing histograms" << endmsg;
112  const size_t bins = m_timerList.size();
113  AIDA::IHistogram1D* histoTime = book( "ElapsedTime", 0, bins, bins );
114  AIDA::IHistogram1D* histoCPU = book( "CPUTime", 0, bins, bins );
115  AIDA::IHistogram1D* histoCount = book( "Count", 0, bins, bins );
116  TH1D* tHtime = Gaudi::Utils::Aida2ROOT::aida2root( histoTime );
117  TH1D* tHCPU = Gaudi::Utils::Aida2ROOT::aida2root( histoCPU );
118  TH1D* tHCount = Gaudi::Utils::Aida2ROOT::aida2root( histoCount );
119  for ( const auto& tfsq : m_timerList ) {
120  tHtime->Fill( tfsq.name().c_str(), tfsq.elapsedTotal() );
121  tHCPU->Fill( tfsq.name().c_str(), tfsq.cpuTotal() );
122  tHCount->Fill( tfsq.name().c_str(), tfsq.count() );
123  }
124  }
125 }
126 
127 //=============================================================================
128 // Add a timer
129 //=============================================================================
131  std::string myName( 2 * m_indent, ' ' );
132  myName += name;
133  if ( myName.size() < m_headerSize ) { myName += std::string( m_headerSize - myName.size(), ' ' ); }
135  return m_timerList.size() - 1;
136 }
137 
138 //=============================================================================
SequencerTimerTool::initialize
StatusCode initialize() override
initialize method, to compute the normalization factor
Definition: SequencerTimerTool.cpp:46
GaudiHistoTool
Definition: GaudiHistoTool.h:49
TimerForSequencer::name
const std::string & name() const
returns the name
Definition: TimerForSequencer.h:51
std::string
STL class.
TimerForSequencer::lastCpu
double lastCpu() const
returns the last measured time
Definition: TimerForSequencer.h:57
RndmGenerators.h
setProperty
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:244
std::move
T move(T... args)
Aida2ROOT.h
std::string::find_last_not_of
T find_last_not_of(T... args)
SequencerTimerTool::m_headerSize
Gaudi::Property< std::string::size_type > m_headerSize
Definition: SequencerTimerTool.h:86
std::find_if
T find_if(T... args)
std::vector::size
T size(T... args)
SequencerTimerTool::indexByName
int indexByName(const std::string &name) override
returns the index of the counter with that name, or -1
Definition: SequencerTimerTool.cpp:94
IRndmGenSvc.h
SequencerTimerTool.h
SequencerTimerTool::addTimer
int addTimer(const std::string &name) override
add a timer entry with the specified name
Definition: SequencerTimerTool.cpp:130
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::distance
T distance(T... args)
GaudiHistos< GaudiTool >::produceHistos
bool produceHistos() const
get the flag for histogram production (property "HistoProduce")
Definition: GaudiHistos.h:2381
std::string::find_first_not_of
T find_first_not_of(T... args)
Gaudi::Utils::Aida2ROOT::aida2root
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Definition: Aida2ROOT.cpp:68
TimerForSequencer::stop
uint64_t stop()
Stop time measurement and return the last elapsed time.
Definition: TimerForSequencer.cpp:20
SequencerTimerTool::m_indent
int m_indent
Amount of indentation.
Definition: SequencerTimerTool.h:89
TimingHistograms.name
name
Definition: TimingHistograms.py:25
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
SequencerTimerTool::m_speedRatio
double m_speedRatio
Definition: SequencerTimerTool.h:92
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
TimerForSequencer::start
void start()
Start a time measurement.
Definition: TimerForSequencer.h:40
TimerForSequencer
Auxiliary class.
Definition: TimerForSequencer.h:30
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
IRndmGenSvc
Definition: IRndmGenSvc.h:45
GaudiHistos< GaudiTool >::book
AIDA::IHistogram1D * book(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100) const
book the 1D histogram
Definition: GaudiHistos.h:1859
SequencerTimerTool::saveHistograms
void saveHistograms() override
prepares and saves the timing histograms
Definition: SequencerTimerTool.cpp:109
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
SequencerTimerTool::m_timerList
std::vector< TimerForSequencer > m_timerList
Definition: SequencerTimerTool.h:90
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
std::string::substr
T substr(T... args)
SequencerTimerTool::m_normFactor
double m_normFactor
Factor to convert to standard CPU (1 GHz PIII)
Definition: SequencerTimerTool.h:91
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
gaudirun.type
type
Definition: gaudirun.py:162
std::vector::emplace_back
T emplace_back(T... args)
SequencerTimerTool
Definition: SequencerTimerTool.h:35
std::begin
T begin(T... args)
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IInterface
Definition: IInterface.h:237
std::vector::empty
T empty(T... args)
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:198
TimerForSequencer::header
static std::string header(std::string::size_type size)
header matching the previous format
Definition: TimerForSequencer.cpp:70
std::end
T end(T... args)
IOTest.end
end
Definition: IOTest.py:123
GaudiHistos< GaudiTool >::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiHistos.icpp:128
SequencerTimerTool::m_normalised
Gaudi::Property< bool > m_normalised
Definition: SequencerTimerTool.h:84
GaudiHistos< GaudiTool >::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiHistos.icpp:91
SequencerTimerTool::finalize
StatusCode finalize() override
finalize method, to print the time summary table
Definition: SequencerTimerTool.cpp:71
SequencerTimerTool::m_shots
Gaudi::Property< int > m_shots
Definition: SequencerTimerTool.h:83