| The Gaudi Framework v32r1 (f65d50dc)

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
21 DECLARE_COMPONENT( JemallocProfile )
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 //=============================================================================
40 StatusCode JemallocProfile::execute() {
41
42 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
43
44 // Increase event number
45 m_eventNumber += 1;
46
47 if ( m_eventNumber == m_nStartFromEvent ) {
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 //=============================================================================
68 StatusCode JemallocProfile::finalize() {
69
70 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
71 return GaudiAlgorithm::finalize(); // must be called after all other actions
72 }
73
74 //=============================================================================
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:42
MSG::DEBUG
Definition: IMessageSvc.h:15
JemallocProfile::m_nStopAtEvent
Gaudi::Property< int > m_nStopAtEvent
Definition: JemallocProfile.h:30
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
JemallocProfile::m_eventNumber
int m_eventNumber
Definition: JemallocProfile.h:36
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
JemallocProfile::m_dumpPeriod
Gaudi::Property< int > m_dumpPeriod
Definition: JemallocProfile.h:33
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:55
JemallocProfile::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: JemallocProfile.cpp:68
JemallocProfile::m_profiling
bool m_profiling
Definition: JemallocProfile.h:35
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
JemallocProfile::m_nStartFromEvent
Gaudi::Property< int > m_nStartFromEvent
Definition: JemallocProfile.h:29
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
JemallocProfile::execute
StatusCode execute() override
Algorithm execution.
Definition: JemallocProfile.cpp:40
JemallocProfile.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
JemallocProfile
Algorithm to enable/disable the profiling of the head by Jemalloc.
Definition: JemallocProfile.h:19
mallctl
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)