DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
profiler.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3// Fork baseline commit: oks-08-03-04 (2022-04-14).
4// Renamed since fork: no.
5
6#define _OksBuildDll_
7
8#include "oks/profiler.hpp"
9#include "oks/kernel.hpp"
10
11namespace dunedaq {
12namespace oks {
13
14static const char* OksProfilerFunctionsStr[] = { "OksKernel::Destructor",
15 "OksKernel::operator<<",
16 "OksKernel::load_schema",
17 "OksKernel::save_schema",
18 "OksKernel::close_schema",
19 "OksKernel::CreateSchemaClassList",
20 "OksKernel::load_data",
21 "OksKernel::save_data",
22 "OksKernel::close_data",
23 "OksKernel::CreateDataObjectList",
24 "OksKernel::is_danglingObject",
25 "OksKernel::is_danglingClass",
26 "OksObject::StreamConstructor",
27 "OksObject::NormalConstructor",
28 "OksObject::CopyConstructor",
29 "OksObject::Destructor",
30 "OksObject::operator==",
31 "OksObject::operator<<",
32 "OksObject::SatisfiesQueryExpression",
33 "OksObject::GetFreeObjectId",
34 "OksObject::PutObject",
35 "OksClass::Constructor",
36 "OksClass::Destructor",
37 "OksClass::operator<<",
38 "OksClass::GetObject",
39 "OksClass::execute_query",
40 "OksClass::RegistrateClass",
41 "OksClass::RegistrateClassChange",
42 "OksClass::RegistrateAttributeChange",
43 "OksClass::RegistrateRelationshipChange",
44 "OksClass::RegistrateInstances",
45 "OksClass::CreateSubClassesList",
46 "oksStringToQuery",
47 "oksStringToQueryExpression",
48 "OksQuery::operator<<" };
49
50namespace oks {
51double
52get_time_interval(const timeval* t1, const timeval* t2)
53{
54 return (t1->tv_sec - t2->tv_sec) + (t1->tv_usec - t2->tv_usec) / 1000000.;
55}
56}
57
59{
60 for (short i = 0; i <= (short)QueryOperatorFrom; i++) {
61 t_total[i] = 0.0;
62 c_total[i] = 0;
63 }
64
65 p_start_time_point = std::chrono::steady_clock::now();
66}
67
68static void
69printTableSeparator(std::ostream& s, unsigned char c)
70{
71 s << '+';
72 s.fill(c);
73 s.width(41);
74 s << "" << '+';
75 s.width(12);
76 s << "" << '+';
77 s.width(10);
78 s << "" << '+';
79 s.width(10);
80 s << "" << '+' << std::endl;
81}
82
83static void
84printTableLine(std::ostream& s, unsigned char c)
85{
86 s << '+';
87 s.fill(c);
88 s.width(76);
89 s << "" << '+' << std::endl;
90}
91
92std::ostream&
93operator<<(std::ostream& s, const OksProfiler& t)
94{
95 const int p = s.precision(4);
96
97 printTableLine(s, '=');
98
99 s << '|';
100 s.fill(' ');
101 s.width(76);
102 s.setf(std::ios::left, std::ios::adjustfield);
103 s << " O K S P R O F I L E R " << '|' << std::endl;
104
105 printTableLine(s, '-');
106
107 s << "| Time: ";
108 s.setf(std::ios::right, std::ios::adjustfield);
109 s << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t.p_start_time_point)
110 .count() /
111 1000.;
112 s.fill(' ');
113 s.width(64);
114 s.setf(std::ios::left, std::ios::adjustfield);
115 s << " seconds" << '|' << std::endl;
116
117 printTableSeparator(s, '-');
118
119 s.fill(' ');
120 s.width(42);
121 s << "| Function name" << '|';
122 s.width(12);
123 s << " # of calls" << '|';
124 s.width(10);
125 s << " total T," << '|';
126 s.width(10);
127 s << " ~T/call," << '|' << std::endl;
128
129 s.fill(' ');
130 s.width(42);
131 s << '|' << "" << '|';
132 s.width(12);
133 s << "" << '|';
134 s.width(10);
135 s << " ms" << '|';
136 s.width(10);
137 s << " µs" << '|' << std::endl;
138
139 for (short i = 0; i <= (short)OksProfiler::QueryOperatorFrom; i++) {
140 if (i == 0 || i == 12 || i == 21 || i == 32)
141 printTableSeparator(s, '-');
142
143 s << "| ";
144
145 s.width(40);
146 s.fill(' ');
147 s.setf(std::ios::left, std::ios::adjustfield);
148 s << OksProfilerFunctionsStr[i] << '|';
149
150 s.width(11);
151 s.setf(std::ios::right, std::ios::adjustfield);
152 s << t.c_total[i] << ' ' << '|';
153
154 if (t.c_total[i]) {
155 s.width(9);
156 s << t.t_total[i] / 1000. << ' ' << '|';
157
158 s.width(9);
159 s << t.t_total[i] / (double)t.c_total[i];
160 } else {
161 s.width(10);
162 s << " - " << '|';
163
164 s.width(9);
165 s << " -";
166 }
167
168 s << " |\n";
169 }
170
171 printTableSeparator(s, '=');
172
173 s.precision(p);
174
175 return s;
176}
177
178void
179OksProfiler::Start(OksProfiler::FunctionID fid, std::chrono::time_point<std::chrono::steady_clock>& time_point)
180{
181 time_point = std::chrono::steady_clock::now();
182 c_total[fid]++;
183}
184
185void
186OksProfiler::Stop(OksProfiler::FunctionID fid, const std::chrono::time_point<std::chrono::steady_clock>& time_point)
187{
188 t_total[fid] +=
189 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - time_point).count();
190}
191
199
205
206} // namespace oks
207} // namespace dunedaq
OksProfiler::FunctionID func_id
Definition profiler.hpp:88
std::chrono::time_point< std::chrono::steady_clock > p_start_time_point
Definition profiler.hpp:89
OksFunctionProfiler(OksProfiler::FunctionID, const OksKernel *)
Definition profiler.cpp:192
Provides interface to the OKS kernel.
Definition kernel.hpp:615
bool get_profiling_mode() const
Get status of profiling mode. The method returns true, if the profiling mode is switched 'On'....
Definition kernel.hpp:739
OksProfiler * GetOksProfiler() const
Definition kernel.hpp:655
friend std::ostream & operator<<(std::ostream &, const OksProfiler &)
Definition profiler.cpp:93
unsigned long c_total[(unsigned) OksProfiler::QueryOperatorFrom+1]
Definition profiler.hpp:74
std::chrono::time_point< std::chrono::steady_clock > p_start_time_point
Definition profiler.hpp:71
double t_total[(unsigned) OksProfiler::QueryOperatorFrom+1]
Definition profiler.hpp:73
void Start(OksProfiler::FunctionID, std::chrono::time_point< std::chrono::steady_clock > &)
Definition profiler.cpp:179
void Stop(OksProfiler::FunctionID, const std::chrono::time_point< std::chrono::steady_clock > &)
Definition profiler.cpp:186
double get_time_interval(const timeval *t1, const timeval *t2)
Definition profiler.cpp:52
static const char * OksProfilerFunctionsStr[]
Definition profiler.cpp:14
static void printTableSeparator(std::ostream &s, unsigned char c)
Definition profiler.cpp:69
static void printTableLine(std::ostream &s, unsigned char c)
Definition profiler.cpp:84
The DUNE-DAQ namespace.
Definition ral.hpp:59