ATLAS Offline Software
CallGraphBuilderSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // CallGraphBuilderSvc.cxx
8 // Implementation file for class CallGraphBuilderSvc
9 // Author: S.Binet<binet@cern.ch>
11 
12 
13 // STL includes
14 
15 // FrameWork includes
16 #include "Gaudi/Property.h"
17 
18 // PerfMonComps includes
19 #include "CallGraphBuilderSvc.h"
20 
21 namespace {
23  static const std::string s_rootName = "<root-node>";
24  static const NodeId_t s_rootId = 0;
25 }
26 
27 namespace PerfMon {
28 
29 // initialize the static "unique identifier"
30 // FIXME: what happens when we wrap around ??
31 NodeId_t CallGraphBuilderSvc::m_uuid = 0;
32 
34 // Public methods:
36 
37 // Constructors
40  ISvcLocator* pSvcLocator ) :
41  AthService( name, pSvcLocator )
42 {
43  //
44  // Property declaration
45  //
46  //declareProperty( "Property", m_nProperty, "descr" );
47 
48  // install the root of the nodes for our callgraph modelisation
49  // (would be so simple with a boost::bimap ... (boost 1.35 ?)
50  m_nameToId[s_rootName] = s_rootId;
51  m_idToName[s_rootId ] = s_rootName;
52 }
53 
54 // Destructor
57 {
58  msg() << MSG::DEBUG << "Calling destructor" << endmsg;
59 }
60 
61 // Athena Algorithm's Hooks
64 {
65  // initialize MsgStream
66  msg().setLevel( m_outputLevel.value() );
67 
68  msg() << MSG::INFO
69  << "Initializing " << name() << "..."
70  << endmsg;
71 
72  msg() << MSG::DEBUG << "Initializing base class..." << endmsg;
73  if ( AthService::initialize().isFailure() ) {
74  msg() << MSG::ERROR
75  << "Could not initialize base class !!"
76  << endmsg;
77  return StatusCode::FAILURE;
78  } else {
79  msg() << MSG::VERBOSE << "Base class initialized" << endmsg;
80  }
81 
82  return StatusCode::SUCCESS;
83 }
84 
86 {
87  msg() << MSG::INFO
88  << "Finalizing " << name() << "..."
89  << endmsg;
90 
91  return StatusCode::SUCCESS;
92 }
93 
94 // Query the interfaces.
95 // Input: riid, Requested interface ID
96 // ppvInterface, Pointer to requested interface
97 // Return: StatusCode indicating SUCCESS or FAILURE.
98 // N.B. Don't forget to release the interface after use!!!
100 CallGraphBuilderSvc::queryInterface( const InterfaceID& riid,
101  void** ppvInterface )
102 {
103  if ( ICallGraphBuilderSvc::interfaceID().versionMatch(riid) ) {
104  *ppvInterface = dynamic_cast<ICallGraphBuilderSvc*>(this);
105  } else {
106  // Interface is not directly available : try out a base class
107  return AthService::queryInterface(riid, ppvInterface);
108  }
109  addRef();
110  return StatusCode::SUCCESS;
111 }
112 
114 // Non-const methods:
116 
117 void CallGraphBuilderSvc::openNode( const std::string& nodeName )
118 {
119  std::scoped_lock lock(m_mutex);
120 
121  if ( m_nameToId.find( nodeName ) == m_nameToId.end() ) {
122  m_nameToId[nodeName] = ++m_uuid;
123  m_idToName[m_uuid ] = nodeName;
124  }
125 
126  const NodeId_t nodeId = m_nameToId[nodeName];
127  const NodeId_t parentId = m_stack.empty() ? 0 : m_stack.top();
128  m_stack.push( nodeId );
129 
130  boost::add_edge( parentId, nodeId, m_graph );
131 
132  msg() << MSG::VERBOSE
133  << "--> [" << nodeName << "] = " << nodeId << "\t"
134  << "(parent = " << m_idToName[parentId] << ")"
135  << endmsg;
136  return;
137 }
138 
139 void CallGraphBuilderSvc::closeNode( const std::string& nodeName )
140 {
141  std::scoped_lock lock(m_mutex);
142 
143  const NodeId_t nodeId = m_nameToId[nodeName];
144  //boost::add_edge( nodeId, 1, m_graph);
145  msg() << MSG::VERBOSE
146  << "<-- [" << nodeName << "] = " << nodeId
147  << endmsg;
148 
149  if ( !m_stack.empty() ) {
150  m_stack.pop();
151  }
152  return;
153 }
154 
155 
156 } // end namespace PerfMon
157 
PerfMon::CallGraphBuilderSvc::m_mutex
std::recursive_mutex m_mutex
Mutex protecting the following members.
Definition: CallGraphBuilderSvc.h:97
CallGraphBuilderSvc.h
PerfMon::CallGraphBuilderSvc::initialize
StatusCode initialize()
Gaudi Service Implementation.
Definition: CallGraphBuilderSvc.cxx:63
PerfMon::CallGraphBuilderSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Definition: CallGraphBuilderSvc.cxx:100
initialize
void initialize()
Definition: run_EoverP.cxx:894
PerfMon
a simple malloc wrapper that keeps track of the amount of memory allocated on the heap.
Definition: CallGraphAuditor.cxx:24
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthService
Definition: AthService.h:32
PerfMon::CallGraphBuilderSvc::openNode
void openNode(const std::string &nodeName)
open a new node in the call graph tree
Definition: CallGraphBuilderSvc.cxx:117
PerfMon::CallGraphBuilderSvc::finalize
StatusCode finalize()
Definition: CallGraphBuilderSvc.cxx:85
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
PerfMon::CallGraphBuilderSvc::CallGraphBuilderSvc
CallGraphBuilderSvc()
Default constructor:
ICallGraphBuilderSvc::interfaceID
static const InterfaceID & interfaceID()
Definition: ICallGraphBuilderSvc.h:60
PerfMon::CallGraphBuilderSvc::NodeId_t
unsigned long NodeId_t
Definition: CallGraphBuilderSvc.h:52
xAOD::parentId
@ parentId
Definition: TrackingPrimitives.h:516
PerfMon::CallGraphBuilderSvc::closeNode
void closeNode(const std::string &nodeName)
close an existing node in the call graph tree
Definition: CallGraphBuilderSvc.cxx:139
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Service >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
PerfMon::CallGraphBuilderSvc::~CallGraphBuilderSvc
virtual ~CallGraphBuilderSvc()
Destructor:
Definition: CallGraphBuilderSvc.cxx:56
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
ICallGraphBuilderSvc
Definition: ICallGraphBuilderSvc.h:23