ATLAS Offline Software
Loading...
Searching...
No Matches
GPT::ProfilerService Class Reference

Implementation of the IProfilerSvc interface. More...

#include <ProfilerService.h>

Inheritance diagram for GPT::ProfilerService:
Collaboration diagram for GPT::ProfilerService:

Public Member Functions

 ProfilerService (const std::string &name, ISvcLocator *svcloc)
 Standard Gaudi service constructor.
virtual ~ProfilerService ()
 Destructor.
virtual StatusCode initialize () override
 Standard Gaudi initialization function.
virtual StatusCode finalize () override
 Standard Gaudi finalization function.
virtual StatusCode startCPUProfiling (const std::string &filename) override
 Start GPT profiling.
virtual StatusCode stopCPUProfiling () override
 Stop the GPT profiling.
virtual bool isCPUProfilingRunning () const override
 Is the GPT profiling running at the moment?
virtual void handle (const Incident &inc) override
 Function handling incoming incidents.

Private Attributes

ServiceHandle< IIncidentSvc > m_incidentSvc
 Handle to the incident service.
bool m_controlledProfiling
 Property: Is profiling controlled from the outside?
int m_initEvent
 Property: Event in which non-controlled profiling should start.
std::string m_profFileName
 Property: Profile file name in non-controlled profiling.
bool m_running
 Is the CPU profiling running at the moment?
std::string m_fileName
 Name of the current profile file.
int m_processedEvents
 Number of events processed so far.

Detailed Description

Implementation of the IProfilerSvc interface.

   This service should be the only component talking directly with
   the GPT functions. Every other component should interact with
   GPT through this service.
Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 33 of file ProfilerService.h.

Constructor & Destructor Documentation

◆ ProfilerService()

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

Standard Gaudi service constructor.

Definition at line 27 of file ProfilerService.cxx.

28 : base_class( name, svcloc ),
29 m_incidentSvc( "IncidentSvc", name ),
30 m_running( false ), m_fileName( "" ), m_processedEvents( 0 ) {
31
32 declareProperty( "ControlledProfiling", m_controlledProfiling = false,
33 "Will the service be controlled by another component?" );
34 declareProperty( "InitEvent", m_initEvent = -1,
35 "Event in which to start the profiling. Negative number "
36 "profiles the entire job." );
37 declareProperty( "ProfileFileName", m_profFileName = "gpt.profile",
38 "Profile file name in con-controlled mode." );
39 }
bool m_running
Is the CPU profiling running at the moment?
ServiceHandle< IIncidentSvc > m_incidentSvc
Handle to the incident service.
int m_initEvent
Property: Event in which non-controlled profiling should start.
std::string m_fileName
Name of the current profile file.
int m_processedEvents
Number of events processed so far.
bool m_controlledProfiling
Property: Is profiling controlled from the outside?
std::string m_profFileName
Property: Profile file name in non-controlled profiling.

◆ ~ProfilerService()

GPT::ProfilerService::~ProfilerService ( )
virtual

Destructor.

Definition at line 41 of file ProfilerService.cxx.

41 {
42
43 // Stop the CPU profiling at this point if it's still running:
44 if( m_running ) {
45 stop().ignore();
46 }
47 }

Member Function Documentation

◆ finalize()

StatusCode GPT::ProfilerService::finalize ( )
overridevirtual

Standard Gaudi finalization function.

Definition at line 81 of file ProfilerService.cxx.

81 {
82
83 ATH_MSG_INFO( "Finalizing GPT::ProfilerService" );
84
85 // The profiling should only be stopped in the destructor even if we
86 // are not under user control...
87
88 return StatusCode::SUCCESS;
89 }
#define ATH_MSG_INFO(x)

◆ handle()

void GPT::ProfilerService::handle ( const Incident & inc)
overridevirtual

Function handling incoming incidents.

The event loop is profiled by listening to incidents coming from the event loop manager.

This function is called every time an "interesting" incident happens.

Parameters
incThe incident that happened

Definition at line 167 of file ProfilerService.cxx.

167 {
168
169 //
170 // Stop the profiling after the last event, if we are only profiling
171 // the event loop:
172 //
173 if( ( inc.type() == ENDEVTLOOP_INCIDENT_NAME ) &&
174 ( ! m_controlledProfiling ) &&
175 ( m_initEvent >= 0 ) ) {
176 if( stopCPUProfiling().isFailure() ) {
177 REPORT_MESSAGE( MSG::ERROR )
178 << "Could not stop the CPU profiling";
179 }
180 return;
181 }
182
183 //
184 // Start the profiling if we only profile the event loop,
185 // and we're in the correct event:
186 //
187 if( ( inc.type() == BEGINEVENT_INCIDENT_NAME ) &&
188 ( ! m_controlledProfiling ) ) {
190 if( startCPUProfiling( m_profFileName ).isFailure() ) {
191 REPORT_MESSAGE( MSG::ERROR )
192 << "Could not start the CPU profiling";
193 }
194 }
196 return;
197 }
198
199 // Complain if we received an incident that we didn't expect:
200 ATH_MSG_WARNING( "Wrong incident type received: " << inc.type() );
201 return;
202 }
#define ATH_MSG_WARNING(x)
#define REPORT_MESSAGE(LVL)
Report a message.
virtual StatusCode stopCPUProfiling() override
Stop the GPT profiling.
virtual StatusCode startCPUProfiling(const std::string &filename) override
Start GPT profiling.
static const std::string ENDEVTLOOP_INCIDENT_NAME
static const std::string BEGINEVENT_INCIDENT_NAME

◆ initialize()

StatusCode GPT::ProfilerService::initialize ( )
overridevirtual

Standard Gaudi initialization function.

Definition at line 49 of file ProfilerService.cxx.

49 {
50
51 ATH_MSG_INFO( "Initializing GPT::ProfilerService" );
52
53 // Don't do anything fancy if the profiling is under user control, just
54 // remind the user of it:
56 ATH_MSG_INFO( " Profiling is under user control" );
57 return StatusCode::SUCCESS;
58 }
59
60 // Start the profiling at this point if full-job profiling is requested:
61 if( m_initEvent < 0 ) {
62
64
65 } else {
66
67 // Set up listening to the incidents only if we are profiling the
68 // event loop with this service:
69 CHECK( m_incidentSvc.retrieve() );
70 m_incidentSvc->addListener( this, BEGINEVENT_INCIDENT_NAME );
71 m_incidentSvc->addListener( this, ENDEVTLOOP_INCIDENT_NAME );
72
73 }
74
75 // Reset the event counter:
77
78 return StatusCode::SUCCESS;
79 }
#define CHECK(...)
Evaluate an expression and check for errors.

◆ isCPUProfilingRunning()

bool GPT::ProfilerService::isCPUProfilingRunning ( ) const
overridevirtual

Is the GPT profiling running at the moment?

This function can be used to ask the service whether CPU profiling is running at the moment.

Returns
true if the profiling is running at the moment, false otherwise

Definition at line 155 of file ProfilerService.cxx.

155 {
156
157 return m_running;
158 }

◆ startCPUProfiling()

StatusCode GPT::ProfilerService::startCPUProfiling ( const std::string & filename)
overridevirtual

Start GPT profiling.

This function can be used to start the profiling, collecting the data into a file with the specified name.

Parameters
filenameName of the GPT profile file
Returns
StatusCode::SUCCESS if the operation was successful, something else otherwise

Definition at line 99 of file ProfilerService.cxx.

99 {
100
101 // Check whether the CPU profiling is already running:
102 if( m_running ) {
104 }
105
106 // Tell the user what's happening:
107 ATH_MSG_INFO( "Starting CPU profiling using output file: " << filename );
108
109 // Remember the profile file name:
111
112 // Start the Google profiler:
113 ProfilerStart( m_fileName.c_str() );
114
115 // Remember that we are in a running state:
116 m_running = true;
117
118 return StatusCode::SUCCESS;
119 }

◆ stopCPUProfiling()

StatusCode GPT::ProfilerService::stopCPUProfiling ( )
overridevirtual

Stop the GPT profiling.

This function should be called to stop the CPU profiling.

Returns
StatusCode::SUCCESS if the operation was successful, something else otherwise

Definition at line 127 of file ProfilerService.cxx.

127 {
128
129 // This should not be called when we are not running:
130 if( ! m_running ) {
131 REPORT_MESSAGE( MSG::ERROR )
132 << "CPU profiling not running at the time of call";
133 return StatusCode::RECOVERABLE;
134 }
135
136 // Stop the profiler:
137 ProfilerStop();
138
139 // Tell the user what happened:
140 ATH_MSG_INFO( "Stopped CPU profiling using output file: " << m_fileName );
141
142 // Remember that we are not running anymore:
143 m_running = false;
144
145 return StatusCode::SUCCESS;
146 }

Member Data Documentation

◆ m_controlledProfiling

bool GPT::ProfilerService::m_controlledProfiling
private

Property: Is profiling controlled from the outside?

Definition at line 63 of file ProfilerService.h.

◆ m_fileName

std::string GPT::ProfilerService::m_fileName
private

Name of the current profile file.

Definition at line 72 of file ProfilerService.h.

◆ m_incidentSvc

ServiceHandle< IIncidentSvc > GPT::ProfilerService::m_incidentSvc
private

Handle to the incident service.

Definition at line 60 of file ProfilerService.h.

◆ m_initEvent

int GPT::ProfilerService::m_initEvent
private

Property: Event in which non-controlled profiling should start.

Definition at line 65 of file ProfilerService.h.

◆ m_processedEvents

int GPT::ProfilerService::m_processedEvents
private

Number of events processed so far.

Definition at line 75 of file ProfilerService.h.

◆ m_profFileName

std::string GPT::ProfilerService::m_profFileName
private

Property: Profile file name in non-controlled profiling.

Definition at line 67 of file ProfilerService.h.

◆ m_running

bool GPT::ProfilerService::m_running
private

Is the CPU profiling running at the moment?

Definition at line 70 of file ProfilerService.h.


The documentation for this class was generated from the following files: