Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
e1bd1f1e
Commit
e1bd1f1e
authored
6 months ago
by
Joan Vallvé Navarro
Browse files
Options
Downloads
Patches
Plain Diff
[skip ci] implementing profiling_unit
parent
2df5d183
No related branches found
No related tags found
1 merge request
!448
Draft: Resolve "Implementation of new nodes creation"
Pipeline
#20345
skipped
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/core/common/profiling_unit.h
+142
-0
142 additions, 0 deletions
include/core/common/profiling_unit.h
include/core/processor/processor_base.h
+14
-0
14 additions, 0 deletions
include/core/processor/processor_base.h
src/processor/processor_base.cpp
+19
-7
19 additions, 7 deletions
src/processor/processor_base.cpp
with
175 additions
and
7 deletions
include/core/common/profiling_unit.h
0 → 100644
+
142
−
0
View file @
e1bd1f1e
// WOLF - Copyright (C) 2020,2021,2022,2023,2024,2025
// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
// Joan Vallvé Navarro (jvallve@iri.upc.edu)
// All rights reserved.
//
// This file is part of WOLF: http://www.iri.upc.edu/wolf
// WOLF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
// wolf includes
#include
"core/common/wolf.h"
// C, std
#include
<sys/time.h>
#include
<iostream>
#include
<iomanip>
static
const
unsigned
int
NANOSECS
=
1000000000
;
namespace
wolf
{
/**
* \brief TimeStamp implements basic functionalities for time stamps
*
* TimeStamp implements basic functionalities for time stamps
*/
class
ProfilingUnit
{
protected:
double
desired_period_
;
unsigned
int
n_callbacks_
;
double
average_period_
;
std
::
chrono
::
microseconds
acc_duration_
;
std
::
chrono
::
microseconds
max_duration_
;
double
var_duration_
;
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
>
first_clock_
;
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
>
start_clock_
;
public:
/** \brief Constructor
*
* Constructor without arguments. Sets time stamp to now.
*
*/
ProfilingUnit
(
double
desired_period_sec
=
-
1
);
void
startProfiling
();
void
stopProfiling
();
void
printProfiling
(
std
::
ostream
&
stream
=
std
::
cout
)
const
;
std
::
stringstream
printDuration
(
double
_duration_ms
,
int
precision
=
2
)
const
;
};
ProfilingUnit
::
ProfilingUnit
(
desired_period_sec
)
:
desired_period_
(
1e6
*
desired_period_sec
),
n_callbacks_
(
0
),
average_period_
(
0
),
acc_duration_
(
0
),
max_duration_
(
0
),
var_duration_
(
0
)
{
}
inline
void
ProfilingUnit
::
startCaptureProfiling
()
{
start_
=
std
::
chrono
::
high_resolution_clock
::
now
();
n_callback_
++
;
if
(
n_callback_
==
1
)
first_clock_
=
start_
;
else
{
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
start_
-
first_clock_
);
average_period_
=
duration
.
count
()
/
(
n_callback_
-
1
);
}
}
inline
void
ProfilingUnit
::
stopCaptureProfiling
()
{
auto
prev_mean_duration
=
n_callback_
<
2
?
0
:
acc_duration_
.
count
()
/
(
n_callback_
-
1
);
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
start_
);
max_duration_
=
std
::
max
(
max_duration_
,
duration
);
acc_duration_
+=
duration
;
var_duration_
=
n_callback_
<
2
?
0
:
((
n_callback_
-
2
)
*
var_duration_
+
(
duration
.
count
()
-
prev_mean_duration
)
*
(
duration
.
count
()
-
acc_duration_
.
count
()
/
n_callback_
))
/
(
n_callback_
-
1
);
}
inline
std
::
stringstream
ProfilingUnit
::
printDuration
(
double
_duration_microsec
,
int
precision
)
const
{
std
::
stringstream
stream
;
if
(
_duration_microsec
>
1e6
)
stream
<<
std
::
fixed
<<
std
::
setprecision
(
precision
)
<<
1e-6
*
_duration_microsec
<<
" s"
;
else
if
(
_duration_microsec
>
1e3
)
stream
<<
std
::
fixed
<<
std
::
setprecision
(
precision
)
<<
1e-3
*
_duration_microsec
<<
" ms"
;
else
stream
<<
std
::
fixed
<<
std
::
setprecision
(
precision
)
<<
_duration_microsec
<<
" us"
;
return
stream
;
}
inline
void
ProcessorBase
::
printProfiling
(
std
::
ostream
&
_stream
)
const
{
auto
ref_period
=
desired_period_
>
0
?
desired_period_
:
average_period_
;
unsigned
int
average_percent
=
(
n_callbacks_
>
0
)
?
std
::
round
(
100
*
acc_duration_
.
count
()
/
n_callbacks_
/
ref_period
)
:
0
;
unsigned
int
max_percent
=
(
n_callbacks_
>
0
)
?
std
::
round
(
100
*
max_duration_
.
count
()
/
ref_period
)
:
0
;
unsigned
int
stdev_percent
=
(
n_callbacks_
>
0
)
?
std
::
round
(
100
*
sqrt
(
var_duration_
)
/
ref_period
)
:
0
;
_stream
<<
"
\n\t\t
instances: "
<<
n_callbacks_
//
<<
"
\n\t\t
average period: "
<<
printDuration
(
average_period_
)
//
<<
"
\n\t\t
total time: "
<<
printDuration
(
acc_duration_
.
count
())
//
<<
"
\n\t\t
avg time: "
<<
printDuration
(
acc_duration_
.
count
()
/
n_callbacks_
)
//
<<
" ("
<<
average_percent
<<
"%)"
//
<<
"
\n\t\t
stdev time: "
<<
printDuration
(
sqrt
(
var_duration_
))
//
<<
" ("
<<
stdev_percent
<<
"%)"
//
<<
"
\n\t\t
max time: "
<<
printDuration
(
max_duration_
.
count
())
//
<<
" ("
<<
max_percent
<<
"%)"
//
}
}
// namespace wolf
This diff is collapsed.
Click to expand it.
include/core/processor/processor_base.h
+
14
−
0
View file @
e1bd1f1e
...
...
@@ -138,6 +138,8 @@ class ProcessorBase : public NodeBase, public std::enable_shared_from_this<Proce
std
::
chrono
::
microseconds
acc_duration_kf_
;
std
::
chrono
::
microseconds
max_duration_capture_
;
std
::
chrono
::
microseconds
max_duration_kf_
;
double
var_duration_capture_
;
double
var_duration_kf_
;
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
>
start_capture_
;
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
>
start_kf_
;
void
startCaptureProfiling
();
...
...
@@ -289,11 +291,17 @@ inline void ProcessorBase::startCaptureProfiling()
inline
void
ProcessorBase
::
stopCaptureProfiling
()
{
//auto prev_mean_duration_capture = n_capture_callback_ < 2 ? 0 : acc_duration_capture_.count() / (n_capture_callback_ - 1);
auto
duration_capture
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
start_capture_
);
max_duration_capture_
=
std
::
max
(
max_duration_capture_
,
duration_capture
);
acc_duration_capture_
+=
duration_capture
;
// var_duration_capture_ = n_capture_callback_ < 2 ? 0 : ((n_capture_callback_ - 2) * var_duration_capture_ +
// (duration_capture.count() - prev_mean_duration_capture) *
// (duration_capture.count() - acc_duration_capture_.count() / n_capture_callback_)) /
// (n_capture_callback_ - 1);
}
inline
void
ProcessorBase
::
startKFProfiling
()
...
...
@@ -303,11 +311,17 @@ inline void ProcessorBase::startKFProfiling()
inline
void
ProcessorBase
::
stopKFProfiling
()
{
//auto prev_mean_duration_kf = n_kf_callback_ < 2 ? 0 : acc_duration_kf_.count() / (n_kf_callback_ - 1) ;
auto
duration_kf
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
start_kf_
);
max_duration_kf_
=
std
::
max
(
max_duration_kf_
,
duration_kf
);
acc_duration_kf_
+=
duration_kf
;
// var_duration_kf_ = n_kf_callback_ < 2 ? 0 : ((n_kf_callback_ - 2) * var_duration_kf_ +
// (duration_kf.count() - prev_mean_duration_kf) *
// (duration_kf.count() - acc_duration_kf_.count() / n_kf_callback_)) /
// (n_kf_callback_ - 1);
}
inline
YAML
::
Node
ProcessorBase
::
getParams
()
const
...
...
This diff is collapsed.
Click to expand it.
src/processor/processor_base.cpp
+
19
−
7
View file @
e1bd1f1e
...
...
@@ -42,7 +42,9 @@ ProcessorBase::ProcessorBase(const std::string& _type, unsigned int _dim_compati
acc_duration_capture_
(
0
),
acc_duration_kf_
(
0
),
max_duration_capture_
(
0
),
max_duration_kf_
(
0
)
max_duration_kf_
(
0
),
var_duration_capture_
(
0
),
var_duration_kf_
(
0
)
{
assert
(
dim_compatible_
==
0
or
dim_compatible_
==
2
or
dim_compatible_
==
3
);
WOLF_DEBUG
(
"Constructed ProcessorBase - "
,
getType
(),
" id: "
,
id
(),
" name: "
,
getName
());
...
...
@@ -244,32 +246,42 @@ void ProcessorBase::printProfiling(std::ostream& _stream) const
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
capture_period_mean_
*
n_capture_callback_
/
n_kf_callback_
)
:
0
;
unsigned
int
average_proc_cap_percent
=
(
n_capture_callback_
>
0
)
?
std
::
round
(
100
*
acc_duration_capture_
.
count
()
/
n_capture_callback_
/
capture_period_mean_
)
?
std
::
round
(
100
*
1e-6
*
acc_duration_capture_
.
count
()
/
n_capture_callback_
/
capture_period_mean_
)
:
0
;
unsigned
int
max_proc_cap_percent
=
(
n_capture_callback_
>
0
)
?
std
::
round
(
100
*
max_duration_capture_
.
count
()
/
capture_period_min_
)
:
0
;
(
n_capture_callback_
>
0
)
?
std
::
round
(
100
*
1e-6
*
max_duration_capture_
.
count
()
/
capture_period_min_
)
:
0
;
unsigned
int
stdev_proc_cap_percent
=
(
n_capture_callback_
>
0
)
?
std
::
round
(
100
*
1e-6
*
sqrt
(
var_duration_capture_
)
/
capture_period_mean_
)
:
0
;
unsigned
int
average_proc_kf_percent
=
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
acc_duration_kf_
.
count
()
/
n_kf_callback_
/
kf_average_period
)
:
0
;
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
1e-6
*
acc_duration_kf_
.
count
()
/
n_kf_callback_
/
kf_average_period
)
:
0
;
unsigned
int
max_proc_kf_percent
=
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
max_duration_kf_
.
count
()
/
kf_average_period
)
:
0
;
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
1e-6
*
max_duration_kf_
.
count
()
/
kf_average_period
)
:
0
;
unsigned
int
std_dev_proc_kf_percent
=
(
n_kf_callback_
>
0
)
?
std
::
round
(
100
*
1e-6
*
sqrt
(
var_duration_kf_
)
/
kf_average_period
)
:
0
;
_stream
<<
"
\n
"
<<
getType
()
<<
" - "
<<
getName
()
<<
":"
<<
"
\n\t
total proc. time: "
<<
1e-6
*
(
acc_duration_capture_
+
acc_duration_kf_
).
count
()
<<
" s"
<<
"
\n\t
Processing captures:"
<<
"
\n\t\t
captures processed: "
<<
n_capture_callback_
<<
"
\n\t\t
average period: "
<<
1e
-
3
*
capture_period_mean_
<<
" ms"
<<
"
\n\t\t
average period: "
<<
1e3
*
capture_period_mean_
<<
" ms"
<<
"
\n\t\t
total proc. time: "
<<
1e-6
*
acc_duration_capture_
.
count
()
<<
" s"
<<
"
\n\t\t
average proc. time: "
<<
1e-3
*
acc_duration_capture_
.
count
()
/
n_capture_callback_
<<
" ms"
<<
" ("
<<
average_proc_cap_percent
<<
"%)"
<<
"
\n\t\t
std dev proc. time: "
<<
1e-3
*
sqrt
(
var_duration_capture_
)
<<
" ms"
<<
" ("
<<
stdev_proc_cap_percent
<<
"%)"
<<
"
\n\t\t
max proc. time: "
<<
1e-3
*
max_duration_capture_
.
count
()
<<
" ms"
<<
" ("
<<
max_proc_cap_percent
<<
"%)"
<<
"
\n\t
Processing keyframes:"
<<
"
\n\t\t
kf processed: "
<<
n_kf_callback_
<<
"
\n\t\t
average period: "
<<
1e-3
*
kf_average_period
<<
"
m
s"
<<
"
\n\t\t
average period: "
<<
kf_average_period
<<
" s"
<<
"
\n\t\t
total proc. time: "
<<
1e-6
*
acc_duration_kf_
.
count
()
<<
" s"
<<
"
\n\t\t
average proc. time: "
<<
1e-3
*
acc_duration_kf_
.
count
()
/
n_kf_callback_
<<
" ms"
<<
" ("
<<
average_proc_kf_percent
<<
"%)"
<<
"
\n\t\t
std dev proc. time: "
<<
1e-3
*
sqrt
(
var_duration_kf_
)
<<
" ms"
<<
" ("
<<
std_dev_proc_kf_percent
<<
"%)"
<<
"
\n\t\t
max proc. time: "
<<
1e-3
*
max_duration_kf_
.
count
()
<<
" ms"
<<
" ("
<<
max_proc_kf_percent
<<
"%)"
<<
std
::
endl
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment