| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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_ALGORITHM_FACTORY( JemallocProfile )
22
23 //=============================================================================
24 // Initialization
25 //=============================================================================
26 StatusCode JemallocProfile::initialize()
27 {
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 return StatusCode::FAILURE;
36 }
37 return StatusCode::SUCCESS;
38 }
39
40 //=============================================================================
41 // Main execution
42 //=============================================================================
43 StatusCode JemallocProfile::execute()
44 {
45
46 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
47
48 // Increase event number
49 m_eventNumber += 1;
50
51 if ( m_eventNumber == m_nStartFromEvent ) {
52 m_profiling = true;
53 info() << "Starting Jemalloc profile at event " << m_eventNumber << endmsg;
54 }
55
56 if ( m_profiling && ( ( m_eventNumber - m_nStartFromEvent ) % m_dumpPeriod == 0 ) ) {
57 info() << "Jemalloc Dumping heap at event " << m_eventNumber << endmsg;
58 mallctl( "prof.dump", NULL, NULL, NULL, 0 );
59 }
60
61 if ( m_eventNumber == m_nStopAtEvent ) {
62 m_profiling = false;
63 info() << "Stopping Jemalloc profile at event " << m_eventNumber << endmsg;
64 mallctl( "prof.dump", NULL, NULL, NULL, 0 );
65 }
66 return StatusCode::SUCCESS;
67 }
68
69 //=============================================================================
70 // Finalize
71 //=============================================================================
72 StatusCode JemallocProfile::finalize()
73 {
74
75 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
76 return GaudiAlgorithm::finalize(); // must be called after all other actions
77 }
78
79 //=============================================================================
StatusCode::SUCCESS
Definition: StatusCode.h:29
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:112
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:43
MSG::DEBUG
Definition: IMessageSvc.h:16
JemallocProfile::m_nStopAtEvent
Gaudi::Property< int > m_nStopAtEvent
Definition: JemallocProfile.h:34
JemallocProfile::m_eventNumber
int m_eventNumber
Definition: JemallocProfile.h:40
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:61
JemallocProfile::m_dumpPeriod
Gaudi::Property< int > m_dumpPeriod
Definition: JemallocProfile.h:37
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:59
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:631
JemallocProfile::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: JemallocProfile.cpp:72
JemallocProfile::m_profiling
bool m_profiling
Definition: JemallocProfile.h:39
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
JemallocProfile::m_nStartFromEvent
Gaudi::Property< int > m_nStartFromEvent
Definition: JemallocProfile.h:33
StatusCode::FAILURE
Definition: StatusCode.h:29
JemallocProfile::execute
StatusCode execute() override
Algorithm execution.
Definition: JemallocProfile.cpp:43
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:124
JemallocProfile.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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)