| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 ), 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
19 TimelineSvc::~TimelineSvc() {
20
21 }
22
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25
26 StatusCode
27 TimelineSvc::initialize() {
28
29 StatusCode sc = Service::initialize();
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
49 StatusCode
50 TimelineSvc::reinitialize() {
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
62 StatusCode
63 TimelineSvc::finalize() {
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
70 outputTimeline();
71
72 }
73
74 return StatusCode::SUCCESS;
75
76 }
77
78
79 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
80 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
81
82 void TimelineSvc::registerTimelineEvent(const TimelineEvent & e){
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
105 void TimelineSvc::outputTimeline(){
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
126 DECLARE_COMPONENT(TimelineSvc)
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
std::chrono::nanoseconds
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
MsgStream.h
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
TimelineSvc::reinitialize
virtual StatusCode reinitialize()
Definition: TimelineSvc.cpp:50
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
TimelineEvent::algorithm
std::string algorithm
Definition: ITimelineSvc.h:23
std::chrono::duration_cast
T duration_cast(T...args)
TimelineEvent::event
uint event
Definition: ITimelineSvc.h:21
TimelineEvent::thread
uint thread
Definition: ITimelineSvc.h:19
TimelineEvent
Definition: ITimelineSvc.h:18
merge_files.sc
int sc
Definition: merge_files.py:167
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
TimelineSvc::TimelineSvc
TimelineSvc(const std::string &name, ISvcLocator *svc)
Definition: TimelineSvc.cpp:7
std::string
STL class.
TimelineEvent::end
time_point end
Definition: ITimelineSvc.h:26
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
std::ofstream
STL class.
TimelineSvc::m_timelineFile
std::string m_timelineFile
Definition: TimelineSvc.h:36
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
TimelineSvc::registerTimelineEvent
virtual void registerTimelineEvent(const TimelineEvent &e)
Definition: TimelineSvc.cpp:82
std::ofstream::close
T close(T...args)
TimelineSvc::m_partial
bool m_partial
Definition: TimelineSvc.h:35
TimelineSvc::m_events
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:37
TimelineSvc::initialize
virtual StatusCode initialize()
Definition: TimelineSvc.cpp:27
TimelineSvc.h
TimelineEvent::start
time_point start
Definition: ITimelineSvc.h:25
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
TimelineEvent::slot
uint slot
Definition: ITimelineSvc.h:20
CommonMessaging
Definition: CommonMessaging.h:58
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
StatusCode.h
TimelineSvc::finalize
virtual StatusCode finalize()
Definition: TimelineSvc.cpp:63
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
MSG::INFO
Definition: IMessageSvc.h:19
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
TimelineSvc::outputTimeline
void outputTimeline()
Definition: TimelineSvc.cpp:105
TimelineSvc::m_isEnabled
bool m_isEnabled
Definition: TimelineSvc.h:34
TimelineSvc
Definition: TimelineSvc.h:12
TimelineSvc::~TimelineSvc
virtual ~TimelineSvc()
Definition: TimelineSvc.cpp:19
AthenaScenario.app
tuple app
Definition: AthenaScenario.py:89
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244