DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
oks
src
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
11
namespace
dunedaq
{
12
namespace
oks
{
13
14
static
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
50
namespace
oks
{
51
double
52
get_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
58
OksProfiler::OksProfiler
()
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
68
static
void
69
printTableSeparator
(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
83
static
void
84
printTableLine
(std::ostream& s,
unsigned
char
c)
85
{
86
s <<
'+'
;
87
s.fill(c);
88
s.width(76);
89
s <<
""
<<
'+'
<< std::endl;
90
}
91
92
std::ostream&
93
operator<<
(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
178
void
179
OksProfiler::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
185
void
186
OksProfiler::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
192
OksFunctionProfiler::OksFunctionProfiler
(
OksProfiler::FunctionID
fid,
const
OksKernel
* k)
193
:
kernel
(k)
194
,
func_id
(fid)
195
{
196
if
(k && k->
get_profiling_mode
())
197
k->
GetOksProfiler
()->
Start
(fid,
p_start_time_point
);
198
}
199
200
OksFunctionProfiler::~OksFunctionProfiler
()
201
{
202
if
(
kernel
&&
kernel
->
get_profiling_mode
())
203
kernel
->
GetOksProfiler
()->
Stop
(
func_id
,
p_start_time_point
);
204
}
205
206
}
// namespace oks
207
}
// namespace dunedaq
dunedaq::oks::OksFunctionProfiler::~OksFunctionProfiler
~OksFunctionProfiler()
Definition
profiler.cpp:200
dunedaq::oks::OksFunctionProfiler::func_id
OksProfiler::FunctionID func_id
Definition
profiler.hpp:88
dunedaq::oks::OksFunctionProfiler::p_start_time_point
std::chrono::time_point< std::chrono::steady_clock > p_start_time_point
Definition
profiler.hpp:89
dunedaq::oks::OksFunctionProfiler::kernel
const OksKernel * kernel
Definition
profiler.hpp:87
dunedaq::oks::OksFunctionProfiler::OksFunctionProfiler
OksFunctionProfiler(OksProfiler::FunctionID, const OksKernel *)
Definition
profiler.cpp:192
dunedaq::oks::OksKernel
Provides interface to the OKS kernel.
Definition
kernel.hpp:615
dunedaq::oks::OksKernel::get_profiling_mode
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
dunedaq::oks::OksKernel::GetOksProfiler
OksProfiler * GetOksProfiler() const
Definition
kernel.hpp:655
dunedaq::oks::OksProfiler::operator<<
friend std::ostream & operator<<(std::ostream &, const OksProfiler &)
Definition
profiler.cpp:93
dunedaq::oks::OksProfiler::c_total
unsigned long c_total[(unsigned) OksProfiler::QueryOperatorFrom+1]
Definition
profiler.hpp:74
dunedaq::oks::OksProfiler::p_start_time_point
std::chrono::time_point< std::chrono::steady_clock > p_start_time_point
Definition
profiler.hpp:71
dunedaq::oks::OksProfiler::FunctionID
FunctionID
Definition
profiler.hpp:22
dunedaq::oks::OksProfiler::QueryOperatorFrom
@ QueryOperatorFrom
Definition
profiler.hpp:57
dunedaq::oks::OksProfiler::t_total
double t_total[(unsigned) OksProfiler::QueryOperatorFrom+1]
Definition
profiler.hpp:73
dunedaq::oks::OksProfiler::OksProfiler
OksProfiler()
Definition
profiler.cpp:58
dunedaq::oks::OksProfiler::Start
void Start(OksProfiler::FunctionID, std::chrono::time_point< std::chrono::steady_clock > &)
Definition
profiler.cpp:179
dunedaq::oks::OksProfiler::Stop
void Stop(OksProfiler::FunctionID, const std::chrono::time_point< std::chrono::steady_clock > &)
Definition
profiler.cpp:186
kernel.hpp
dunedaq::oks::oks::get_time_interval
double get_time_interval(const timeval *t1, const timeval *t2)
Definition
profiler.cpp:52
dunedaq::oks::OksProfilerFunctionsStr
static const char * OksProfilerFunctionsStr[]
Definition
profiler.cpp:14
dunedaq::oks::printTableSeparator
static void printTableSeparator(std::ostream &s, unsigned char c)
Definition
profiler.cpp:69
dunedaq::oks::printTableLine
static void printTableLine(std::ostream &s, unsigned char c)
Definition
profiler.cpp:84
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
oks
Definition
ral.hpp:59
profiler.hpp
Generated on
for DUNE-DAQ by
1.18.0