Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r11 (bdb84f5f)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
JemallocProfile.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // Include files
12 
13 // local
14 #include "JemallocProfile.h"
15 
16 // including jemmalloc.h is difficult as the malloc signature is not exactly identical
17 // to the system one (issue with throw).
18 // We therefore declare mallctl here.
19 
20 extern "C" {
21 int mallctl( const char* name, void* oldp, size_t* oldlenp, void* newp, size_t newlen );
22 }
23 
24 //-----------------------------------------------------------------------------
25 // Implementation file for class : JemallocProfile
26 //
27 // 2015-06-09 : Ben Couturier
28 //-----------------------------------------------------------------------------
29 
30 // Declaration of the Algorithm Factory
32 
33 //=============================================================================
34 // Initialization
35 //=============================================================================
36 StatusCode JemallocProfile::initialize() {
37  StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
38  if ( sc.isFailure() ) return sc; // error printed already by GaudiAlgorithm
39 
40  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
41  bool active = true;
42  int res = mallctl( "prof.active", NULL, NULL, &active, sizeof( active ) );
43  if ( res != 0 ) { return StatusCode::FAILURE; }
44  return StatusCode::SUCCESS;
45 }
46 
47 //=============================================================================
48 // Main execution
49 //=============================================================================
51 
52  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
53 
54  // Increase event number
55  m_eventNumber += 1;
56 
58  m_profiling = true;
59  info() << "Starting Jemalloc profile at event " << m_eventNumber << endmsg;
60  }
61 
62  if ( m_profiling && ( ( m_eventNumber - m_nStartFromEvent ) % m_dumpPeriod == 0 ) ) {
63  info() << "Jemalloc Dumping heap at event " << m_eventNumber << endmsg;
64  mallctl( "prof.dump", NULL, NULL, NULL, 0 );
65  }
66 
67  if ( m_eventNumber == m_nStopAtEvent ) {
68  m_profiling = false;
69  info() << "Stopping Jemalloc profile at event " << 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 //=============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
JemallocProfile
Definition: JemallocProfile.h:29
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:65
JemallocProfile::m_eventNumber
int m_eventNumber
Definition: JemallocProfile.h:46
JemallocProfile::m_nStopAtEvent
Gaudi::Property< int > m_nStopAtEvent
Definition: JemallocProfile.h:40
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
JemallocProfile::m_dumpPeriod
Gaudi::Property< int > m_dumpPeriod
Definition: JemallocProfile.h:43
TimingHistograms.name
name
Definition: TimingHistograms.py:25
StatusCode
Definition: StatusCode.h:65
JemallocProfile.h
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:52
JemallocProfile::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: JemallocProfile.cpp:78
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
JemallocProfile::m_profiling
bool m_profiling
Definition: JemallocProfile.h:45
JemallocProfile::m_nStartFromEvent
Gaudi::Property< int > m_nStartFromEvent
Definition: JemallocProfile.h:39
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
mallctl
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
JemallocProfile::execute
StatusCode execute() override
Algorithm execution.
Definition: JemallocProfile.cpp:50
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101