ATLAS Offline Software
Public Member Functions | Private 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 Member Functions

StatusCode makeAuditor (const std::string &audName, IAuditorSvc *audSvc)
 Helper method to create auditors. 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 132 of file VTuneProfilerService.cxx.

132  {
133 
134  // Use incidents only if there is no auditor
135  // Next step is to get rid of the incidents altogether
136  if ( !m_algs.empty() ) return;
137 
138  //
139  // Pause the profiling after the last event
140  //
141  if( inc.type() == ENDEVTLOOP_INCIDENT_NAME ) {
142  if( m_runner ) {
143  if( pauseProfiling().isFailure() ) {
144  REPORT_MESSAGE( MSG::ERROR )
145  << "Could not pause the profiling";
146  }
147  }
148  return;
149  }
150 
151  //
152  // Resume/Pause the profiling on the right event
153  //
154  if( inc.type() == BEGINEVENT_INCIDENT_NAME ) {
156  !m_runner ) {
157  std::lock_guard<std::mutex> lock(m_mutex);
158  //double checked locking pattern
159  //https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
160  //cppcheck-suppress identicalInnerCondition
161  if (!m_runner) {
162  if( resumeProfiling().isFailure() ) {
163  REPORT_MESSAGE( MSG::ERROR )
164  << "Could not resume the profiling";
165  }
166  }
167  }
169  return;
170  }
171  else if( inc.type() == ENDEVENT_INCIDENT_NAME ) {
173  std::lock_guard<std::mutex> lock(m_mutex);
174  //double checked locking pattern
175  //https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
176  //cppcheck-suppress identicalInnerCondition
177  if (m_runner) {
178  if( pauseProfiling().isFailure() &&
179  m_runner ) {
180  REPORT_MESSAGE( MSG::ERROR )
181  << "Could not pause the profiling";
182  }
183  }
184  }
185  return;
186  }
187 
188  // Complain if we received an incident that we didn't expect:
189  ATH_MSG_WARNING( "Wrong incident type received: " << inc.type() );
190  return;
191 
192 }

◆ 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  makeAuditor("VTuneAuditor",auditorSvc()).ignore();
53 
54  // Check if the auditor is correctly created
55  if ((auditorSvc()==0) || auditorSvc()->getAuditor("VTuneAuditor")==0) {
56  ATH_MSG_ERROR ("Cannot find [VTuneAuditor]. ");
57  return StatusCode::FAILURE;
58  }
59  else {
60  ATH_MSG_VERBOSE ("Found [VTuneAuditor].");
61  }
62 
63  }
64 
65  // Set up listening to the incidents
66  CHECK( m_incidentSvc.retrieve() );
67  m_incidentSvc->addListener( this, BEGINEVENT_INCIDENT_NAME );
68  m_incidentSvc->addListener( this, ENDEVENT_INCIDENT_NAME );
69  m_incidentSvc->addListener( this, ENDEVTLOOP_INCIDENT_NAME );
70 
71  // Reset the event counter:
73 
74  return StatusCode::SUCCESS;
75 
76 }

◆ isProfilingRunning()

bool VTuneProfilerService::isProfilingRunning ( ) const
overridevirtual

Is the profiling running at the moment?

Is the profiling running?

Definition at line 123 of file VTuneProfilerService.cxx.

123  {
124 
125  return (m_runner!=nullptr);
126 
127 }

◆ makeAuditor()

StatusCode VTuneProfilerService::makeAuditor ( const std::string &  audName,
IAuditorSvc *  audSvc 
)
private

Helper method to create auditors.

Create the auditor here ala PerfMonComps/PerfMonUtils.

Definition at line 197 of file VTuneProfilerService.cxx.

199 {
200  if ( 0 == audSvc ) {
201  ATH_MSG_ERROR ("Null pointer to IAuditorSvc !!");
202  return StatusCode::FAILURE;
203  }
204 
205  if ( 0 != audSvc->getAuditor( audName ) ) {
206  ATH_MSG_VERBOSE ("AuditorSvc already knows about ["
207  << audName << "]... good.");
208  return StatusCode::SUCCESS;
209  }
210 
211  const std::string propName = "Auditors";
212  IProperty * audSvcProp = dynamic_cast<IProperty*>(audSvc);
213 
214  if ( 0 == audSvcProp ) {
215  ATH_MSG_ERROR ("Could not dyn-cast IAuditorSvc to an IProperty !!");
216  return StatusCode::FAILURE;
217  }
218 
219  StringArrayProperty audNames;
220  audNames.assign( audSvcProp->getProperty(propName) );
221  std::vector<std::string> updatedNames( audNames.value() );
222  updatedNames.push_back( audName );
223  audNames.set( updatedNames );
224  audNames.setName( propName );
225  if ( !audSvcProp->setProperty( audNames ).isSuccess() ) {
227  ("Could not add [" << audName
228  << "] to the list of auditors of [AuditorSvc] !!"
229  << endmsg
230  << audSvcProp->getProperty(propName));
231  return StatusCode::FAILURE;
232  }
233 
234  // make sure the auditor has been created...
235  if ( 0 == audSvc->getAuditor( audName ) ) {
236  ATH_MSG_ERROR ("Failed to make AuditorSvc instantiating ["
237  << audName << "] !!");
238  return StatusCode::FAILURE;
239  }
240 
241  ATH_MSG_VERBOSE ("[" << audName << "] successfully created.");
242  return StatusCode::SUCCESS;
243 }

◆ pauseProfiling()

StatusCode VTuneProfilerService::pauseProfiling ( )
overridevirtual

Pause profiling.

Pause the profiling.

Definition at line 102 of file VTuneProfilerService.cxx.

102  {
103 
104  // Check whether the profiling is already running:
105  if( !m_runner ) {
106  ATH_MSG_INFO( "VTune profiling is not running!" );
107  return StatusCode::SUCCESS;
108  }
109 
110  // Print information
111  ATH_MSG_INFO( "Stopping VTune profiling." );
112 
113  // Pause VTune
114  m_runner.reset();
115 
116  return StatusCode::SUCCESS;
117 
118 }

◆ resumeProfiling()

StatusCode VTuneProfilerService::resumeProfiling ( )
overridevirtual

Resume profiling.

Resume the profiling.

Definition at line 81 of file VTuneProfilerService.cxx.

81  {
82 
83  // Check whether the profiling is already running:
84  if( m_runner ) {
85  ATH_MSG_INFO( "VTune profiling already running!" );
86  return StatusCode::SUCCESS;
87  }
88 
89  // Print information
90  ATH_MSG_INFO( "Starting VTune profiling." );
91 
92  // Resume VTune
93  m_runner = std::make_unique< VTuneProfileRunner >();
94 
95  return StatusCode::SUCCESS;
96 
97 }

Member Data Documentation

◆ m_algs

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

Property: List of algorithms to profile.

Definition at line 66 of file VTuneProfilerService.h.

◆ m_incidentSvc

ServiceHandle< IIncidentSvc > VTuneProfilerService::m_incidentSvc
private

Handle to the incident service.

Definition at line 57 of file VTuneProfilerService.h.

◆ m_mutex

std::mutex VTuneProfilerService::m_mutex
private

Definition at line 74 of file VTuneProfilerService.h.

◆ m_pauseEvent

int VTuneProfilerService::m_pauseEvent
private

Property: Event in which profiling should pause.

Definition at line 63 of file VTuneProfilerService.h.

◆ m_processedEvents

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

Number of events processed so far.

Definition at line 72 of file VTuneProfilerService.h.

◆ m_resumeEvent

int VTuneProfilerService::m_resumeEvent
private

Property: Event in which profiling should start.

Definition at line 60 of file VTuneProfilerService.h.

◆ m_runner

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

Unique ptr to the VTuneProfileRunner.

Definition at line 69 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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
VTuneProfilerService::m_incidentSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
Handle to the incident service.
Definition: VTuneProfilerService.h:57
VTuneProfilerService::pauseProfiling
virtual StatusCode pauseProfiling() override
Pause profiling.
Definition: VTuneProfilerService.cxx:102
VTuneProfilerService::m_processedEvents
std::atomic< int > m_processedEvents
Number of events processed so far.
Definition: VTuneProfilerService.h:72
VTuneProfilerService::resumeProfiling
virtual StatusCode resumeProfiling() override
Resume profiling.
Definition: VTuneProfilerService.cxx:81
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
VTuneProfilerService::m_resumeEvent
int m_resumeEvent
Property: Event in which profiling should start.
Definition: VTuneProfilerService.h:60
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
VTuneProfilerService::m_mutex
std::mutex m_mutex
Definition: VTuneProfilerService.h:74
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:63
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
L1CaloPhase1Monitoring.propName
propName
Definition: L1CaloPhase1Monitoring.py:451
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
VTuneProfilerService::makeAuditor
StatusCode makeAuditor(const std::string &audName, IAuditorSvc *audSvc)
Helper method to create auditors.
Definition: VTuneProfilerService.cxx:197
VTuneProfilerService::m_runner
std::unique_ptr< VTuneProfileRunner > m_runner
Unique ptr to the VTuneProfileRunner.
Definition: VTuneProfilerService.h:69
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:66