ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
PerformanceMonitoring
PerfMonVTune
src
VTuneProfilerService.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Gaudi/Athena include(s):
6
#include "
AthenaKernel/errorcheck.h
"
7
8
// Local include(s):
9
#include "
VTuneProfilerService.h
"
10
11
//
12
// Convenience variable(s):
13
//
14
static
const
std::string
BEGINEVENT_INCIDENT_NAME
=
"BeginEvent"
;
15
static
const
std::string
ENDEVENT_INCIDENT_NAME
=
"EndEvent"
;
16
static
const
std::string
ENDEVTLOOP_INCIDENT_NAME
=
"EndEvtLoop"
;
17
21
VTuneProfilerService::VTuneProfilerService
(
const
std::string& name, ISvcLocator* svcloc )
22
: base_class( name, svcloc ),
23
m_incidentSvc
(
"IncidentSvc"
, name ),
24
m_processedEvents
( 0 ) {
25
26
declareProperty(
"ResumeEvent"
,
m_resumeEvent
= 0,
27
"Event in which to resume the profiling."
);
28
declareProperty(
"PauseEvent"
,
m_pauseEvent
= -1,
29
"Event in which to pause the profiling. Negative number "
30
"profiles the entire event-loop."
);
31
declareProperty(
"ProfiledAlgs"
,
m_algs
,
32
"List of profiled algorithms."
);
33
34
}
35
39
StatusCode
VTuneProfilerService::initialize
() {
40
41
// Print information
42
ATH_MSG_INFO
(
"Initializing VTuneProfilerService"
);
43
44
// Use the auditor if a list of algorithms is provided
45
if
(!
m_algs
.empty()) {
46
47
// Resume/Pause event don't work in conjuction w/ a list of algorithms
48
ATH_MSG_INFO
(
"ResumeEvent/PauseEvent don't work in conjuction with ProfiledAlgs. "
<<
49
"Execute methods of all provided algorithms will be sampled in all events."
);
50
51
// Create the auditor
52
ATH_CHECK
( auditorSvc()->addAuditor(
"VTuneAuditor"
) );
53
}
54
55
// Set up listening to the incidents
56
CHECK
(
m_incidentSvc
.retrieve() );
57
m_incidentSvc
->addListener(
this
,
BEGINEVENT_INCIDENT_NAME
);
58
m_incidentSvc
->addListener(
this
,
ENDEVENT_INCIDENT_NAME
);
59
m_incidentSvc
->addListener(
this
,
ENDEVTLOOP_INCIDENT_NAME
);
60
61
// Reset the event counter:
62
m_processedEvents
= 0;
63
64
return
StatusCode::SUCCESS;
65
66
}
67
71
StatusCode
VTuneProfilerService::resumeProfiling
() {
72
73
// Check whether the profiling is already running:
74
if
(
m_runner
) {
75
ATH_MSG_INFO
(
"VTune profiling already running!"
);
76
return
StatusCode::SUCCESS;
77
}
78
79
// Print information
80
ATH_MSG_INFO
(
"Starting VTune profiling."
);
81
82
// Resume VTune
83
m_runner
= std::make_unique< VTuneProfileRunner >();
84
85
return
StatusCode::SUCCESS;
86
87
}
88
92
StatusCode
VTuneProfilerService::pauseProfiling
() {
93
94
// Check whether the profiling is already running:
95
if
( !
m_runner
) {
96
ATH_MSG_INFO
(
"VTune profiling is not running!"
);
97
return
StatusCode::SUCCESS;
98
}
99
100
// Print information
101
ATH_MSG_INFO
(
"Stopping VTune profiling."
);
102
103
// Pause VTune
104
m_runner
.reset();
105
106
return
StatusCode::SUCCESS;
107
108
}
109
113
bool
VTuneProfilerService::isProfilingRunning
()
const
{
114
115
return
(
m_runner
!=
nullptr
);
116
117
}
118
122
void
VTuneProfilerService::handle
(
const
Incident& inc ) {
123
124
// Use incidents only if there is no auditor
125
// Next step is to get rid of the incidents altogether
126
if
( !
m_algs
.empty() )
return
;
127
128
//
129
// Pause the profiling after the last event
130
//
131
if
( inc.type() ==
ENDEVTLOOP_INCIDENT_NAME
) {
132
if
(
m_runner
) {
133
if
(
pauseProfiling
().isFailure() ) {
134
REPORT_MESSAGE
( MSG::ERROR )
135
<<
"Could not pause the profiling"
;
136
}
137
}
138
return
;
139
}
140
141
//
142
// Resume/Pause the profiling on the right event
143
//
144
if
( inc.type() ==
BEGINEVENT_INCIDENT_NAME
) {
145
if
(
m_resumeEvent
==
m_processedEvents
&&
146
!
m_runner
) {
147
std::lock_guard<std::mutex>
lock
(
m_mutex
);
148
//double checked locking pattern
149
//https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
150
//cppcheck-suppress identicalInnerCondition
151
if
(!
m_runner
) {
152
if
(
resumeProfiling
().isFailure() ) {
153
REPORT_MESSAGE
( MSG::ERROR )
154
<<
"Could not resume the profiling"
;
155
}
156
}
157
}
158
++
m_processedEvents
;
159
return
;
160
}
161
else
if
( inc.type() ==
ENDEVENT_INCIDENT_NAME
) {
162
if
(
m_pauseEvent
==
m_processedEvents
&&
m_runner
) {
163
std::lock_guard<std::mutex>
lock
(
m_mutex
);
164
//double checked locking pattern
165
//https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
166
//cppcheck-suppress identicalInnerCondition
167
if
(
m_runner
) {
168
if
(
pauseProfiling
().isFailure() &&
169
m_runner
) {
170
REPORT_MESSAGE
( MSG::ERROR )
171
<<
"Could not pause the profiling"
;
172
}
173
}
174
}
175
return
;
176
}
177
178
// Complain if we received an incident that we didn't expect:
179
ATH_MSG_WARNING
(
"Wrong incident type received: "
<< inc.type() );
180
return
;
181
182
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
errorcheck.h
Helpers for checking error return status codes and reporting errors.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:365
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
BEGINEVENT_INCIDENT_NAME
static const std::string BEGINEVENT_INCIDENT_NAME
Definition
VTuneProfilerService.cxx:14
ENDEVENT_INCIDENT_NAME
static const std::string ENDEVENT_INCIDENT_NAME
Definition
VTuneProfilerService.cxx:15
ENDEVTLOOP_INCIDENT_NAME
static const std::string ENDEVTLOOP_INCIDENT_NAME
Definition
VTuneProfilerService.cxx:16
VTuneProfilerService.h
VTuneProfilerService::VTuneProfilerService
VTuneProfilerService(const std::string &name, ISvcLocator *svcloc)
Standard Gaudi service constructor.
Definition
VTuneProfilerService.cxx:21
VTuneProfilerService::m_runner
std::unique_ptr< VTuneProfileRunner > m_runner
Unique ptr to the VTuneProfileRunner.
Definition
VTuneProfilerService.h:66
VTuneProfilerService::m_pauseEvent
int m_pauseEvent
Property: Event in which profiling should pause.
Definition
VTuneProfilerService.h:60
VTuneProfilerService::m_algs
std::vector< std::string > m_algs
Property: List of algorithms to profile.
Definition
VTuneProfilerService.h:63
VTuneProfilerService::m_processedEvents
std::atomic< int > m_processedEvents
Number of events processed so far.
Definition
VTuneProfilerService.h:69
VTuneProfilerService::m_resumeEvent
int m_resumeEvent
Property: Event in which profiling should start.
Definition
VTuneProfilerService.h:57
VTuneProfilerService::isProfilingRunning
virtual bool isProfilingRunning() const override
Is the profiling running at the moment?
Definition
VTuneProfilerService.cxx:113
VTuneProfilerService::handle
virtual void handle(const Incident &inc) override
Function handling incoming incidents.
Definition
VTuneProfilerService.cxx:122
VTuneProfilerService::m_incidentSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
Handle to the incident service.
Definition
VTuneProfilerService.h:54
VTuneProfilerService::resumeProfiling
virtual StatusCode resumeProfiling() override
Resume profiling.
Definition
VTuneProfilerService.cxx:71
VTuneProfilerService::m_mutex
std::mutex m_mutex
Definition
VTuneProfilerService.h:71
VTuneProfilerService::pauseProfiling
virtual StatusCode pauseProfiling() override
Pause profiling.
Definition
VTuneProfilerService.cxx:92
VTuneProfilerService::initialize
virtual StatusCode initialize() override
Standard Gaudi initialization function.
Definition
VTuneProfilerService.cxx:39
Generated on
for ATLAS Offline Software by
1.17.0