| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
15 DECLARE_ALGORITHM_FACTORY( CallgrindProfile )
16
17
18 //=============================================================================
19 // Standard constructor, initializes variables
20 //=============================================================================
21 CallgrindProfile::CallgrindProfile( const std::string& name,
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 //=============================================================================
61 CallgrindProfile::~CallgrindProfile() {}
62
63 //=============================================================================
64 // Initialization
65 //=============================================================================
66 StatusCode CallgrindProfile::initialize() {
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 //=============================================================================
77 StatusCode CallgrindProfile::execute() {
78
79 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
80
81 // Increase event number
82 m_eventNumber += 1;
83
84 if (m_eventNumber == m_nStartFromEvent)
85 {
86 m_profiling = true;
87 warning() << "Starting Callgrind profile at event "
88 << m_eventNumber << endmsg;
89 CALLGRIND_START_INSTRUMENTATION;
90 }
91
92 if (m_eventNumber == m_nZeroAtEvent)
93 {
94 warning() << "Setting Callgrind counters to zero at event "
95 << m_eventNumber << endmsg;
96 CALLGRIND_ZERO_STATS;
97 }
98
99 if (m_eventNumber == m_nStopAtEvent)
100 {
101 m_profiling = false;
102 warning() << "Stopping Callgrind profile at event "
103 << m_eventNumber << endmsg;
104 CALLGRIND_STOP_INSTRUMENTATION;
105 }
106
107 if (m_eventNumber == m_nDumpAtEvent)
108 {
109 warning() << "Dumping Callgrind counters to zero at event "
110 << m_eventNumber << endmsg;
111
112 if (m_dumpName == "")
113 {
114 CALLGRIND_DUMP_STATS;
115 }
116 else
117 {
118 CALLGRIND_DUMP_STATS_AT(m_dumpName.c_str());
119 }
120 m_dumpDone = true;
121 }
122
123 return StatusCode::SUCCESS;
124 }
125
126 //=============================================================================
127 // Finalize
128 //=============================================================================
129 StatusCode CallgrindProfile::finalize() {
130
131 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
132
133 if (!m_dumpDone)
134 {
135 if (m_dumpName == "")
136 {
137 CALLGRIND_DUMP_STATS;
138 }
139 else
140 {
141 CALLGRIND_DUMP_STATS_AT(m_dumpName.c_str());
142 }
143 }
144
145 return GaudiAlgorithm::finalize(); // must be called after all other actions
146 }
147
148 //=============================================================================
CallgrindProfile::m_profiling
bool m_profiling
Definition: CallgrindProfile.h:35
CallgrindProfile::m_nStartFromEvent
int m_nStartFromEvent
Definition: CallgrindProfile.h:30
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
CALLGRIND_START_INSTRUMENTATION
#define CALLGRIND_START_INSTRUMENTATION
Definition: local_callgrind.h:114
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
CallgrindProfile::m_eventNumber
int m_eventNumber
Definition: CallgrindProfile.h:34
CallgrindProfile::m_nDumpAtEvent
int m_nDumpAtEvent
Definition: CallgrindProfile.h:32
CallgrindProfile::m_dumpDone
bool m_dumpDone
Definition: CallgrindProfile.h:36
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:48
CallgrindProfile::initialize
virtual StatusCode initialize()
Algorithm initialization.
Definition: CallgrindProfile.cpp:66
MSG::DEBUG
Definition: IMessageSvc.h:18
std
STL namespace.
CALLGRIND_ZERO_STATS
#define CALLGRIND_ZERO_STATS
Definition: local_callgrind.h:98
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
CallgrindProfile::execute
virtual StatusCode execute()
Algorithm execution.
Definition: CallgrindProfile.cpp:77
CallgrindProfile::~CallgrindProfile
virtual ~CallgrindProfile()
Destructor.
Definition: CallgrindProfile.cpp:61
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
CallgrindProfile::m_nStopAtEvent
int m_nStopAtEvent
Definition: CallgrindProfile.h:31
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:62
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:777
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:93
CallgrindProfile.h
CALLGRIND_DUMP_STATS
#define CALLGRIND_DUMP_STATS
Definition: local_callgrind.h:85
CallgrindProfile::m_dumpName
std::string m_dumpName
Definition: CallgrindProfile.h:37
CALLGRIND_DUMP_STATS_AT
#define CALLGRIND_DUMP_STATS_AT(pos_str)
Definition: local_callgrind.h:93
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
std::string::c_str
T c_str(T...args)
CallgrindProfile::m_nZeroAtEvent
int m_nZeroAtEvent
Definition: CallgrindProfile.h:33
CallgrindProfile
Algorithm to enable/disable the profiling by Callgrind at given events.
Definition: CallgrindProfile.h:16
local_callgrind.h
CALLGRIND_STOP_INSTRUMENTATION
#define CALLGRIND_STOP_INSTRUMENTATION
Definition: local_callgrind.h:125
CallgrindProfile::finalize
virtual StatusCode finalize()
Algorithm finalization.
Definition: CallgrindProfile.cpp:129
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244