| The Gaudi Framework v27r1

- 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 //=============================================================================
26 // Standard constructor, initializes variables
27 //=============================================================================
28 JemallocProfile::JemallocProfile( const std::string& name,
29 ISvcLocator* pSvcLocator)
30 : GaudiAlgorithm ( name , pSvcLocator ), m_profiling(false), m_eventNumber (0)
31 {
32
33 declareProperty("StartFromEventN", m_nStartFromEvent = 1,
34 "After what event we start profiling. "
35 );
36
37 declareProperty("StopAtEventN", m_nStopAtEvent = 0,
38 "After what event we stop profiling. "
39 "If 0 than we also profile finalization stage. Default = 0."
40 );
41
42 declareProperty("DumpPeriod", m_dumpPeriod = 100,
43 "Period for dumping head to a file. Default=100"
44 );
45
46 }
47 //=============================================================================
48 // Destructor
49 //=============================================================================
50 JemallocProfile::~JemallocProfile() {}
51
52 //=============================================================================
53 // Initialization
54 //=============================================================================
55 StatusCode JemallocProfile::initialize() {
56 StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
57 if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
58
59 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Initialize" << endmsg;
60 bool active = true;
61 int res = mallctl("prof.active", NULL, NULL, &active, sizeof(active));
62 if (res != 0)
63 {
64 return StatusCode::FAILURE;
65 }
66 return StatusCode::SUCCESS;
67 }
68
69 //=============================================================================
70 // Main execution
71 //=============================================================================
72 StatusCode JemallocProfile::execute() {
73
74 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
75
76 // Increase event number
77 m_eventNumber += 1;
78
79 if (m_eventNumber == m_nStartFromEvent)
80 {
81 m_profiling = true;
82 info() << "Starting Jemalloc profile at event "
83 << m_eventNumber << endmsg;
84 }
85
86 if (m_profiling && ((m_eventNumber - m_nStartFromEvent) % m_dumpPeriod == 0))
87 {
88 info() << "Jemalloc Dumping heap at event "
89 << m_eventNumber << endmsg;
90 mallctl("prof.dump", NULL, NULL, NULL, 0);
91 }
92
93 if (m_eventNumber == m_nStopAtEvent)
94 {
95 m_profiling = false;
96 info() << "Stopping Jemalloc profile at event "
97 << m_eventNumber << endmsg;
98 mallctl("prof.dump", NULL, NULL, NULL, 0);
99 }
100 return StatusCode::SUCCESS;
101 }
102
103 //=============================================================================
104 // Finalize
105 //=============================================================================
106 StatusCode JemallocProfile::finalize() {
107
108 if ( msgLevel(MSG::DEBUG) ) debug() << "==> Finalize" << endmsg;
109 return GaudiAlgorithm::finalize(); // must be called after all other actions
110 }
111
112 //=============================================================================
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
JemallocProfile::finalize
virtual StatusCode finalize()
Algorithm finalization.
Definition: JemallocProfile.cpp:106
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
JemallocProfile::m_dumpPeriod
int m_dumpPeriod
Definition: JemallocProfile.h:37
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:48
MSG::DEBUG
Definition: IMessageSvc.h:18
std
STL namespace.
JemallocProfile::m_nStopAtEvent
int m_nStopAtEvent
Definition: JemallocProfile.h:35
merge_files.sc
int sc
Definition: merge_files.py:167
JemallocProfile::m_eventNumber
int m_eventNumber
Definition: JemallocProfile.h:38
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
JemallocProfile::execute
virtual StatusCode execute()
Algorithm execution.
Definition: JemallocProfile.cpp:72
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:62
DECLARE_ALGORITHM_FACTORY
#define DECLARE_ALGORITHM_FACTORY(x)
Definition: Algorithm.h:777
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:93
JemallocProfile::m_nStartFromEvent
int m_nStartFromEvent
Definition: JemallocProfile.h:34
JemallocProfile::initialize
virtual StatusCode initialize()
Algorithm initialization.
Definition: JemallocProfile.cpp:55
JemallocProfile::m_profiling
bool m_profiling
Definition: JemallocProfile.h:36
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
JemallocProfile.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
JemallocProfile::~JemallocProfile
virtual ~JemallocProfile()
Destructor.
Definition: JemallocProfile.cpp:50
JemallocProfile
Algorithm to enable/disable the profiling of the head by Jemalloc.
Definition: JemallocProfile.h:20
mallctl
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)