LDMX Software
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
framework::performance::Tracker Class Reference

Class to interface between framework::Process and various measurements that can eventually be written into the output histogram file. More...

#include <Tracker.h>

Public Member Functions

 Tracker (TDirectory *storage_directory, const std::vector< std::string > &names)
 Create the tracker with a specific destination for writing information.
 
 ~Tracker ()
 Close up tracking and write all of the data collected to the storage directory.
 
void absolute_start ()
 literally first line of Process::run
 
void absolute_stop ()
 literally last line of Process::run (if run compeletes without error)
 
void start (Callback cb, std::size_t i_proc)
 start the timer for a specific callback and specific processor
 
void stop (Callback cb, std::size_t i_proc)
 stop the timer for a specific callback and specific processor
 
void end_event (bool completed)
 inform us that we finished an event (and whether it was completed or not)
 

Private Attributes

TDirectory * storage_directory_
 handle to the destination for the data
 
TTree * event_data_
 event-by-event perf info
 
bool event_completed_
 buffer for bool flag on if event completed
 
Timer absolute_
 timer from the first line of Process::run to the last line
 
std::vector< std::vector< Timer > > processor_timers_
 a timer for each processor in the sequence and each callback
 
std::vector< std::string > names_
 names of the processors in the sequence for serialization
 

Static Private Attributes

static const std::string ALL = "__ALL__"
 Special name representing "all" processors in the sequence.
 

Detailed Description

Class to interface between framework::Process and various measurements that can eventually be written into the output histogram file.

See also
Timer for the data format of timing measurements

Definition at line 20 of file Tracker.h.

Constructor & Destructor Documentation

◆ Tracker()

framework::performance::Tracker::Tracker ( TDirectory *  storage_directory,
const std::vector< std::string > &  names 
)

Create the tracker with a specific destination for writing information.

Parameters
[in]storage_directorydirectory in-which to write data when closing
[in]namessequence of processor names we will be tracking

Create the event-by-event data TTree while within the storage directory. This means the event data TTree will be connected to this file automatically and will be written there and full synchronized when that file is closed

Copy the processor names passed to us and include an extra name at the beginning representing a timer encompasing all of the processors in the sequence

Allocate timers for each of the callbacks and each of the processors

Attach the processor timers to the event-by-event data TTree as branches

Note
This is where we connect the address of our timer to the TTree for serialization. This effectively means that the vector of processor_timers_ should not be moved or changed in size to avoid breaking this I/O connection.

We add an extra . character after the branch name to tell ROOT to make sure to fully-specify the names of the sub-branches. This makes it a bit easier for other tools (e.g. uproot) to load the data into memory without clashes.

Section 14.10.4 https://root.cern.ch/root/htmldoc/guides/users-guide/Trees.html#adding-a-tbranch-to-hold-an-object

Definition at line 7 of file Tracker.cxx.

9 : storage_directory_{storage_directory} {
18 event_data_ = new TTree("by_event", "by_event");
19
26 names_.reserve(names.size() + 1);
27 names_.push_back(Tracker::ALL);
28 for (const std::string& name : names) {
29 names_.push_back(name);
30 }
31
35 processor_timers_.resize(7); // 7 different callbacks
36 for (std::vector<Timer>& timer_set : processor_timers_) {
37 timer_set.resize(names_.size());
38 }
39
57 event_data_->Branch("completed", &event_completed_);
58 for (std::size_t i{0}; i < names_.size(); i++) {
59 event_data_->Branch((names_[i] + ".").c_str(),
60 &(processor_timers_[to_index(Callback::process)][i]));
61 }
62}
TDirectory * storage_directory_
handle to the destination for the data
Definition Tracker.h:54
std::vector< std::string > names_
names of the processors in the sequence for serialization
Definition Tracker.h:74
bool event_completed_
buffer for bool flag on if event completed
Definition Tracker.h:58
static const std::string ALL
Special name representing "all" processors in the sequence.
Definition Tracker.h:52
TTree * event_data_
event-by-event perf info
Definition Tracker.h:56
std::vector< std::vector< Timer > > processor_timers_
a timer for each processor in the sequence and each callback
Definition Tracker.h:72

References ALL, event_completed_, event_data_, names_, processor_timers_, and storage_directory_.

◆ ~Tracker()

framework::performance::Tracker::~Tracker ( )

Close up tracking and write all of the data collected to the storage directory.

Write the non-event callbacks in their own directories, this data is then accessible as single data-points instead of a TTree of entires

Definition at line 64 of file Tracker.cxx.

64 {
67
73 std::vector<Callback> non_event_callbacks = {
74 Callback::onProcessStart, Callback::onProcessEnd, Callback::onFileOpen,
75 Callback::onFileClose, Callback::beforeNewRun, Callback::onNewRun};
76 for (auto& callback : non_event_callbacks) {
77 TDirectory* callback_d =
78 storage_directory_->mkdir(to_name(callback).c_str());
79 for (std::size_t i_proc{0}; i_proc < names_.size(); i_proc++) {
80 processor_timers_[to_index(callback)][i_proc].write(callback_d,
81 names_[i_proc]);
82 }
83 }
84}
void write(TDirectory *location, const std::string &name) const
Write ourselves under the input name to the input location.
Definition Timer.cxx:29
Timer absolute_
timer from the first line of Process::run to the last line
Definition Tracker.h:61

References absolute_, names_, processor_timers_, storage_directory_, and framework::performance::Timer::write().

Member Function Documentation

◆ absolute_start()

void framework::performance::Tracker::absolute_start ( )

literally first line of Process::run

Definition at line 86 of file Tracker.cxx.

86{ absolute_.start(); }
void start()
start the timer
Definition Timer.cxx:15

References absolute_, and framework::performance::Timer::start().

Referenced by framework::Process::run().

◆ absolute_stop()

void framework::performance::Tracker::absolute_stop ( )

literally last line of Process::run (if run compeletes without error)

Definition at line 88 of file Tracker.cxx.

88{ absolute_.stop(); }
void stop()
stop the timer
Definition Timer.cxx:22

References absolute_, and framework::performance::Timer::stop().

Referenced by framework::Process::run().

◆ end_event()

void framework::performance::Tracker::end_event ( bool  completed)

inform us that we finished an event (and whether it was completed or not)

Make sure to reset the timer after the event data has been filled so that if a future event is not completed (and some timers are not started or ended), that can be reflected in the serialized data.

Definition at line 98 of file Tracker.cxx.

98 {
99 event_completed_ = completed;
100 event_data_->Fill();
106 for (std::size_t i_proc{0}; i_proc < names_.size(); i_proc++) {
107 processor_timers_[to_index(Callback::process)][i_proc].reset();
108 }
109}

References event_completed_, event_data_, names_, and processor_timers_.

Referenced by framework::Process::process().

◆ start()

void framework::performance::Tracker::start ( Callback  cb,
std::size_t  i_proc 
)

start the timer for a specific callback and specific processor

Definition at line 90 of file Tracker.cxx.

90 {
91 processor_timers_[to_index(callback)][i_proc].start();
92}

References processor_timers_.

Referenced by framework::Process::newRun(), framework::Process::onFileClose(), framework::Process::onFileOpen(), framework::Process::process(), and framework::Process::run().

◆ stop()

void framework::performance::Tracker::stop ( Callback  cb,
std::size_t  i_proc 
)

stop the timer for a specific callback and specific processor

Definition at line 94 of file Tracker.cxx.

94 {
95 processor_timers_[to_index(callback)][i_proc].stop();
96}

References processor_timers_.

Referenced by framework::Process::newRun(), framework::Process::onFileClose(), framework::Process::onFileOpen(), framework::Process::process(), and framework::Process::run().

Member Data Documentation

◆ absolute_

Timer framework::performance::Tracker::absolute_
private

timer from the first line of Process::run to the last line

Definition at line 61 of file Tracker.h.

Referenced by absolute_start(), absolute_stop(), and ~Tracker().

◆ ALL

const std::string framework::performance::Tracker::ALL = "__ALL__"
staticprivate

Special name representing "all" processors in the sequence.

For measurements related to beginning, this is before all processors and for measurements related to ending, this is after all processors.

Definition at line 52 of file Tracker.h.

Referenced by Tracker().

◆ event_completed_

bool framework::performance::Tracker::event_completed_
private

buffer for bool flag on if event completed

Definition at line 58 of file Tracker.h.

Referenced by end_event(), and Tracker().

◆ event_data_

TTree* framework::performance::Tracker::event_data_
private

event-by-event perf info

Definition at line 56 of file Tracker.h.

Referenced by end_event(), and Tracker().

◆ names_

std::vector<std::string> framework::performance::Tracker::names_
private

names of the processors in the sequence for serialization

Definition at line 74 of file Tracker.h.

Referenced by end_event(), Tracker(), and ~Tracker().

◆ processor_timers_

std::vector<std::vector<Timer> > framework::performance::Tracker::processor_timers_
private

a timer for each processor in the sequence and each callback

The timers for the process Callback (Producer::produce or Analyzer::analyze) need to stay in the same memory location during the lifetime of this object. This is because the address of those timers is given to event_data_ to watch (and eventually serialize) while processing. Effectively, this means the size and shape of this member should be set in the constructor and then it should not be changed.

Definition at line 72 of file Tracker.h.

Referenced by end_event(), start(), stop(), Tracker(), and ~Tracker().

◆ storage_directory_

TDirectory* framework::performance::Tracker::storage_directory_
private

handle to the destination for the data

Definition at line 54 of file Tracker.h.

Referenced by Tracker(), and ~Tracker().


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