The Gaudi Framework  v29r0 (ff2e7097)
TimelineSvc.cpp
Go to the documentation of this file.
1 #include "TimelineSvc.h"
4 
5 #include <fstream>
6 
7 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8 
10 {
11 
13  if ( !sc.isSuccess() ) return sc;
14 
15  if ( msgLevel( MSG::DEBUG ) ) debug() << "initialize" << endmsg;
16 
17  m_events.clear();
18 
19  if ( m_partial ) {
20  std::ofstream out( m_timelineFile + ".part", std::ofstream::trunc | std::ofstream::out );
21  out << "#start end algorithm thread slot event" << std::endl;
22  out.close();
23  }
24 
25  return StatusCode::SUCCESS;
26 }
27 
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
29 
31 {
32 
33  MsgStream log( msgSvc(), name() );
34  log << MSG::DEBUG << "reinitialize" << endmsg;
35 
36  m_events.clear();
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 {
44 
45  if ( m_dumpTimeline && m_events.size() > 0 ) {
46  MsgStream log( msgSvc(), name() );
47 
48  log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile
49  << endmsg;
50 
52  }
53 
54  return StatusCode::SUCCESS;
55 }
56 
57 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
58 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
59 
61 {
62 
63  m_events.push_back( e );
64 
65  if ( m_partial ) {
66  std::ofstream out( m_timelineFile + ".part", std::ofstream::app | std::ofstream::out );
67  out << std::chrono::duration_cast<std::chrono::nanoseconds>( e.start.time_since_epoch() ).count() << " "
68  << std::chrono::duration_cast<std::chrono::nanoseconds>( e.end.time_since_epoch() ).count() << " "
69  << e.algorithm << " " << e.thread << " " << e.slot << " " << e.event << std::endl;
70 
71  out.close();
72  }
73 }
74 
76 {
77 
78  for ( const auto& candidate : m_events ) {
79  if ( candidate.algorithm == e.algorithm ) {
80  e = candidate;
81  break;
82  }
83  }
84 }
85 
86 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
87 
88 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
89 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
90 
92 {
93 
94  std::ofstream out( m_timelineFile, std::ofstream::out | std::ofstream::trunc );
95 
96  out << "#start end algorithm thread slot event" << std::endl;
97 
98  for ( const auto& e : m_events ) {
99  out << std::chrono::duration_cast<std::chrono::nanoseconds>( e.start.time_since_epoch() ).count() << " "
100  << std::chrono::duration_cast<std::chrono::nanoseconds>( e.end.time_since_epoch() ).count() << " "
101  << e.algorithm << " " << e.thread << " " << e.slot << " " << e.event << std::endl;
102  }
103 
104  out.close();
105 }
106 
107 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
108 
void getTimelineEvent(TimelineEvent &) const override
Definition: TimelineSvc.cpp:75
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:64
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
pthread_t thread
Definition: ITimelineSvc.h:14
Gaudi::Property< bool > m_partial
Definition: TimelineSvc.h:36
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
T endl(T...args)
std::string algorithm
Definition: ITimelineSvc.h:18
T duration_cast(T...args)
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
time_point end
Definition: ITimelineSvc.h:21
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
T close(T...args)
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:38
StatusCode finalize() override
Definition: TimelineSvc.cpp:42
StatusCode initialize() override
Definition: TimelineSvc.cpp:9
time_point start
Definition: ITimelineSvc.h:20
Gaudi::Property< std::string > m_timelineFile
Definition: TimelineSvc.h:33
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void registerTimelineEvent(const TimelineEvent &) override
Definition: TimelineSvc.cpp:60
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
void outputTimeline()
Definition: TimelineSvc.cpp:91
StatusCode reinitialize() override
Definition: TimelineSvc.cpp:30
Gaudi::Property< bool > m_dumpTimeline
Definition: TimelineSvc.h:35
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209