TimelineSvc.cpp
Go to the documentation of this file.
1 #include "TimelineSvc.h"
4 
5 #include <fstream>
6 
8  : base_class( name, svc ), m_partial(false)
9 {
10 
11  declareProperty("TimelineFile", m_timelineFile = "timeline.csv");
12  declareProperty("RecordTimeline", m_isEnabled = false);
13  declareProperty("Partial",m_partial = false);
14 
15 }
16 
17 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18 
20 
21 }
22 
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 
28 
30  if (!sc.isSuccess()) return sc;
31 
32  if (msgLevel(MSG::DEBUG))
33  debug() << "initialize" << endmsg;
34 
35  m_events.clear();
36 
37  if (m_partial) {
38  std::ofstream out(m_timelineFile+".part", std::ofstream::trunc | std::ofstream::out);
39  out << "#start end algorithm thread slot event" << std::endl;
40  out.close();
41  }
42 
43  return StatusCode::SUCCESS;
44 
45 }
46 
47 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48 
51 
52  MsgStream log( msgSvc(), name() );
53  log << MSG::DEBUG << "reinitialize" << endmsg;
54 
55  m_events.clear();
56 
57  return StatusCode::SUCCESS;
58 
59 }
60 
61 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
64 
65  if (m_events.size() > 0) {
66  MsgStream log( msgSvc(), name() );
67 
68  log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile << endmsg;
69 
71 
72  }
73 
74  return StatusCode::SUCCESS;
75 
76 }
77 
78 
79 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
80 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
81 
83 
84  m_events.push_back(e);
85 
86  if (m_partial) {
87  std::ofstream out(m_timelineFile+".part", std::ofstream::app | std::ofstream::out);
88  out << std::chrono::duration_cast<std::chrono::nanoseconds>(e.start.time_since_epoch()).count() << " "
89  << std::chrono::duration_cast<std::chrono::nanoseconds>(e.end.time_since_epoch()).count() << " "
90  << e.algorithm << " "
91  << e.thread << " "
92  << e.slot << " "
93  << e.event << std::endl;
94 
95  out.close();
96  }
97 
98 }
99 
100 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
101 
102 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
103 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
104 
106 
107  std::ofstream out(m_timelineFile, std::ofstream::out | std::ofstream::trunc);
108 
109  out << "#start end algorithm thread slot event" << std::endl;
110 
111  for(const auto & e : m_events){
112  out << std::chrono::duration_cast<std::chrono::nanoseconds>(e.start.time_since_epoch()).count() << " "
113  << std::chrono::duration_cast<std::chrono::nanoseconds>(e.end.time_since_epoch()).count() << " "
114  << e.algorithm << " "
115  << e.thread << " "
116  << e.slot << " "
117  << e.event << std::endl;
118  }
119 
120  out.close();
121 
122 }
123 
124 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
125 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:68
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
virtual StatusCode reinitialize()
Definition: TimelineSvc.cpp:50
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
T endl(T...args)
std::string algorithm
Definition: ITimelineSvc.h:23
T duration_cast(T...args)
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
TimelineSvc(const std::string &name, ISvcLocator *svc)
Definition: TimelineSvc.cpp:7
STL class.
time_point end
Definition: ITimelineSvc.h:26
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
STL class.
std::string m_timelineFile
Definition: TimelineSvc.h:36
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual void registerTimelineEvent(const TimelineEvent &e)
Definition: TimelineSvc.cpp:82
T close(T...args)
bool m_partial
Definition: TimelineSvc.h:35
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:37
virtual StatusCode initialize()
Definition: TimelineSvc.cpp:27
time_point start
Definition: ITimelineSvc.h:25
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual StatusCode finalize()
Definition: TimelineSvc.cpp:63
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
void outputTimeline()
bool m_isEnabled
Definition: TimelineSvc.h:34
virtual ~TimelineSvc()
Definition: TimelineSvc.cpp:19
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244