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