All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IntelProfilerAuditor Class Reference
Inheritance diagram for IntelProfilerAuditor:
Collaboration diagram for IntelProfilerAuditor:

Classes

struct  stack_entity
 

Public Member Functions

 IntelProfilerAuditor (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
void handle (const Incident &incident)
 Inform that a new incident has occurred.
 
void before (StandardEventType type, INamedInterface *i)
 The following methods are meant to be implemented by the child class...
 
void after (StandardEventType type, INamedInterface *i, const StatusCode &sc)
 
- Public Member Functions inherited from Auditor
 Auditor (const std::string &name, ISvcLocator *svcloc)
 Constructor.
 
virtual ~Auditor ()
 Destructor.
 
StatusCode sysInitialize ()
 Initialization method invoked by the framework.
 
StatusCode sysFinalize ()
 Finalization method invoked by the framework.
 
virtual void before (StandardEventType, const std::string &)
 
virtual void before (CustomEventTypeRef, INamedInterface *)
 
virtual void before (CustomEventTypeRef, const std::string &)
 
virtual void after (StandardEventType, const std::string &, const StatusCode &)
 
virtual void after (CustomEventTypeRef, INamedInterface *, const StatusCode &)
 
virtual void after (CustomEventTypeRef, const std::string &, const StatusCode &)
 
virtual void beforeInitialize (INamedInterface *)
 
virtual void afterInitialize (INamedInterface *)
 
virtual void beforeReinitialize (INamedInterface *)
 
virtual void afterReinitialize (INamedInterface *)
 
virtual void beforeExecute (INamedInterface *)
 
virtual void afterExecute (INamedInterface *, const StatusCode &)
 
virtual void beforeFinalize (INamedInterface *)
 
virtual void afterFinalize (INamedInterface *)
 
virtual void beforeBeginRun (INamedInterface *)
 
virtual void afterBeginRun (INamedInterface *)
 
virtual void beforeEndRun (INamedInterface *)
 
virtual void afterEndRun (INamedInterface *)
 
virtual StatusCode finalize ()
 
virtual const std::string & name () const
 
virtual bool isEnabled () const
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
int outputLevel () const
 Retrieve the output level of current auditor.
 
void setOutputLevel (int level)
 Set the output level for current auditor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 The standard service locator.
 
template<class T >
StatusCode service (const std::string &name, T *&svc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist.
 
virtual StatusCode setProperty (const Property &p)
 Set a value of a property of an auditor.
 
virtual StatusCode setProperty (const std::string &s)
 Implementation of IProperty::setProperty.
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Implementation of IProperty::setProperty.
 
virtual StatusCode getProperty (Property *p) const
 Get the value of a property.
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name.
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Implementation of IProperty::getProperty.
 
const std::vector< Property * > & getProperties () const
 Get all properties.
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setProperties ()
 Set the auditor's properties.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
 Auditor (const std::string &name, ISvcLocator *svcloc)
 Constructor.
 
virtual ~Auditor ()
 Destructor.
 
StatusCode sysInitialize ()
 Initialization method invoked by the framework.
 
StatusCode sysFinalize ()
 Finalization method invoked by the framework.
 
virtual void before (StandardEventType, const std::string &)
 
virtual void before (CustomEventTypeRef, INamedInterface *)
 
virtual void before (CustomEventTypeRef, const std::string &)
 
virtual void after (StandardEventType, const std::string &, const StatusCode &)
 
virtual void after (CustomEventTypeRef, INamedInterface *, const StatusCode &)
 
virtual void after (CustomEventTypeRef, const std::string &, const StatusCode &)
 
virtual void beforeInitialize (INamedInterface *)
 
virtual void afterInitialize (INamedInterface *)
 
virtual void beforeReinitialize (INamedInterface *)
 
virtual void afterReinitialize (INamedInterface *)
 
virtual void beforeExecute (INamedInterface *)
 
virtual void afterExecute (INamedInterface *, const StatusCode &)
 
virtual void beforeFinalize (INamedInterface *)
 
virtual void afterFinalize (INamedInterface *)
 
virtual void beforeBeginRun (INamedInterface *)
 
virtual void afterBeginRun (INamedInterface *)
 
virtual void beforeEndRun (INamedInterface *)
 
virtual void afterEndRun (INamedInterface *)
 
virtual StatusCode finalize ()
 
virtual const std::string & name () const
 
virtual bool isEnabled () const
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
int outputLevel () const
 Retrieve the output level of current auditor.
 
void setOutputLevel (int level)
 Set the output level for current auditor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 The standard service locator.
 
template<class T >
StatusCode service (const std::string &name, T *&svc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist.
 
virtual StatusCode setProperty (const Property &p)
 Set a value of a property of an auditor.
 
virtual StatusCode setProperty (const std::string &s)
 Implementation of IProperty::setProperty.
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Implementation of IProperty::setProperty.
 
virtual StatusCode getProperty (Property *p) const
 Get the value of a property.
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name.
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Implementation of IProperty::getProperty.
 
const std::vector< Property * > & getProperties () const
 Get all properties.
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setProperties ()
 Set the auditor's properties.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
- Public Member Functions inherited from IIncidentListener
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID.
 
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID.
 
- Public Member Functions inherited from IInterface
virtual void * i_cast (const InterfaceID &) const =0
 main cast function
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces.
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance.
 
virtual unsigned long release ()=0
 Release Interface instance.
 
virtual unsigned long refCount () const =0
 Current reference count.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance.
 
virtual ~IInterface ()
 Virtual destructor.
 
virtual void * i_cast (const InterfaceID &) const =0
 main cast function
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces.
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance.
 
virtual unsigned long release ()=0
 Release Interface instance.
 
virtual unsigned long refCount () const =0
 Current reference count.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance.
 
virtual ~IInterface ()
 Virtual destructor.
 

Private Member Functions

void start_profiling_component (const std::string &name)
 
void skip_profiling_component (const std::string &name)
 
void start ()
 
void pause ()
 
void resume ()
 
void stop ()
 
bool hasIncludes () const
 
bool isIncluded (const std::string &name) const
 
bool isExcluded (const std::string &name) const
 
bool isRunning () const
 
int stackLevel () const
 
std::string stackIndent (bool newLevel=false) const
 
std::string taskTypeName (const std::string &component_name) const
 

Private Attributes

int m_nStartFromEvent
 
int m_nStopAtEvent
 
std::vector< std::string > m_excluded
 
std::vector< std::string > m_included
 
std::vector< std::string > m_algs_for_tasktypes
 
std::string m_alg_delim
 
bool m_enable_frames
 
int m_frames_rate
 
MsgStream m_log
 
int m_nEvents
 
__itt_domain * domain
 
bool m_isStarted
 
std::vector< stack_entitym_stack
 
TaskTypes m_tasktypes
 

Additional Inherited Members

- Public Types inherited from Auditor
typedef
Gaudi::PluginService::Factory
< IAuditor *, const
std::string &, ISvcLocator * > 
Factory
 
typedef
Gaudi::PluginService::Factory
< IAuditor *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from IInterface
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID.
 
typedef mpl::set1< iidext_iids
 Extra interfaces.
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID.
 
typedef mpl::set1< iidext_iids
 Extra interfaces.
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface.
 
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface.
 

Detailed Description

Definition at line 34 of file IntelProfilerAuditor.cpp.

Constructor & Destructor Documentation

IntelProfilerAuditor::IntelProfilerAuditor ( const std::string &  name,
ISvcLocator pSvcLocator 
)

Definition at line 122 of file IntelProfilerAuditor.cpp.

: Auditor(name, pSvcLocator), m_log(msgSvc(), name)
,m_nEvents(0), m_isStarted(false) {
// ## Properties
declareProperty("IncludeAlgorithms", m_included,
"Names of included algorithms."
);
declareProperty("ExcludeAlgorithms", m_excluded,
"Names of excluded algorithms."
);
declareProperty("StartFromEventN", m_nStartFromEvent = 1,
"After what event we stop profiling. "
"If 0 than we also profile finalization stage."
);
declareProperty("StopAtEventN", m_nStopAtEvent = 0,
"After what event we stop profiling. "
"If 0 than we also profile finalization stage. Default = 0."
);
declareProperty("ComponentsForTaskTypes", m_algs_for_tasktypes,
"Algorithm name, for which intel amplifier task type will be created."
"By default all algorithms have a corresponding task type.");
declareProperty("TaskTypeNameDelimeter", m_alg_delim = " ",
"The String delimiter between sequences/algorithms names in "
"\"Task Type\" grouping at Amplifier. Default=\" \"."
);
declareProperty("EnableFrames", m_enable_frames = false,
"Enable frames (needed for detecting slow events). Default=false."
);
declareProperty("FramesRate", m_frames_rate = 100,
"Frames rate. The recommended maximum rate for calling the Frame API is "
"1000 frames (events) per second. A higher rate may result in large product"
" memory consumption and slow finalization. "
"You need update \"slow-frames-threshold\" and \"fast-frames-threshold\" "
"parameters of amplxe-cl tool to separate slow, medium and fast events. "
"For use frames you need to switch on \"EnableFrames\". "
"Default=100"
);
}

Member Function Documentation

void IntelProfilerAuditor::after ( StandardEventType  type,
INamedInterface i,
const StatusCode sc 
)
virtual

Reimplemented from Auditor.

Definition at line 397 of file IntelProfilerAuditor.cpp.

{
// Skip unnecessary event types
if (!((type == IAuditor::Execute) && m_isStarted)) return;
if ((m_nEvents+1) % m_frames_rate == 0) {
__itt_frame_end_v3(domain, NULL);
}
// Name of the current component
const std::string& name = i->name();
stack_entity state = m_stack.back();
// Remove component from stack.
m_stack.pop_back();
if (state.event != 0) {
m_log << MSG::DEBUG << stackIndent(true) << "End event for "
<< name << endmsg;
__itt_event_end(state.event);
if (state.parent_event != 0) {
m_log << MSG::DEBUG << stackIndent() << "Resume event for "
<< state.parent_event << endmsg;
__itt_event_start(state.parent_event);
}
}
if (m_stack.empty()) {
// Pause if there are no parent components (top algorithm).
pause();
} else if (state.status) {
// If the profiling is running and we have parent component that is
// paused then pause the profiling.
if (!m_stack.back().status) {
pause();
}
}else {
// If the profiling was stopped, but the parent component should be profiled
// then resume profiling.
if (m_stack.back().status) {
resume();
}
}
}
void IntelProfilerAuditor::before ( StandardEventType  evt,
INamedInterface obj 
)
virtual

The following methods are meant to be implemented by the child class...

Reimplemented from Auditor.

Definition at line 350 of file IntelProfilerAuditor.cpp.

{
// Skip unnecessary event types.
if (!((type == IAuditor::Execute) && m_isStarted)) return;
// Name of the current component.
const std::string& name = i->name();
//m_log << MSG::DEBUG << "Before: " << name << " " << type << endmsg;
if (isRunning()) {
if (isExcluded(name)) {
// If profiling is running and component is explicitly excluded
// then skip component.
}else{
// If profiling is running and component is'not explicitly excluded
// then start profiling for component (add to stack).
}
}else {
if (hasIncludes()) {
// If the profiling is not running and "includes" is explicitly defined ...
if (isIncluded(name)) {
// and the current component is in the include's list then start the
// component profiling.
} else{
// and the current component is not in the includes list then skip
// a profiling of the component.
}
}else {
// If "Includes" property isn't present and the component is ...
if (isExcluded(name)) {
// in the excludes list then skip a profiling
}else{
// not in the exclude list then start a profiling
}
}
}
if (m_nEvents % m_frames_rate == 0) {
__itt_frame_begin_v3(domain, NULL);
}
}
void IntelProfilerAuditor::handle ( const Incident )
virtual

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 332 of file IntelProfilerAuditor.cpp.

{
if (IncidentType::BeginEvent != incident.type()) return;
// Increment the event counter
m_log << MSG::INFO << "Start profiling (event #" << m_nEvents << ")"
<< endmsg;
start();
}
m_log << MSG::INFO << "Stop profiling (event #" << m_nEvents << ")"
<< endmsg;
stop();
}
}
bool IntelProfilerAuditor::hasIncludes ( ) const
private

Definition at line 237 of file IntelProfilerAuditor.cpp.

{
return !m_included.empty();
}
StatusCode IntelProfilerAuditor::initialize ( )
virtual

Reimplemented from Auditor.

Definition at line 277 of file IntelProfilerAuditor.cpp.

{
m_log << MSG::INFO << "Initialised" << endmsg;
IIncidentSvc * inSvc = NULL;
const StatusCode sc = serviceLocator()->service("IncidentSvc", inSvc);
if (sc.isFailure())
return sc;
// Useful to start profiling only after some event, we don't need profile
// initialization stage. For that we need to count events with BeginEvent
// listener.
// If the end event number don't setup we finish profiling at the end
// of loop. We don't need profiling finalization stage.
std::string str_excluded, str_included, str_eventtypes;
BOOST_FOREACH(const std::string& name, m_excluded)
{
str_excluded += " " + name;
}
BOOST_FOREACH(const std::string& name, m_included)
{
str_included += " " + name;
}
BOOST_FOREACH(const std::string& name, m_algs_for_tasktypes)
{
str_eventtypes += " " + name;
}
if (!m_included.empty()) {
m_log << MSG::INFO << "Included algorithms (" << m_included.size()
<< "): " << str_included << endmsg;
}
if (!m_excluded.empty()){
m_log << MSG::INFO << "Excluded algorithms (" << m_excluded.size()
<< "): " << str_excluded << endmsg;
}
if (!m_algs_for_tasktypes.empty()){
m_log << MSG::INFO << "Event types (" << m_algs_for_tasktypes.size()
<< "): " << str_eventtypes << endmsg;
}
// Create a profiler domain for detection of slow events.
domain = __itt_domain_create("Event loop");
}
bool IntelProfilerAuditor::isExcluded ( const std::string &  name) const
private

Definition at line 246 of file IntelProfilerAuditor.cpp.

{
return std::find(m_excluded.begin(), m_excluded.end(), name) !=
m_excluded.end();
}
bool IntelProfilerAuditor::isIncluded ( const std::string &  name) const
private

Definition at line 241 of file IntelProfilerAuditor.cpp.

{
return std::find(m_included.begin(), m_included.end(), name) !=
m_included.end();
}
bool IntelProfilerAuditor::isRunning ( ) const
private

Definition at line 251 of file IntelProfilerAuditor.cpp.

{
return !m_stack.empty() && m_stack.back().status;
}
void IntelProfilerAuditor::pause ( )
private

Definition at line 218 of file IntelProfilerAuditor.cpp.

{
if (!m_isStarted) return;
m_log << MSG::DEBUG << stackIndent() << "Pause" << endmsg;
__itt_pause();
}
void IntelProfilerAuditor::resume ( )
private

Definition at line 212 of file IntelProfilerAuditor.cpp.

{
if (!m_isStarted) return;
m_log << MSG::DEBUG << stackIndent() << "Resume" << endmsg;
__itt_resume();
}
void IntelProfilerAuditor::skip_profiling_component ( const std::string &  name)
private

Definition at line 224 of file IntelProfilerAuditor.cpp.

{
if (!m_isStarted) return;
m_stack.push_back(stack_entity(name, false));
m_log << MSG::DEBUG << stackIndent() << "Skip component "
<< name << endmsg;
}
std::string IntelProfilerAuditor::stackIndent ( bool  newLevel = false) const
private

Definition at line 259 of file IntelProfilerAuditor.cpp.

{
std::stringstream indent(std::stringstream::out);
indent << std::setw(stackLevel()*2+(newLevel?2:0)) << " ";
return indent.str();
}
int IntelProfilerAuditor::stackLevel ( ) const
private

Definition at line 255 of file IntelProfilerAuditor.cpp.

{
return m_stack.size();
}
void IntelProfilerAuditor::start ( )
private

Definition at line 161 of file IntelProfilerAuditor.cpp.

{
m_isStarted = true;
__itt_resume();
}
void IntelProfilerAuditor::start_profiling_component ( const std::string &  name)
private

Definition at line 166 of file IntelProfilerAuditor.cpp.

{
if (!m_isStarted) return;
std::string typeName = taskTypeName(name);
__itt_event taskId = 0;
TaskTypes::const_iterator iter = m_tasktypes.find(typeName);
if( iter != m_tasktypes.end()) {
taskId = iter->second;
}
if(!taskId && m_algs_for_tasktypes.empty()) {
// Create event
taskId = __itt_event_create(typeName.c_str(), typeName.size());
m_tasktypes.insert(TaskTypes::value_type(typeName, taskId));
}
stack_entity state = stack_entity(name, true, taskId);
stack_entity* parent = !m_stack.empty()?&m_stack.back():NULL;
if (parent != NULL) {
if (parent->event) {
state.parent_event = parent->event;
} else {
state.parent_event = parent->parent_event;
}
}
if (taskId && state.parent_event) {
m_log << MSG::DEBUG << stackIndent() << "Pause event " <<
state.parent_event << endmsg;
__itt_event_end(state.parent_event);
}
m_stack.push_back(state);
m_log << MSG::DEBUG << stackIndent() << "Start profiling component "
<< typeName << endmsg;
if (taskId) {
// Start event
m_log << MSG::DEBUG << stackIndent() << "Start event type "
<< state.event << " for " << typeName << endmsg;
__itt_event_start(state.event);
}
__itt_resume();
}
void IntelProfilerAuditor::stop ( )
private

Definition at line 231 of file IntelProfilerAuditor.cpp.

{
if (!m_isStarted) return;
m_isStarted = false;
__itt_pause();
}
std::string IntelProfilerAuditor::taskTypeName ( const std::string &  component_name) const
private

Definition at line 266 of file IntelProfilerAuditor.cpp.

{
std::string result;
std::string delim = "";
BOOST_FOREACH(const stack_entity& value,
result += delim+value.name;
delim = m_alg_delim;
}
return result+m_alg_delim+component_name;
}

Member Data Documentation

__itt_domain* IntelProfilerAuditor::domain
private

Definition at line 94 of file IntelProfilerAuditor.cpp.

std::string IntelProfilerAuditor::m_alg_delim
private

Definition at line 79 of file IntelProfilerAuditor.cpp.

std::vector<std::string> IntelProfilerAuditor::m_algs_for_tasktypes
private

Definition at line 76 of file IntelProfilerAuditor.cpp.

bool IntelProfilerAuditor::m_enable_frames
private

Definition at line 81 of file IntelProfilerAuditor.cpp.

std::vector<std::string> IntelProfilerAuditor::m_excluded
private

Definition at line 72 of file IntelProfilerAuditor.cpp.

int IntelProfilerAuditor::m_frames_rate
private

Definition at line 87 of file IntelProfilerAuditor.cpp.

std::vector<std::string> IntelProfilerAuditor::m_included
private

Definition at line 74 of file IntelProfilerAuditor.cpp.

bool IntelProfilerAuditor::m_isStarted
private

Definition at line 96 of file IntelProfilerAuditor.cpp.

MsgStream IntelProfilerAuditor::m_log
private

Definition at line 90 of file IntelProfilerAuditor.cpp.

int IntelProfilerAuditor::m_nEvents
private

Definition at line 92 of file IntelProfilerAuditor.cpp.

int IntelProfilerAuditor::m_nStartFromEvent
private

Definition at line 67 of file IntelProfilerAuditor.cpp.

int IntelProfilerAuditor::m_nStopAtEvent
private

Definition at line 70 of file IntelProfilerAuditor.cpp.

std::vector<stack_entity> IntelProfilerAuditor::m_stack
private

Definition at line 98 of file IntelProfilerAuditor.cpp.

TaskTypes IntelProfilerAuditor::m_tasktypes
private

Definition at line 100 of file IntelProfilerAuditor.cpp.


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