The Gaudi Framework  v33r0 (d5ea422b)
CallgrindProfile.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // Include files
12 #include <iostream>
13 
14 // local
15 #include "CallgrindProfile.h"
16 #include "local_callgrind.h"
17 
18 //-----------------------------------------------------------------------------
19 // Implementation file for class : CallgrindProfile
20 //
21 // 2014-08-22 : Ben Couturier
22 //-----------------------------------------------------------------------------
23 
24 // Declaration of the Algorithm Factory
26 
27 //=============================================================================
28 // Main execution
29 //=============================================================================
31 
32  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
33 
34  // Increase event number
35  ++m_eventNumber;
36 
37  if ( m_eventNumber == m_nStartFromEvent ) {
38  m_profiling = true;
39  warning() << "Starting Callgrind profile at event " << m_eventNumber << endmsg;
41  }
42 
43  if ( m_eventNumber == m_nZeroAtEvent ) {
44  warning() << "Setting Callgrind counters to zero at event " << m_eventNumber << endmsg;
46  }
47 
48  if ( m_eventNumber == m_nStopAtEvent ) {
49  m_profiling = false;
50  warning() << "Stopping Callgrind profile at event " << m_eventNumber << endmsg;
52  }
53 
54  if ( m_eventNumber == m_nDumpAtEvent ) {
55  warning() << "Dumping Callgrind counters to zero at event " << m_eventNumber << endmsg;
56 
57  if ( m_dumpName == "" ) {
59  } else {
60  CALLGRIND_DUMP_STATS_AT( m_dumpName.value().c_str() );
61  }
62  m_dumpDone = true;
63  }
64 
65  return StatusCode::SUCCESS;
66 }
67 
68 //=============================================================================
69 // Finalize
70 //=============================================================================
72 
73  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
74 
75  if ( !m_dumpDone ) {
76  if ( m_dumpName == "" ) {
78  } else {
79  CALLGRIND_DUMP_STATS_AT( m_dumpName.value().c_str() );
80  }
81  }
82 
83  return Algorithm::finalize(); // must be called after all other actions
84 }
85 
86 //=============================================================================
#define CALLGRIND_START_INSTRUMENTATION
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
Gaudi::Property< std::string > m_dumpName
#define CALLGRIND_ZERO_STATS
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:182
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define CALLGRIND_DUMP_STATS
#define CALLGRIND_DUMP_STATS_AT(pos_str)
StatusCode finalize() override
Algorithm finalization.
Algorithm to enable/disable the profiling by Callgrind at given events.
#define CALLGRIND_STOP_INSTRUMENTATION
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202