CallgrindProfile.cpp
Go to the documentation of this file.
1 // Include files
2 #include <iostream>
3 
4 // local
5 #include "local_callgrind.h"
6 #include "CallgrindProfile.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 //=============================================================================
19 // Standard constructor, initializes variables
20 //=============================================================================
22  ISvcLocator* pSvcLocator)
23  : GaudiAlgorithm ( name , pSvcLocator )
24 {
25 
26  declareProperty("StartFromEventN", m_nStartFromEvent = 1,
27  "After what event we start profiling. "
28  );
29 
30  declareProperty("StopAtEventN", m_nStopAtEvent = 0,
31  "After what event we stop profiling. "
32  "If 0 than we also profile finalization stage. Default = 0."
33  );
34 
35  declareProperty("DumpAtEventN", m_nDumpAtEvent = 0,
36  "After what event we stop profiling. "
37  "If 0 than we also profile finalization stage. Default = 0."
38  );
39 
40  declareProperty("ZeroAtEventN", m_nZeroAtEvent = 0,
41  "After what event we stop profiling. "
42  "If 0 than we also profile finalization stage. Default = 0."
43  );
44  declareProperty("DumpName", m_dumpName = "",
45  "Label for the callgrind dump "
46  );
47 
48  // Internal counter for event numbers
49  m_eventNumber = 0;
50 
51  // Current state
52  m_profiling = false;
53 
54  // Flag to indicate whether the callgrind was done
55  m_dumpDone = false;
56 
57 }
58 //=============================================================================
59 // Destructor
60 //=============================================================================
62 
63 //=============================================================================
64 // Initialization
65 //=============================================================================
67  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
68  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
69 
70  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
71  return StatusCode::SUCCESS;
72 }
73 
74 //=============================================================================
75 // Main execution
76 //=============================================================================
78 
79  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
80 
81  // Increase event number
82  m_eventNumber += 1;
83 
85  {
86  m_profiling = true;
87  warning() << "Starting Callgrind profile at event "
88  << m_eventNumber << endmsg;
90  }
91 
93  {
94  warning() << "Setting Callgrind counters to zero at event "
95  << m_eventNumber << endmsg;
97  }
98 
100  {
101  m_profiling = false;
102  warning() << "Stopping Callgrind profile at event "
103  << m_eventNumber << endmsg;
105  }
106 
108  {
109  warning() << "Dumping Callgrind counters to zero at event "
110  << m_eventNumber << endmsg;
111 
112  if (m_dumpName == "")
113  {
115  }
116  else
117  {
119  }
120  m_dumpDone = true;
121  }
122 
123  return StatusCode::SUCCESS;
124 }
125 
126 //=============================================================================
127 // Finalize
128 //=============================================================================
130 
131  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
132 
133  if (!m_dumpDone)
134  {
135  if (m_dumpName == "")
136  {
138  }
139  else
140  {
142  }
143  }
144 
145  return GaudiAlgorithm::finalize(); // must be called after all other actions
146 }
147 
148 //=============================================================================
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:946
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
#define CALLGRIND_START_INSTRUMENTATION
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode initialize() override
standard initialization method
virtual StatusCode initialize()
Algorithm initialization.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
STL namespace.
#define CALLGRIND_ZERO_STATS
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
virtual StatusCode execute()
Algorithm execution.
virtual ~CallgrindProfile()
Destructor.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode finalize() override
standard finalization method
The useful base class for data processing algorithms.
#define CALLGRIND_DUMP_STATS
std::string m_dumpName
#define CALLGRIND_DUMP_STATS_AT(pos_str)
Algorithm to enable/disable the profiling by Callgrind at given events.
#define CALLGRIND_STOP_INSTRUMENTATION
virtual StatusCode finalize()
Algorithm finalization.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream