LDMX Software
Tracker.cxx
1#include "Framework/Performance/Tracker.h"
2
3namespace framework::performance {
4
5const std::string Tracker::ALL = "__ALL__";
6
7Tracker::Tracker(TDirectory* storage_directory,
8 const std::vector<std::string>& names)
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}
63
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}
85
87
89
90void Tracker::start(Callback callback, std::size_t i_proc) {
91 processor_timers_[to_index(callback)][i_proc].start();
92}
93
94void Tracker::stop(Callback callback, std::size_t i_proc) {
95 processor_timers_[to_index(callback)][i_proc].stop();
96}
97
98void Tracker::end_event(bool completed) {
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}
110
111} // namespace framework::performance
void write(TDirectory *location, const std::string &name) const
Write ourselves under the input name to the input location.
Definition Timer.cxx:29
void stop()
stop the timer
Definition Timer.cxx:22
void start()
start the timer
Definition Timer.cxx:15
void start(Callback cb, std::size_t i_proc)
start the timer for a specific callback and specific processor
Definition Tracker.cxx:90
Tracker(TDirectory *storage_directory, const std::vector< std::string > &names)
Create the tracker with a specific destination for writing information.
Definition Tracker.cxx:7
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
void end_event(bool completed)
inform us that we finished an event (and whether it was completed or not)
Definition Tracker.cxx:98
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
~Tracker()
Close up tracking and write all of the data collected to the storage directory.
Definition Tracker.cxx:64
TTree * event_data_
event-by-event perf info
Definition Tracker.h:56
void stop(Callback cb, std::size_t i_proc)
stop the timer for a specific callback and specific processor
Definition Tracker.cxx:94
void absolute_start()
literally first line of Process::run
Definition Tracker.cxx:86
void absolute_stop()
literally last line of Process::run (if run compeletes without error)
Definition Tracker.cxx:88
Timer absolute_
timer from the first line of Process::run to the last line
Definition Tracker.h:61
std::vector< std::vector< Timer > > processor_timers_
a timer for each processor in the sequence and each callback
Definition Tracker.h:72