| The Gaudi Framework v29r1 (5cd95fa2)

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