| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 {
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
22 DECLARE_ALGORITHM_FACTORY( JemallocProfile )
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 //=============================================================================
44 StatusCode JemallocProfile::execute() {
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 {
53 m_profiling = true;
54 info() << "Starting Jemalloc profile at event "
55 << m_eventNumber << endmsg;
56 }
57
58 if (m_profiling && ((m_eventNumber - m_nStartFromEvent) % m_dumpPeriod == 0))
59 {
60 info() << "Jemalloc Dumping heap at event "
61 << m_eventNumber << endmsg;
62 mallctl("prof.dump", NULL, NULL, NULL, 0);
63 }
64
65 if (m_eventNumber == m_nStopAtEvent)
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 //=============================================================================
78 StatusCode JemallocProfile::finalize() {
79
80 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
81 return GaudiAlgorithm::finalize(); // must be called after all other actions
82 }
83
84 //=============================================================================
StatusCode::SUCCESS
Definition: StatusCode.h:30
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:44
MSG::DEBUG
Definition: IMessageSvc.h:18
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:84
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:58
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:620
JemallocProfile::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: JemallocProfile.cpp:78
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:126
JemallocProfile::m_nStartFromEvent
Gaudi::Property< int > m_nStartFromEvent
Definition: JemallocProfile.h:33
JemallocProfile::execute
StatusCode execute() override
Algorithm execution.
Definition: JemallocProfile.cpp:44
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
JemallocProfile.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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)