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