Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
3a29305f
Commit
3a29305f
authored
Jun 17, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convenience type for measuring times
parent
b7f4a3f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
0 deletions
+104
-0
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/fwd.hpp
libcaf_core/caf/fwd.hpp
+1
-0
libcaf_core/caf/telemetry/timer.hpp
libcaf_core/caf/telemetry/timer.hpp
+60
-0
libcaf_core/test/telemetry/timer.cpp
libcaf_core/test/telemetry/timer.cpp
+42
-0
No files found.
libcaf_core/CMakeLists.txt
View file @
3a29305f
...
@@ -313,6 +313,7 @@ caf_add_test_suites(caf-core-test
...
@@ -313,6 +313,7 @@ caf_add_test_suites(caf-core-test
telemetry.histogram
telemetry.histogram
telemetry.label
telemetry.label
telemetry.metric_registry
telemetry.metric_registry
telemetry.timer
thread_hook
thread_hook
tracing_data
tracing_data
type_id_list
type_id_list
...
...
libcaf_core/caf/fwd.hpp
View file @
3a29305f
...
@@ -241,6 +241,7 @@ class label_view;
...
@@ -241,6 +241,7 @@ class label_view;
class
metric
;
class
metric
;
class
metric_family
;
class
metric_family
;
class
metric_registry
;
class
metric_registry
;
class
timer
;
enum
class
metric_type
:
uint8_t
;
enum
class
metric_type
:
uint8_t
;
...
...
libcaf_core/caf/telemetry/timer.hpp
0 → 100644
View file @
3a29305f
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2020 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <chrono>
#include "caf/telemetry/histogram.hpp"
namespace
caf
::
telemetry
{
/// Convenience helper for measuring durations such as latency using a histogram
/// with second resolution. The measurement starts when creating the objects and
/// finishes when the timer goes out of scope.
class
timer
{
public:
using
clock_type
=
std
::
chrono
::
steady_clock
;
explicit
timer
(
dbl_histogram
*
h
)
:
h_
(
h
)
{
if
(
h
)
start_
=
clock_type
::
now
();
}
~
timer
()
{
using
dbl_sec
=
std
::
chrono
::
duration
<
double
>
;
if
(
h_
)
{
auto
end
=
clock_type
::
now
();
h_
->
observe
(
std
::
chrono
::
duration_cast
<
dbl_sec
>
(
end
-
start_
).
count
());
}
}
auto
histogram_ptr
()
const
noexcept
{
return
h_
;
}
auto
started
()
const
noexcept
{
return
start_
;
}
private:
dbl_histogram
*
h_
;
clock_type
::
time_point
start_
;
};
}
// namespace caf::telemetry
libcaf_core/test/telemetry/timer.cpp
0 → 100644
View file @
3a29305f
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2020 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE telemetry.timer
#include "caf/telemetry/timer.hpp"
#include "caf/test/dsl.hpp"
using
namespace
caf
;
using
namespace
caf
::
telemetry
;
CAF_TEST
(
timers
observe
how
much
time
passes
in
a
scope
)
{
dbl_histogram
h1
{
1
,
2
,
4
,
8
};
CAF_MESSAGE
(
"timers call observe() with the measured time"
);
{
timer
t
{
&
h1
};
CAF_CHECK_EQUAL
(
t
.
histogram_ptr
(),
&
h1
);
CAF_CHECK_GREATER
(
t
.
started
().
time_since_epoch
().
count
(),
0
);
}
CAF_CHECK_GREATER
(
h1
.
sum
(),
0.0
);
CAF_MESSAGE
(
"timers constructed with a nullptr have no effect"
);
{
timer
t
{
nullptr
};
CAF_CHECK_EQUAL
(
t
.
histogram_ptr
(),
nullptr
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment