The Gaudi Framework  v29r0 (ff2e7097)
CallgrindProfile.cpp
Go to the documentation of this file.
1 // Include files
2 #include <iostream>
3 
4 // local
5 #include "CallgrindProfile.h"
6 #include "local_callgrind.h"
7 
8 //-----------------------------------------------------------------------------
9 // Implementation file for class : CallgrindProfile
10 //
11 // 2014-08-22 : Ben Couturier
12 //-----------------------------------------------------------------------------
13 
14 // Declaration of the Algorithm Factory
16 
17 //=============================================================================
18 // Initialization
19 //=============================================================================
21 {
22  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
23  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
24 
25  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
26  return StatusCode::SUCCESS;
27 }
28 
29 //=============================================================================
30 // Main execution
31 //=============================================================================
33 {
34 
35  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
36 
37  // Increase event number
38  m_eventNumber += 1;
39 
41  m_profiling = true;
42  warning() << "Starting Callgrind profile at event " << m_eventNumber << endmsg;
44  }
45 
46  if ( m_eventNumber == m_nZeroAtEvent ) {
47  warning() << "Setting Callgrind counters to zero at event " << m_eventNumber << endmsg;
49  }
50 
51  if ( m_eventNumber == m_nStopAtEvent ) {
52  m_profiling = false;
53  warning() << "Stopping Callgrind profile at event " << m_eventNumber << endmsg;
55  }
56 
57  if ( m_eventNumber == m_nDumpAtEvent ) {
58  warning() << "Dumping Callgrind counters to zero at event " << m_eventNumber << endmsg;
59 
60  if ( m_dumpName == "" ) {
62  } else {
63  CALLGRIND_DUMP_STATS_AT( m_dumpName.value().c_str() );
64  }
65  m_dumpDone = true;
66  }
67 
68  return StatusCode::SUCCESS;
69 }
70 
71 //=============================================================================
72 // Finalize
73 //=============================================================================
75 {
76 
77  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
78 
79  if ( !m_dumpDone ) {
80  if ( m_dumpName == "" ) {
82  } else {
83  CALLGRIND_DUMP_STATS_AT( m_dumpName.value().c_str() );
84  }
85  }
86 
87  return GaudiAlgorithm::finalize(); // must be called after all other actions
88 }
89 
90 //=============================================================================
#define CALLGRIND_START_INSTRUMENTATION
StatusCode initialize() override
standard initialization method
Gaudi::Property< int > m_nDumpAtEvent
Gaudi::Property< int > m_nStartFromEvent
Gaudi::Property< std::string > m_dumpName
#define CALLGRIND_ZERO_STATS
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
Gaudi::Property< int > m_nZeroAtEvent
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
StatusCode finalize() override
standard finalization method
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:629
StatusCode execute() override
Algorithm execution.
#define CALLGRIND_DUMP_STATS
StatusCode finalize() override
Algorithm finalization.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Algorithm to enable/disable the profiling by Callgrind at given events.
Gaudi::Property< int > m_nStopAtEvent
#define CALLGRIND_STOP_INSTRUMENTATION
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
#define CALLGRIND_DUMP_STATS_AT(pos_str)