The Gaudi Framework master (9cc87df9)
Loading...
Searching...
No Matches
TimelineSvc Class Reference
Inheritance diagram for TimelineSvc:
Collaboration diagram for TimelineSvc:

Public Member Functions

StatusCode initialize () override
StatusCode reinitialize () override
StatusCode finalize () override
TimelineRecorder getRecorder (std::string alg, const EventContext &ctx) override
bool getTimelineEvent (TimelineEvent &) const override
bool getFirstMatching (TimelineEvent &) const override
bool getLastMatching (TimelineEvent &) const override
bool isEnabled () const override
Public Member Functions inherited from extends< Service, ITimelineSvc >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
StatusCode configure () override
StatusCode initialize () override
StatusCode start () override
StatusCode stop () override
StatusCode finalize () override
StatusCode terminate () override
Gaudi::StateMachine::State FSMState () const override
Gaudi::StateMachine::State targetFSMState () const override
StatusCode reinitialize () override
StatusCode restart () override
StatusCode sysInitialize () override
 Initialize Service.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBase * declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBase * property (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolder & operator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
MsgStream & msgStream () const
 Return an uninitialized MsgStream.
MsgStream & msgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
MsgStream & always () const
 shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & fatal () const
 shortcut for the method msgStream(MSG::FATAL)
MsgStream & err () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & error () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning () const
 shortcut for the method msgStream(MSG::WARNING)
MsgStream & info () const
 shortcut for the method msgStream(MSG::INFO)
MsgStream & debug () const
 shortcut for the method msgStream(MSG::DEBUG)
MsgStream & verbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & msg () const
 shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream

Private Types

using key_type = std::tuple<std::string, std::size_t>

Private Member Functions

void outputTimeline ()

Private Attributes

Gaudi::Property< std::string > m_timelineFile { this, "TimelineFile", "timeline.csv", "" }
Gaudi::Property< bool > m_isEnabled { this, "RecordTimeline", false, "Enable recording of the timeline events" }
Gaudi::Property< bool > m_dumpTimeline { this, "DumpTimeline", false, "Enable dumping of the timeline events" }
Gaudi::Property< bool > m_partial { this, "Partial", false, "" }
tbb::concurrent_unordered_multimap< key_type, TimelineEvent, boost::hash< key_type > > m_events

Additional Inherited Members

Public Types inherited from extends< Service, ITimelineSvc >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvc > m_pAuditorSvc
 Auditor Service.

Detailed Description

Definition at line 29 of file TimelineSvc.cpp.

Member Typedef Documentation

◆ key_type

using TimelineSvc::key_type = std::tuple<std::string, std::size_t>
private

Definition at line 52 of file TimelineSvc.cpp.

Member Function Documentation

◆ finalize()

StatusCode TimelineSvc::finalize ( )
override

Definition at line 86 of file TimelineSvc.cpp.

86 {
87 if ( m_dumpTimeline && m_events.size() > 0 ) {
88 MsgStream log( msgSvc(), name() );
89
90 log << MSG::INFO << "Outputting timeline with " << m_events.size() << " entries to file " << m_timelineFile.value()
91 << endmsg;
92
94 }
95
97}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
const ValueType & value() const
Definition Property.h:246
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
constexpr static const auto SUCCESS
Definition StatusCode.h:99
void outputTimeline()
Gaudi::Property< std::string > m_timelineFile
Gaudi::Property< bool > m_dumpTimeline
tbb::concurrent_unordered_multimap< key_type, TimelineEvent, boost::hash< key_type > > m_events
@ INFO
Definition IMessageSvc.h:22

◆ getFirstMatching()

bool TimelineSvc::getFirstMatching ( TimelineEvent & e) const
override

Definition at line 120 of file TimelineSvc.cpp.

120 {
121 auto [begin, end] = m_events.equal_range( std::make_tuple( e.algorithm, e.event ) );
122 if ( begin == end ) { return false; }
123 auto it =
124 std::min_element( begin, end, []( const auto& a, const auto& b ) { return a.second.start < b.second.start; } );
125 e = it->second;
126 return true;
127}
constexpr tuple< typename __decay_and_strip< _Elements >::__type... > make_tuple(_Elements &&... __args)
constexpr _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last)
constexpr auto begin(_Container &__cont) -> decltype(__cont.begin())
std::string algorithm

◆ getLastMatching()

bool TimelineSvc::getLastMatching ( TimelineEvent & e) const
override

Definition at line 129 of file TimelineSvc.cpp.

129 {
130 auto [begin, end] = m_events.equal_range( std::make_tuple( e.algorithm, e.event ) );
131 if ( begin == end ) { return false; }
132 auto it =
133 std::max_element( begin, end, []( const auto& a, const auto& b ) { return a.second.start < b.second.start; } );
134 e = it->second;
135 return true;
136}
constexpr _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last)

◆ getRecorder()

ITimelineSvc::TimelineRecorder TimelineSvc::getRecorder ( std::string alg,
const EventContext & ctx )
override

Definition at line 99 of file TimelineSvc.cpp.

99 {
100 auto& newTimelineEvent = m_events.emplace( std::make_tuple( alg, ctx.evt() ), TimelineEvent{} ).first->second;
101 newTimelineEvent.algorithm = std::move( alg );
102 newTimelineEvent.slot = ctx.slot();
103 newTimelineEvent.event = ctx.evt();
104 TimelineRecorder recorder{ newTimelineEvent };
105 if ( m_partial ) {
107 out << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.start.time_since_epoch() ).count()
108 << " "
109 << std::chrono::duration_cast<std::chrono::nanoseconds>( newTimelineEvent.end.time_since_epoch() ).count()
110 << " " << newTimelineEvent.algorithm << " " << newTimelineEvent.thread << " " << newTimelineEvent.slot << " "
111 << newTimelineEvent.event << std::endl;
112
113 out.close();
114 }
115 return recorder;
116}
constexpr __enable_if_is_duration< _ToDur > duration_cast(const duration< _Rep, _Period > &__d)
basic_ofstream< char > ofstream
constexpr _OI move(_II __first, _II __last, _OI __result)
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
static const openmode out
static const openmode app
Gaudi::Property< bool > m_partial

◆ getTimelineEvent()

bool TimelineSvc::getTimelineEvent ( TimelineEvent & e) const
override

Definition at line 118 of file TimelineSvc.cpp.

118{ return getFirstMatching( e ); }
bool getFirstMatching(TimelineEvent &) const override

◆ initialize()

StatusCode TimelineSvc::initialize ( )
override

Definition at line 56 of file TimelineSvc.cpp.

56 {
57 StatusCode sc = Service::initialize();
58 if ( !sc.isSuccess() ) return sc;
59
60 if ( msgLevel( MSG::DEBUG ) ) debug() << "initialize" << endmsg;
61
62 m_events.clear();
63 // the initial allocation of tbb::concurrent_vector determines the size of
64 // the first allocated array, useful to reduce fragmentation
65 m_events.reserve( 1024 );
66
67 if ( m_partial ) {
69 out << "#start end algorithm thread slot event" << std::endl;
70 out.close();
71 }
72
74}
static const openmode trunc
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode initialize() override
Definition Service.cpp:118
bool isSuccess() const
Definition StatusCode.h:302
@ DEBUG
Definition IMessageSvc.h:22

◆ isEnabled()

bool TimelineSvc::isEnabled ( ) const
inlineoverride

Definition at line 42 of file TimelineSvc.cpp.

42{ return m_isEnabled; }
Gaudi::Property< bool > m_isEnabled

◆ outputTimeline()

void TimelineSvc::outputTimeline ( )
private

Definition at line 138 of file TimelineSvc.cpp.

138 {
140
141 out << "#start end algorithm thread slot event" << std::endl;
142
143 auto flat_events = std::vector<TimelineEvent>();
144 flat_events.reserve( m_events.size() );
145
146 std::ranges::copy( m_events | std::views::values, std::back_inserter( flat_events ) );
147
148 std::sort( flat_events.begin(), flat_events.end(), []( const auto& a, const auto& b ) { return a.start < b.start; } );
149 for ( const auto& e : flat_events ) {
150 out << std::chrono::duration_cast<std::chrono::nanoseconds>( e.start.time_since_epoch() ).count() << " "
151 << std::chrono::duration_cast<std::chrono::nanoseconds>( e.end.time_since_epoch() ).count() << " "
152 << e.algorithm << " " << e.thread << " " << e.slot << " " << e.event << std::endl;
153 }
154
155 out.close();
156}
constexpr void sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)

◆ reinitialize()

StatusCode TimelineSvc::reinitialize ( )
override

Definition at line 76 of file TimelineSvc.cpp.

76 {
77
78 MsgStream log( msgSvc(), name() );
79 log << MSG::DEBUG << "reinitialize" << endmsg;
80
81 m_events.clear();
82
84}

Member Data Documentation

◆ m_dumpTimeline

Gaudi::Property<bool> TimelineSvc::m_dumpTimeline { this, "DumpTimeline", false, "Enable dumping of the timeline events" }
private

Definition at line 49 of file TimelineSvc.cpp.

◆ m_events

tbb::concurrent_unordered_multimap<key_type, TimelineEvent, boost::hash<key_type> > TimelineSvc::m_events
private

Definition at line 53 of file TimelineSvc.cpp.

◆ m_isEnabled

Gaudi::Property<bool> TimelineSvc::m_isEnabled { this, "RecordTimeline", false, "Enable recording of the timeline events" }
private

Definition at line 48 of file TimelineSvc.cpp.

◆ m_partial

Gaudi::Property<bool> TimelineSvc::m_partial { this, "Partial", false, "" }
private

Definition at line 50 of file TimelineSvc.cpp.

◆ m_timelineFile

Gaudi::Property<std::string> TimelineSvc::m_timelineFile { this, "TimelineFile", "timeline.csv", "" }
private

Definition at line 47 of file TimelineSvc.cpp.


The documentation for this class was generated from the following file: