The Gaudi Framework  master (37c0b60a)
JemallocProfileSvc Class Reference

#include <jemalloc/JemallocProfileSvc.h>

Inheritance diagram for JemallocProfileSvc:
Collaboration diagram for JemallocProfileSvc:

Public Member Functions

StatusCode initialize () override
 Initializer. More...
 
StatusCode finalize () override
 Finalizer. More...
 
void handle (const Incident &incident) override
 
- Public Member Functions inherited from extends< Service, IIncidentListener >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service
More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service
More...
 
StatusCode sysStart () override
 Initialize Service
More...
 
StatusCode sysStop () override
 Initialize Service
More...
 
StatusCode sysFinalize () override
 Finalize Service
More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator
More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T >
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Protected Member Functions

void handleBegin ()
 
void handleEnd ()
 
void startProfiling ()
 Utility method to start profiling with jemalloc. More...
 
void stopProfiling ()
 Utility method to stop profiling with jemalloc. More...
 
void dumpProfile ()
 Utility method to dump profile with jemalloc. More...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 Standard Destructor
More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Private Attributes

Gaudi::Property< int > m_nStartFromEvent { this, "StartFromEventN", 0, "After what event we start profiling." }
 
Gaudi::Property< std::vector< std::string > > m_startFromIncidents
 
Gaudi::Property< int > m_nStopAtEvent
 
Gaudi::Property< std::vector< std::string > > m_stopAtIncidents
 
Gaudi::Property< int > m_dumpPeriod { this, "DumpPeriod", 100, "Period for dumping head to a file. Default=100" }
 
int m_eventNumber = 0
 Current event number. More...
 
bool m_hasStartIncident = false
 
bool m_hasStopIncident = false
 
bool m_profiling = false
 Status of the profiling. More...
 
SmartIF< IIncidentSvcm_incidentSvc
 Pointer to the incident service. More...
 

Additional Inherited Members

- Public Types inherited from extends< Service, IIncidentListener >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
Gaudi::Property< bool > m_auditInit { this, "AuditServices", false, "[[deprecated]] unused" }
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service
More...
 

Detailed Description

Service that enables the Jemalloc profiler on demand. By default, the profiling is diabled, the user needs to set incidents at which to start/stop the profiling, or specify incidents for that purpose.

Author
Ben Couturier
Date
2016-01-12

Definition at line 28 of file JemallocProfileSvc.h.

Member Function Documentation

◆ dumpProfile()

void JemallocProfileSvc::dumpProfile ( )
inlineprotected

Utility method to dump profile with jemalloc.

Definition at line 162 of file JemallocProfileSvc.cpp.

162  {
163  info() << "Dumping Jemalloc profile at event " << m_eventNumber << endmsg;
164  mallctl( "prof.dump", NULL, NULL, NULL, 0 );
165 }

◆ finalize()

StatusCode JemallocProfileSvc::finalize ( )
override

Finalizer.

Definition at line 73 of file JemallocProfileSvc.cpp.

73  {
74  if ( m_profiling ) { stopProfiling(); }
75  // unregistering from the IncidentSvc
76  m_incidentSvc->removeListener( this, IncidentType::BeginEvent );
77  m_incidentSvc->removeListener( this, IncidentType::EndEvent );
79  return base_class::finalize();
80 }

◆ handle()

void JemallocProfileSvc::handle ( const Incident incident)
override

Definition at line 88 of file JemallocProfileSvc.cpp.

88  {
89  if ( IncidentType::BeginEvent == incident.type() ) {
90  handleBegin();
91  } else if ( IncidentType::EndEvent == incident.type() ) {
92  handleEnd();
93  }
94 
95  // If already processing we can ignore the incidents for start
96  if ( !m_profiling && m_hasStartIncident ) {
97  for ( const std::string& startincident : m_startFromIncidents ) {
98  if ( startincident == incident.type() ) {
99  info() << "Starting Jemalloc profile at incident " << incident.type() << endmsg;
100  startProfiling();
101  break;
102  }
103  } // Loop on incidents
104  } // If checking incidents to start
105 
106  // If already processing we can ignore the incidents for start
107  if ( m_profiling && m_hasStopIncident ) {
108  for ( const std::string& stopincident : m_stopAtIncidents ) {
109  if ( stopincident == incident.type() ) {
110  info() << "Stopping Jemalloc profile at incident " << incident.type() << endmsg;
111  stopProfiling();
112  break;
113  }
114  } // Loop on incidents
115  } // If checking incidents to stop
116 }

◆ handleBegin()

void JemallocProfileSvc::handleBegin ( )
inlineprotected

Definition at line 120 of file JemallocProfileSvc.cpp.

120  {
121  m_eventNumber += 1;
122 
124 }

◆ handleEnd()

void JemallocProfileSvc::handleEnd ( )
inlineprotected

Definition at line 128 of file JemallocProfileSvc.cpp.

128  {
130  ( ( m_eventNumber - m_nStartFromEvent ) % m_dumpPeriod == 0 ) ) {
131  dumpProfile();
132  }
133 
135 }

◆ initialize()

StatusCode JemallocProfileSvc::initialize ( )
override

Initializer.

Definition at line 37 of file JemallocProfileSvc.cpp.

37  {
38  StatusCode sc = base_class::initialize();
39  if ( sc.isFailure() ) return sc;
40 
41  // register to the incident service
42  static const std::string serviceName = "IncidentSvc";
43  m_incidentSvc = serviceLocator()->service( serviceName );
44  if ( !m_incidentSvc ) {
45  error() << "Cannot retrieve " << serviceName << endmsg;
46  return StatusCode::FAILURE;
47  }
48 
49  debug() << "Register to the IncidentSvc" << endmsg;
50  m_incidentSvc->addListener( this, IncidentType::BeginEvent );
51  m_incidentSvc->addListener( this, IncidentType::EndEvent );
52  for ( std::string incident : m_startFromIncidents ) { m_incidentSvc->addListener( this, incident ); }
53  for ( std::string incident : m_stopAtIncidents ) { m_incidentSvc->addListener( this, incident ); }
54 
55  // Resetting the event counter
56  m_eventNumber = 0;
57  m_profiling = false;
58 
59  // Cache whether we have start/stop incidents
61  m_hasStopIncident = ( m_stopAtIncidents.size() > 0 );
62 
63  // Checking the consistency of the start/stop events
65  info() << "Stop profiling trigger was specified but no start. Defaulting to first events" << endmsg;
67  }
68 
69  return StatusCode::SUCCESS;
70 }

◆ startProfiling()

void JemallocProfileSvc::startProfiling ( )
inlineprotected

Utility method to start profiling with jemalloc.

Definition at line 145 of file JemallocProfileSvc.cpp.

145  {
146  m_profiling = true;
147  info() << "Starting Jemalloc profile at event " << m_eventNumber << endmsg;
148  mallctl( "prof.dump", NULL, NULL, NULL, 0 );
149 }

◆ stopProfiling()

void JemallocProfileSvc::stopProfiling ( )
inlineprotected

Utility method to stop profiling with jemalloc.

Definition at line 154 of file JemallocProfileSvc.cpp.

154  {
155  m_profiling = false;
156  dumpProfile();
157 }

Member Data Documentation

◆ m_dumpPeriod

Gaudi::Property<int> JemallocProfileSvc::m_dumpPeriod { this, "DumpPeriod", 100, "Period for dumping head to a file. Default=100" }
private

Definition at line 59 of file JemallocProfileSvc.h.

◆ m_eventNumber

int JemallocProfileSvc::m_eventNumber = 0
private

Current event number.

Definition at line 62 of file JemallocProfileSvc.h.

◆ m_hasStartIncident

bool JemallocProfileSvc::m_hasStartIncident = false
private

Definition at line 64 of file JemallocProfileSvc.h.

◆ m_hasStopIncident

bool JemallocProfileSvc::m_hasStopIncident = false
private

Definition at line 65 of file JemallocProfileSvc.h.

◆ m_incidentSvc

SmartIF<IIncidentSvc> JemallocProfileSvc::m_incidentSvc
private

Pointer to the incident service.

Definition at line 71 of file JemallocProfileSvc.h.

◆ m_nStartFromEvent

Gaudi::Property<int> JemallocProfileSvc::m_nStartFromEvent { this, "StartFromEventN", 0, "After what event we start profiling." }
private

Definition at line 51 of file JemallocProfileSvc.h.

◆ m_nStopAtEvent

Gaudi::Property<int> JemallocProfileSvc::m_nStopAtEvent
private
Initial value:
{
this, "StopAtEventN", 0,
"After what event we stop profiling. If 0 than we also profile finalization stage. Default = 0." }

Definition at line 54 of file JemallocProfileSvc.h.

◆ m_profiling

bool JemallocProfileSvc::m_profiling = false
private

Status of the profiling.

Definition at line 68 of file JemallocProfileSvc.h.

◆ m_startFromIncidents

Gaudi::Property<std::vector<std::string> > JemallocProfileSvc::m_startFromIncidents
private
Initial value:
{
this, "StartFromIncidents", {}, "Incidents that trigger profiling start" }

Definition at line 52 of file JemallocProfileSvc.h.

◆ m_stopAtIncidents

Gaudi::Property<std::vector<std::string> > JemallocProfileSvc::m_stopAtIncidents
private
Initial value:
{
this, "StopAtIncidents", {}, "Incidents that trigger profiling start" }

Definition at line 57 of file JemallocProfileSvc.h.


The documentation for this class was generated from the following files:
JemallocProfileSvc::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
Definition: JemallocProfileSvc.h:71
std::string
STL class.
JemallocProfileSvc::m_hasStopIncident
bool m_hasStopIncident
Definition: JemallocProfileSvc.h:65
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
JemallocProfileSvc::m_nStartFromEvent
Gaudi::Property< int > m_nStartFromEvent
Definition: JemallocProfileSvc.h:51
mallctl
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
JemallocProfileSvc::m_nStopAtEvent
Gaudi::Property< int > m_nStopAtEvent
Definition: JemallocProfileSvc.h:54
JemallocProfileSvc::m_stopAtIncidents
Gaudi::Property< std::vector< std::string > > m_stopAtIncidents
Definition: JemallocProfileSvc.h:57
StatusCode
Definition: StatusCode.h:65
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
JemallocProfileSvc::startProfiling
void startProfiling()
Utility method to start profiling with jemalloc.
Definition: JemallocProfileSvc.cpp:145
JemallocProfileSvc::handleBegin
void handleBegin()
Definition: JemallocProfileSvc.cpp:120
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
JemallocProfileSvc::dumpProfile
void dumpProfile()
Utility method to dump profile with jemalloc.
Definition: JemallocProfileSvc.cpp:162
JemallocProfileSvc::handleEnd
void handleEnd()
Definition: JemallocProfileSvc.cpp:128
JemallocProfileSvc::m_profiling
bool m_profiling
Status of the profiling.
Definition: JemallocProfileSvc.h:68
JemallocProfileSvc::stopProfiling
void stopProfiling()
Utility method to stop profiling with jemalloc.
Definition: JemallocProfileSvc.cpp:154
JemallocProfileSvc::m_dumpPeriod
Gaudi::Property< int > m_dumpPeriod
Definition: JemallocProfileSvc.h:59
JemallocProfileSvc::m_hasStartIncident
bool m_hasStartIncident
Definition: JemallocProfileSvc.h:64
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:48
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
JemallocProfileSvc::m_eventNumber
int m_eventNumber
Current event number.
Definition: JemallocProfileSvc.h:62
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:335
JemallocProfileSvc::m_startFromIncidents
Gaudi::Property< std::vector< std::string > > m_startFromIncidents
Definition: JemallocProfileSvc.h:52