TimelineSvc.cpp
Go to the documentation of this file.
1 #include "TimelineSvc.h"
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/StatusCode.h"
4 
5 #include <fstream>
6 
7 TimelineSvc::TimelineSvc(const std::string& name, ISvcLocator* svc )
8  : base_class( name, svc )
9 {
10 
11  declareProperty("TimelineFile", m_timelineFile = "timeline.csv");
12  declareProperty("RecordTimeline", m_isEnabled = false);
13 
14 }
15 
16 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
17 
19 
20 }
21 
22 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 
24 
27 
29  if (!sc.isSuccess()) return sc;
30 
31  MsgStream log( msgSvc(), name() );
32  log << MSG::DEBUG << "initialize" << endmsg;
33 
34  m_events.clear();
35 
36  return StatusCode::SUCCESS;
37 
38 }
39 
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 
44 
45  MsgStream log( msgSvc(), name() );
46  log << MSG::DEBUG << "reinitialize" << endmsg;
47 
48  m_events.clear();
49 
50  return StatusCode::SUCCESS;
51 
52 }
53 
54 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
57 
58  if (m_events.size() > 0) {
59  MsgStream log( msgSvc(), name() );
60 
61  log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile << endmsg;
62 
64 
65  }
66 
67  return StatusCode::SUCCESS;
68 
69 }
70 
71 
72 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
73 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
74 
76 
77  m_events.push_back(e);
78 
79 }
80 
81 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
82 
83 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
84 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
85 
87 
88  std::ofstream out(m_timelineFile, std::ofstream::out | std::ofstream::trunc);
89 
90  out << "#start end algorithm thread slot event" << std::endl;
91 
92  for(const auto & e : m_events){
93  out << std::chrono::duration_cast<std::chrono::nanoseconds>(e.start.time_since_epoch()).count() << " "
94  << std::chrono::duration_cast<std::chrono::nanoseconds>(e.end.time_since_epoch()).count() << " "
95  << e.algorithm << " "
96  << e.thread << " "
97  << e.slot << " "
98  << e.event << std::endl;
99  }
100 
101  out.close();
102 
103 }
104 
105 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106 
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode reinitialize()
Definition: TimelineSvc.cpp:43
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
TimelineSvc(const std::string &name, ISvcLocator *svc)
Definition: TimelineSvc.cpp:7
std::string m_timelineFile
Definition: TimelineSvc.h:34
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual void registerTimelineEvent(const TimelineEvent &e)
Definition: TimelineSvc.cpp:75
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:35
virtual StatusCode initialize()
Definition: TimelineSvc.cpp:26
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
virtual StatusCode finalize()
Definition: TimelineSvc.cpp:56
void outputTimeline()
Definition: TimelineSvc.cpp:86
bool m_isEnabled
Definition: TimelineSvc.h:33
virtual ~TimelineSvc()
Definition: TimelineSvc.cpp:18