Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TimelineSvc.cpp
Go to the documentation of this file.
1 #include "TimelineSvc.h"
4 
5 #include <fstream>
6 
9  if ( !sc.isSuccess() ) return sc;
10 
11  if ( msgLevel( MSG::DEBUG ) ) debug() << "initialize" << endmsg;
12 
13  m_events.clear();
14  // the initial allocation of tbb::concurrent_vector determines the size of
15  // the first allocated array, useful to reduce fragmentation
16  m_events.reserve( 1024 );
17 
18  if ( m_partial ) {
19  std::ofstream out( m_timelineFile + ".part", std::ofstream::trunc | std::ofstream::out );
20  out << "#start end algorithm thread slot event" << std::endl;
21  out.close();
22  }
23 
24  return StatusCode::SUCCESS;
25 }
26 
28 
29  MsgStream log( msgSvc(), name() );
30  log << MSG::DEBUG << "reinitialize" << endmsg;
31 
32  m_events.clear();
33 
34  return StatusCode::SUCCESS;
35 }
36 
38  if ( m_dumpTimeline && m_events.size() > 0 ) {
39  MsgStream log( msgSvc(), name() );
40 
41  log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile
42  << endmsg;
43 
45  }
46 
47  return StatusCode::SUCCESS;
48 }
49 
51  auto& newTimelineEvent = *m_events.emplace_back();
52  TimelineRecorder recorder{newTimelineEvent, std::move( alg ), ctx};
53  if ( m_partial ) {
54  std::ofstream out( m_timelineFile + ".part", std::ofstream::app | std::ofstream::out );
55  out << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.start.time_since_epoch() ).count()
56  << " "
57  << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.end.time_since_epoch() ).count()
58  << " " << newTimelineEvent.algorithm << " " << newTimelineEvent.thread << " " << newTimelineEvent.slot << " "
59  << newTimelineEvent.event << std::endl;
60 
61  out.close();
62  }
63  return recorder;
64 }
65 
67  for ( const auto& candidate : m_events ) {
68  if ( candidate.algorithm == e.algorithm && candidate.event == e.event ) {
69  e = candidate;
70  return true;
71  }
72  }
73  return false;
74 }
75 
77  std::ofstream out( m_timelineFile, std::ofstream::out | std::ofstream::trunc );
78 
79  out << "#start end algorithm thread slot event" << std::endl;
80 
81  for ( const auto& e : m_events ) {
82  out << std::chrono::duration_cast<std::chrono::nanoseconds>( e.start.time_since_epoch() ).count() << " "
83  << std::chrono::duration_cast<std::chrono::nanoseconds>( e.end.time_since_epoch() ).count() << " "
84  << e.algorithm << " " << e.thread << " " << e.slot << " " << e.event << std::endl;
85  }
86 
87  out.close();
88 }
89 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:60
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
Gaudi::Property< bool > m_partial
Definition: TimelineSvc.h:31
bool isSuccess() const
Definition: StatusCode.h:267
T endl(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::string algorithm
Definition: ITimelineSvc.h:21
T duration_cast(T...args)
This class represents an entry point to all the event specific data.
Definition: EventContext.h:31
STL class.
#define DECLARE_COMPONENT(type)
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
T close(T...args)
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:33
bool getTimelineEvent(TimelineEvent &) const override
Definition: TimelineSvc.cpp:66
StatusCode finalize() override
Definition: TimelineSvc.cpp:37
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
TimelineRecorder getRecorder(std::string alg, const EventContext &ctx) override
Definition: TimelineSvc.cpp:50
T move(T...args)
StatusCode initialize() override
Definition: TimelineSvc.cpp:7
Gaudi::Property< std::string > m_timelineFile
Definition: TimelineSvc.h:28
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
RAII helper to record timeline events.
Definition: ITimelineSvc.h:34
void outputTimeline()
Definition: TimelineSvc.cpp:76
StatusCode reinitialize() override
Definition: TimelineSvc.cpp:27
Gaudi::Property< bool > m_dumpTimeline
Definition: TimelineSvc.h:30
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)