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 //=============================================================================