All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CallgrindProfile.cpp
Go to the documentation of this file.
1 // Include files
2 #include <iostream>
3 
4  // from Gaudi
5 #include "GaudiKernel/AlgFactory.h"
6 
7 // local
8 #include "local_callgrind.h"
9 #include "CallgrindProfile.h"
10 
11 //-----------------------------------------------------------------------------
12 // Implementation file for class : CallgrindProfile
13 //
14 // 2014-08-22 : Ben Couturier
15 //-----------------------------------------------------------------------------
16 
17 // Declaration of the Algorithm Factory
19 
20 
21 //=============================================================================
22 // Standard constructor, initializes variables
23 //=============================================================================
24 CallgrindProfile::CallgrindProfile( const std::string& name,
25  ISvcLocator* pSvcLocator)
26  : GaudiAlgorithm ( name , pSvcLocator )
27 {
28 
29  declareProperty("StartFromEventN", m_nStartFromEvent = 1,
30  "After what event we start profiling. "
31  );
32 
33  declareProperty("StopAtEventN", m_nStopAtEvent = 0,
34  "After what event we stop profiling. "
35  "If 0 than we also profile finalization stage. Default = 0."
36  );
37 
38  declareProperty("DumpAtEventN", m_nDumpAtEvent = 0,
39  "After what event we stop profiling. "
40  "If 0 than we also profile finalization stage. Default = 0."
41  );
42 
43  declareProperty("ZeroAtEventN", m_nZeroAtEvent = 0,
44  "After what event we stop profiling. "
45  "If 0 than we also profile finalization stage. Default = 0."
46  );
47  declareProperty("DumpName", m_dumpName = "",
48  "Label for the callgrind dump "
49  );
50 
51  // Internal counter for event numbers
52  m_eventNumber = 0;
53 
54  // Current state
55  m_profiling = false;
56 
57  // Flag to indicate whether the callgrind was done
58  m_dumpDone = false;
59 
60 }
61 //=============================================================================
62 // Destructor
63 //=============================================================================
65 
66 //=============================================================================
67 // Initialization
68 //=============================================================================
70  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
71  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
72 
73  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
74  return StatusCode::SUCCESS;
75 }
76 
77 //=============================================================================
78 // Main execution
79 //=============================================================================
81 
82  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
83 
84  // Increase event number
85  m_eventNumber += 1;
86 
88  {
89  m_profiling = true;
90  warning() << "Starting Callgrind profile at event "
91  << m_eventNumber << endmsg;
93  }
94 
96  {
97  warning() << "Setting Callgrind counters to zero at event "
98  << m_eventNumber << endmsg;
100  }
101 
103  {
104  m_profiling = false;
105  warning() << "Stopping Callgrind profile at event "
106  << m_eventNumber << endmsg;
108  }
109 
111  {
112  warning() << "Dumping Callgrind counters to zero at event "
113  << m_eventNumber << endmsg;
114 
115  if (m_dumpName == "")
116  {
118  }
119  else
120  {
122  }
123  m_dumpDone = true;
124  }
125 
126  return StatusCode::SUCCESS;
127 }
128 
129 //=============================================================================
130 // Finalize
131 //=============================================================================
133 
134  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
135 
136  if (!m_dumpDone)
137  {
138  if (m_dumpName == "")
139  {
141  }
142  else
143  {
145  }
146  }
147 
148  return GaudiAlgorithm::finalize(); // must be called after all other actions
149 }
150 
151 //=============================================================================
MsgStream & warning() const
shortcut for the method msgStream ( MSG::WARNING )
Definition: GaudiCommon.h:495
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
#define CALLGRIND_START_INSTRUMENTATION
virtual StatusCode initialize()
Algorithm initialization.
virtual StatusCode initialize()
standard initialization method
#define CALLGRIND_ZERO_STATS
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
MSG::Level msgLevel() const
The current message service output level.
Definition: GaudiCommon.h:532
virtual StatusCode execute()
Algorithm execution.
virtual StatusCode finalize()
standard finalization method
virtual ~CallgrindProfile()
Destructor.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:605
The useful base class for data processing algorithms.
MsgStream & debug() const
shortcut for the method msgStream ( MSG::DEBUG )
Definition: GaudiCommon.h:499
#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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244