Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
JemallocProfile.cpp
Go to the documentation of this file.
1 // Include files
2 
3 // local
4 #include "JemallocProfile.h"
5 
6 // including jemmalloc.h is difficult as the malloc signature is not exactly identical
7 // to the system one (issue with throw).
8 // We therefore declare mallctl here.
9 
10 extern "C" {
11 int mallctl( const char* name, void* oldp, size_t* oldlenp, void* newp, size_t newlen );
12 }
13 
14 //-----------------------------------------------------------------------------
15 // Implementation file for class : JemallocProfile
16 //
17 // 2015-06-09 : Ben Couturier
18 //-----------------------------------------------------------------------------
19 
20 // Declaration of the Algorithm Factory
22 
23 //=============================================================================
24 // Initialization
25 //=============================================================================
26 StatusCode JemallocProfile::initialize() {
27  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
28  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
29 
30  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
31  bool active = true;
32  int res = mallctl( "prof.active", NULL, NULL, &active, sizeof( active ) );
33  if ( res != 0 ) { return StatusCode::FAILURE; }
34  return StatusCode::SUCCESS;
35 }
36 
37 //=============================================================================
38 // Main execution
39 //=============================================================================
41 
42  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
43 
44  // Increase event number
45  m_eventNumber += 1;
46 
48  m_profiling = true;
49  info() << "Starting Jemalloc profile at event " << m_eventNumber << endmsg;
50  }
51 
52  if ( m_profiling && ( ( m_eventNumber - m_nStartFromEvent ) % m_dumpPeriod == 0 ) ) {
53  info() << "Jemalloc Dumping heap at event " << m_eventNumber << endmsg;
54  mallctl( "prof.dump", NULL, NULL, NULL, 0 );
55  }
56 
57  if ( m_eventNumber == m_nStopAtEvent ) {
58  m_profiling = false;
59  info() << "Stopping Jemalloc profile at event " << m_eventNumber << endmsg;
60  mallctl( "prof.dump", NULL, NULL, NULL, 0 );
61  }
62  return StatusCode::SUCCESS;
63 }
64 
65 //=============================================================================
66 // Finalize
67 //=============================================================================
69 
70  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
71  return GaudiAlgorithm::finalize(); // must be called after all other actions
72 }
73 
74 //=============================================================================
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode initialize() override
standard initialization method
Gaudi::Property< int > m_nStopAtEvent
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool isFailure() const
Definition: StatusCode.h:130
#define DECLARE_COMPONENT(type)
Gaudi::Property< int > m_dumpPeriod
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode finalize() override
standard finalization method
StatusCode finalize() override
Algorithm finalization.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::Property< int > m_nStartFromEvent
StatusCode execute() override
Algorithm execution.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Algorithm to enable/disable the profiling of the head by Jemalloc.
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)