| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8
9 StatusCode
10 TimelineSvc::initialize() {
11
12 StatusCode sc = Service::initialize();
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
32 StatusCode
33 TimelineSvc::reinitialize() {
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 StatusCode
46 TimelineSvc::finalize() {
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
53 outputTimeline();
54
55 }
56
57 return StatusCode::SUCCESS;
58
59 }
60
61
62 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
63 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
64
65 void TimelineSvc::registerTimelineEvent(const TimelineEvent & e){
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
88 void TimelineSvc::outputTimeline(){
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
109 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:64
std::chrono::nanoseconds
StatusCode::SUCCESS
Definition: StatusCode.h:30
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
MsgStream.h
TimelineEvent::thread
pthread_t thread
Definition: ITimelineSvc.h:14
TimelineSvc::m_partial
Gaudi::Property< bool > m_partial
Definition: TimelineSvc.h:34
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
TimelineEvent::algorithm
std::string algorithm
Definition: ITimelineSvc.h:18
std::chrono::duration_cast
T duration_cast(T...args)
TimelineEvent::event
uint event
Definition: ITimelineSvc.h:16
TimelineEvent
Definition: ITimelineSvc.h:13
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
TimelineEvent::end
time_point end
Definition: ITimelineSvc.h:21
std::ofstream
STL class.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::ofstream::close
T close(T...args)
TimelineSvc::m_events
tbb::concurrent_vector< TimelineEvent > m_events
Definition: TimelineSvc.h:36
TimelineSvc::finalize
StatusCode finalize() override
Definition: TimelineSvc.cpp:46
TimelineSvc.h
TimelineSvc::initialize
StatusCode initialize() override
Definition: TimelineSvc.cpp:10
TimelineEvent::start
time_point start
Definition: ITimelineSvc.h:20
TimelineSvc::m_timelineFile
Gaudi::Property< std::string > m_timelineFile
Definition: TimelineSvc.h:32
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
TimelineEvent::slot
uint slot
Definition: ITimelineSvc.h:15
BrunelScenarioForwardScheduler.app
app
Definition: BrunelScenarioForwardScheduler.py:137
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:70
TimelineSvc::registerTimelineEvent
void registerTimelineEvent(const TimelineEvent &e) override
Definition: TimelineSvc.cpp:65
StatusCode.h
MSG::INFO
Definition: IMessageSvc.h:19
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
TimelineSvc::outputTimeline
void outputTimeline()
Definition: TimelineSvc.cpp:88
TimelineSvc::reinitialize
StatusCode reinitialize() override
Definition: TimelineSvc.cpp:33
TimelineSvc
Definition: TimelineSvc.h:12
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi.Configuration.log
log
Definition: Configuration.py:13