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 {
12  int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
13 }
14 
15 //-----------------------------------------------------------------------------
16 // Implementation file for class : JemallocProfile
17 //
18 // 2015-06-09 : Ben Couturier
19 //-----------------------------------------------------------------------------
20 
21 // Declaration of the Algorithm Factory
23 
24 //=============================================================================
25 // Initialization
26 //=============================================================================
27 StatusCode JemallocProfile::initialize() {
28  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
29  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
30 
31  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
32  bool active = true;
33  int res = mallctl("prof.active", NULL, NULL, &active, sizeof(active));
34  if (res != 0)
35  {
36  return StatusCode::FAILURE;
37  }
38  return StatusCode::SUCCESS;
39 }
40 
41 //=============================================================================
42 // Main execution
43 //=============================================================================
45 
46  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
47 
48  // Increase event number
49  m_eventNumber += 1;
50 
52  {
53  m_profiling = true;
54  info() << "Starting Jemalloc profile at event "
55  << m_eventNumber << endmsg;
56  }
57 
59  {
60  info() << "Jemalloc Dumping heap at event "
61  << m_eventNumber << endmsg;
62  mallctl("prof.dump", NULL, NULL, NULL, 0);
63  }
64 
66  {
67  m_profiling = false;
68  info() << "Stopping Jemalloc profile at event "
69  << m_eventNumber << endmsg;
70  mallctl("prof.dump", NULL, NULL, NULL, 0);
71  }
72  return StatusCode::SUCCESS;
73 }
74 
75 //=============================================================================
76 // Finalize
77 //=============================================================================
79 
80  if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
81  return GaudiAlgorithm::finalize(); // must be called after all other actions
82 }
83 
84 //=============================================================================
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode initialize() override
standard initialization method
Gaudi::Property< int > m_nStopAtEvent
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
Gaudi::Property< int > m_dumpPeriod
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode finalize() override
standard finalization method
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:620
StatusCode finalize() override
Algorithm finalization.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< int > m_nStartFromEvent
StatusCode execute() override
Algorithm execution.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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)