The Gaudi Framework  master (1304469f)
Loading...
Searching...
No Matches
TimelineSvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include "TimelineSvc.h"
15
16#include <fstream>
17
20 if ( !sc.isSuccess() ) return sc;
21
22 if ( msgLevel( MSG::DEBUG ) ) debug() << "initialize" << endmsg;
23
24 m_events.clear();
25 // the initial allocation of tbb::concurrent_vector determines the size of
26 // the first allocated array, useful to reduce fragmentation
27 m_events.reserve( 1024 );
28
29 if ( m_partial ) {
30 std::ofstream out( m_timelineFile + ".part", std::ofstream::trunc | std::ofstream::out );
31 out << "#start end algorithm thread slot event" << std::endl;
32 out.close();
33 }
34
36}
37
39
40 MsgStream log( msgSvc(), name() );
41 log << MSG::DEBUG << "reinitialize" << endmsg;
42
43 m_events.clear();
44
46}
47
49 if ( m_dumpTimeline && m_events.size() > 0 ) {
50 MsgStream log( msgSvc(), name() );
51
52 log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile.value()
53 << endmsg;
54
56 }
57
59}
60
62 auto& newTimelineEvent = *m_events.emplace_back();
63 TimelineRecorder recorder{ newTimelineEvent, std::move( alg ), ctx };
64 if ( m_partial ) {
65 std::ofstream out( m_timelineFile + ".part", std::ofstream::app | std::ofstream::out );
66 out << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.start.time_since_epoch() ).count()
67 << " "
68 << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.end.time_since_epoch() ).count()
69 << " " << newTimelineEvent.algorithm << " " << newTimelineEvent.thread << " " << newTimelineEvent.slot << " "
70 << newTimelineEvent.event << std::endl;
71
72 out.close();
73 }
74 return recorder;
75}
76
78 for ( const auto& candidate : m_events ) {
79 if ( candidate.algorithm == e.algorithm && candidate.event == e.event ) {
80 e = candidate;
81 return true;
82 }
83 }
84 return false;
85}
86
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 << " " << e.thread << " " << e.slot << " " << e.event << std::endl;
96 }
97
98 out.close();
99}
100
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
This class represents an entry point to all the event specific data.
RAII helper to record timeline events.
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
StatusCode initialize() override
Definition Service.cpp:118
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
Gaudi::Property< bool > m_partial
Definition TimelineSvc.h:40
void outputTimeline()
bool getTimelineEvent(TimelineEvent &) const override
StatusCode initialize() override
StatusCode reinitialize() override
StatusCode finalize() override
Gaudi::Property< std::string > m_timelineFile
Definition TimelineSvc.h:37
TimelineRecorder getRecorder(std::string alg, const EventContext &ctx) override
Gaudi::Property< bool > m_dumpTimeline
Definition TimelineSvc.h:39
tbb::concurrent_vector< TimelineEvent > m_events
Definition TimelineSvc.h:42
@ DEBUG
Definition IMessageSvc.h:22
@ INFO
Definition IMessageSvc.h:22
std::string algorithm