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