JemallocProfileSvc Class Reference

Service that enables the Jemalloc profiler on demand. More...

#include <jemalloc/JemallocProfileSvc.h>

Inheritance diagram for JemallocProfileSvc:
Collaboration diagram for JemallocProfileSvc:

Public Member Functions

 JemallocProfileSvc (const std::string &name, ISvcLocator *svcLoc)
 Standard constructor. More...
 
StatusCode initialize ()
 Initializer. More...
 
StatusCode finalize ()
 Finalizer. More...
 
void handle (const Incident &incident)
 Destructor. More...
 
virtual ~JemallocProfileSvc ()
 
- 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...
 
 ~extends () override=default
 Virtual destructor. 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...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. 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 >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. 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
 ~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 > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Private Attributes

int m_nStartFromEvent
 Start, End event and counter. More...
 
int m_nStopAtEvent
 
int m_dumpPeriod
 
int m_eventNumber
 
std::vector< std::stringm_startFromIncidents
 
std::vector< std::stringm_stopAtIncidents
 
bool m_hasStartIncident
 
bool m_hasStopIncident
 
bool m_profiling
 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
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- 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
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. 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 18 of file JemallocProfileSvc.h.

Constructor & Destructor Documentation

JemallocProfileSvc::JemallocProfileSvc ( const std::string name,
ISvcLocator svcLoc 
)

Standard constructor.

Definition at line 28 of file JemallocProfileSvc.cpp.

28  :
29  base_class(name, svcLoc), m_eventNumber(0), m_startFromIncidents({}),
31  m_profiling(false) {
32 
33  declareProperty("StartFromEventN", m_nStartFromEvent = 0,
34  "After what event we start profiling. "
35  );
36 
37  declareProperty("StartFromIncidents", m_startFromIncidents = {},
38  "Incidents that trigger profiling start"
39  );
40 
41  declareProperty("StopAtEventN", m_nStopAtEvent = 0,
42  "After what event we stop profiling. "
43  "If 0 than we also profile finalization stage. Default = 0."
44  );
45 
46  declareProperty("StopAtIncidents", m_stopAtIncidents = {},
47  "Incidents that trigger profiling start"
48  );
49 
50  declareProperty("DumpPeriod", m_dumpPeriod = 100,
51  "Period for dumping head to a file. Default=100"
52  );
53 
54 }
std::vector< std::string > m_stopAtIncidents
extends base_class
Typedef to this class.
Definition: extends.h:14
std::vector< std::string > m_startFromIncidents
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
int m_nStartFromEvent
Start, End event and counter.
bool m_profiling
Status of the profiling.
JemallocProfileSvc::~JemallocProfileSvc ( )
virtual

Definition at line 233 of file JemallocProfileSvc.cpp.

233 {}

Member Function Documentation

void JemallocProfileSvc::dumpProfile ( )
inlineprotected

Utility method to dump profile with jemalloc.

Definition at line 220 of file JemallocProfileSvc.cpp.

221 {
222  info() << "Dumping Jemalloc profile at event "
223  << m_eventNumber << endmsg;
224  mallctl("prof.dump", NULL, NULL, NULL, 0);
225 
226 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode JemallocProfileSvc::finalize ( )

Finalizer.

Definition at line 105 of file JemallocProfileSvc.cpp.

105  {
106 
107  // unregistering from the IncidentSvc
108  m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
109  m_incidentSvc->removeListener(this, IncidentType::EndEvent);
111  return base_class::finalize();
112 }
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
void JemallocProfileSvc::handle ( const Incident incident)

Destructor.

Definition at line 120 of file JemallocProfileSvc.cpp.

121 {
122  if (IncidentType::BeginEvent == incident.type())
123  {
124  handleBegin();
125  } else if (IncidentType::EndEvent == incident.type())
126  {
127  handleEnd();
128  }
129 
130  // If already processing we can ignore the incidents for start
132  {
133  for(std::string startincident: m_startFromIncidents)
134  {
135  if (startincident == incident.type())
136  {
137  info() << "Starting Jemalloc profile at incident "
138  << incident.type() << endmsg;
139  startProfiling();
140  break;
141  }
142  } // Loop on incidents
143  } // If checking incidents to start
144 
145  // If already processing we can ignore the incidents for start
147  {
148  for(std::string stopincident: m_stopAtIncidents)
149  {
150  if (stopincident == incident.type())
151  {
152  info() << "Stopping Jemalloc profile at incident "
153  << incident.type() << endmsg;
154  stopProfiling();
155  break;
156  }
157  } // Loop on incidents
158  } // If checking incidents to stop
159 
160 
161 }
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
void startProfiling()
Utility method to start profiling with jemalloc.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< std::string > m_stopAtIncidents
STL class.
void stopProfiling()
Utility method to stop profiling with jemalloc.
std::vector< std::string > m_startFromIncidents
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_profiling
Status of the profiling.
void JemallocProfileSvc::handleBegin ( )
inlineprotected

Definition at line 165 of file JemallocProfileSvc.cpp.

166 {
167  m_eventNumber += 1;
168 
170  {
171  startProfiling();
172  }
173 }
void startProfiling()
Utility method to start profiling with jemalloc.
int m_nStartFromEvent
Start, End event and counter.
void JemallocProfileSvc::handleEnd ( )
inlineprotected

Definition at line 177 of file JemallocProfileSvc.cpp.

178 {
179  if (m_profiling
182  {
183  dumpProfile();
184  }
185 
187  {
188  stopProfiling();
189  }
190 }
void stopProfiling()
Utility method to stop profiling with jemalloc.
void dumpProfile()
Utility method to dump profile with jemalloc.
int m_nStartFromEvent
Start, End event and counter.
bool m_profiling
Status of the profiling.
StatusCode JemallocProfileSvc::initialize ( )

Initializer.

Definition at line 59 of file JemallocProfileSvc.cpp.

59  {
61  if (sc.isFailure()) return sc;
62 
63  // register to the incident service
64  static const std::string serviceName = "IncidentSvc";
65  m_incidentSvc = serviceLocator()->service(serviceName);
66  if ( ! m_incidentSvc ) {
67  error() << "Cannot retrieve " << serviceName << endmsg;
68  return StatusCode::FAILURE;
69  }
70 
71  debug() << "Register to the IncidentSvc" << endmsg;
72  m_incidentSvc->addListener(this, IncidentType::BeginEvent);
73  m_incidentSvc->addListener(this, IncidentType::EndEvent);
74  for (std::string incident: m_startFromIncidents)
75  {
76  m_incidentSvc->addListener(this, incident);
77  }
78  for (std::string incident: m_stopAtIncidents)
79  {
80  m_incidentSvc->addListener(this, incident);
81  }
82 
83  // Resetting the event counter
84  m_eventNumber = 0;
85  m_profiling = false;
86 
87  // Cache whether we have start/stop incidents
88  m_hasStartIncident = (m_startFromIncidents.size() > 0);
89  m_hasStopIncident = (m_stopAtIncidents.size() > 0);
90 
91  // Checking the consistency of the start/stop events
94  {
95  info() << "Stop profiling trigger was specified but no start. Defaulting to first events" << endmsg;
97  }
98 
99 
100 
101  return StatusCode::SUCCESS;
102 }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
def initialize()
Definition: AnalysisTest.py:12
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< std::string > m_stopAtIncidents
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::vector< std::string > m_startFromIncidents
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
int m_nStartFromEvent
Start, End event and counter.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_profiling
Status of the profiling.
void JemallocProfileSvc::startProfiling ( )
inlineprotected

Utility method to start profiling with jemalloc.

Definition at line 200 of file JemallocProfileSvc.cpp.

201 {
202  m_profiling = true;
203  info() << "Starting Jemalloc profile at event "
204  << m_eventNumber << endmsg;
205  mallctl("prof.dump", NULL, NULL, NULL, 0);
206 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_profiling
Status of the profiling.
void JemallocProfileSvc::stopProfiling ( )
inlineprotected

Utility method to stop profiling with jemalloc.

Definition at line 211 of file JemallocProfileSvc.cpp.

212 {
213  m_profiling = false;
214  dumpProfile();
215 }
void dumpProfile()
Utility method to dump profile with jemalloc.
bool m_profiling
Status of the profiling.

Member Data Documentation

int JemallocProfileSvc::m_dumpPeriod
private

Definition at line 49 of file JemallocProfileSvc.h.

int JemallocProfileSvc::m_eventNumber
private

Definition at line 50 of file JemallocProfileSvc.h.

bool JemallocProfileSvc::m_hasStartIncident
private

Definition at line 53 of file JemallocProfileSvc.h.

bool JemallocProfileSvc::m_hasStopIncident
private

Definition at line 54 of file JemallocProfileSvc.h.

SmartIF<IIncidentSvc> JemallocProfileSvc::m_incidentSvc
private

Pointer to the incident service.

Definition at line 61 of file JemallocProfileSvc.h.

int JemallocProfileSvc::m_nStartFromEvent
private

Start, End event and counter.

Definition at line 47 of file JemallocProfileSvc.h.

int JemallocProfileSvc::m_nStopAtEvent
private

Definition at line 48 of file JemallocProfileSvc.h.

bool JemallocProfileSvc::m_profiling
private

Status of the profiling.

Definition at line 58 of file JemallocProfileSvc.h.

std::vector<std::string> JemallocProfileSvc::m_startFromIncidents
private

Definition at line 51 of file JemallocProfileSvc.h.

std::vector<std::string> JemallocProfileSvc::m_stopAtIncidents
private

Definition at line 52 of file JemallocProfileSvc.h.


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