ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
VTuneProfilerService Class Reference

#include <VTuneProfilerService.h>

Inheritance diagram for VTuneProfilerService:
Collaboration diagram for VTuneProfilerService:

Public Member Functions

 VTuneProfilerService (const std::string &name, ISvcLocator *svcloc)
 Standard Gaudi service constructor. More...
 
virtual StatusCode initialize () override
 Standard Gaudi initialization function. More...
 
virtual StatusCode resumeProfiling () override
 Resume profiling. More...
 
virtual StatusCode pauseProfiling () override
 Pause profiling. More...
 
virtual bool isProfilingRunning () const override
 Is the profiling running at the moment? More...
 
virtual void handle (const Incident &inc) override
 Function handling incoming incidents. More...
 

Private Attributes

ServiceHandle< IIncidentSvc > m_incidentSvc
 Handle to the incident service. More...
 
int m_resumeEvent
 Property: Event in which profiling should start. More...
 
int m_pauseEvent
 Property: Event in which profiling should pause. More...
 
std::vector< std::string > m_algs
 Property: List of algorithms to profile. More...
 
std::unique_ptr< VTuneProfileRunnerm_runner
 Unique ptr to the VTuneProfileRunner. More...
 
std::atomic< int > m_processedEvents
 Number of events processed so far. More...
 
std::mutex m_mutex
 

Detailed Description

Definition at line 27 of file VTuneProfilerService.h.

Constructor & Destructor Documentation

◆ VTuneProfilerService()

VTuneProfilerService::VTuneProfilerService ( const std::string &  name,
ISvcLocator *  svcloc 
)

Standard Gaudi service constructor.

Constructor.

Definition at line 21 of file VTuneProfilerService.cxx.

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 }

Member Function Documentation

◆ handle()

void VTuneProfilerService::handle ( const Incident &  inc)
overridevirtual

Function handling incoming incidents.

Handle when to resume/pause the profiling.

Definition at line 122 of file VTuneProfilerService.cxx.

122  {
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 ) {
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  }
159  return;
160  }
161  else if( inc.type() == ENDEVENT_INCIDENT_NAME ) {
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 }

◆ initialize()

StatusCode VTuneProfilerService::initialize ( )
overridevirtual

Standard Gaudi initialization function.

Initalize the service.

Definition at line 39 of file VTuneProfilerService.cxx.

39  {
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:
63 
64  return StatusCode::SUCCESS;
65 
66 }

◆ isProfilingRunning()

bool VTuneProfilerService::isProfilingRunning ( ) const
overridevirtual

Is the profiling running at the moment?

Is the profiling running?

Definition at line 113 of file VTuneProfilerService.cxx.

113  {
114 
115  return (m_runner!=nullptr);
116 
117 }

◆ pauseProfiling()

StatusCode VTuneProfilerService::pauseProfiling ( )
overridevirtual

Pause profiling.

Pause the profiling.

Definition at line 92 of file VTuneProfilerService.cxx.

92  {
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 }

◆ resumeProfiling()

StatusCode VTuneProfilerService::resumeProfiling ( )
overridevirtual

Resume profiling.

Resume the profiling.

Definition at line 71 of file VTuneProfilerService.cxx.

71  {
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 }

Member Data Documentation

◆ m_algs

std::vector<std::string> VTuneProfilerService::m_algs
private

Property: List of algorithms to profile.

Definition at line 63 of file VTuneProfilerService.h.

◆ m_incidentSvc

ServiceHandle< IIncidentSvc > VTuneProfilerService::m_incidentSvc
private

Handle to the incident service.

Definition at line 54 of file VTuneProfilerService.h.

◆ m_mutex

std::mutex VTuneProfilerService::m_mutex
private

Definition at line 71 of file VTuneProfilerService.h.

◆ m_pauseEvent

int VTuneProfilerService::m_pauseEvent
private

Property: Event in which profiling should pause.

Definition at line 60 of file VTuneProfilerService.h.

◆ m_processedEvents

std::atomic<int> VTuneProfilerService::m_processedEvents
private

Number of events processed so far.

Definition at line 69 of file VTuneProfilerService.h.

◆ m_resumeEvent

int VTuneProfilerService::m_resumeEvent
private

Property: Event in which profiling should start.

Definition at line 57 of file VTuneProfilerService.h.

◆ m_runner

std::unique_ptr< VTuneProfileRunner > VTuneProfilerService::m_runner
private

Unique ptr to the VTuneProfileRunner.

Definition at line 66 of file VTuneProfilerService.h.


The documentation for this class was generated from the following files:
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
VTuneProfilerService::m_incidentSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
Handle to the incident service.
Definition: VTuneProfilerService.h:54
VTuneProfilerService::pauseProfiling
virtual StatusCode pauseProfiling() override
Pause profiling.
Definition: VTuneProfilerService.cxx:92
VTuneProfilerService::m_processedEvents
std::atomic< int > m_processedEvents
Number of events processed so far.
Definition: VTuneProfilerService.h:69
VTuneProfilerService::resumeProfiling
virtual StatusCode resumeProfiling() override
Resume profiling.
Definition: VTuneProfilerService.cxx:71
VTuneProfilerService::m_resumeEvent
int m_resumeEvent
Property: Event in which profiling should start.
Definition: VTuneProfilerService.h:57
VTuneProfilerService::m_mutex
std::mutex m_mutex
Definition: VTuneProfilerService.h:71
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
VTuneProfilerService::m_pauseEvent
int m_pauseEvent
Property: Event in which profiling should pause.
Definition: VTuneProfilerService.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
VTuneProfilerService::m_runner
std::unique_ptr< VTuneProfileRunner > m_runner
Unique ptr to the VTuneProfileRunner.
Definition: VTuneProfilerService.h:66
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
VTuneProfilerService::m_algs
std::vector< std::string > m_algs
Property: List of algorithms to profile.
Definition: VTuneProfilerService.h:63