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
9f6f11bf
Commit
9f6f11bf
authored
Jun 18, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optionally allow operator++ on counters
parent
4dc03681
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
libcaf_core/caf/telemetry/counter.hpp
libcaf_core/caf/telemetry/counter.hpp
+13
-0
libcaf_core/test/telemetry/counter.cpp
libcaf_core/test/telemetry/counter.cpp
+12
-10
No files found.
libcaf_core/caf/telemetry/counter.hpp
View file @
9f6f11bf
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#pragma once
#pragma once
#include <type_traits>
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/telemetry/gauge.hpp"
#include "caf/telemetry/gauge.hpp"
...
@@ -48,6 +50,10 @@ public:
...
@@ -48,6 +50,10 @@ public:
// nop
// nop
}
}
explicit
counter
(
const
std
::
vector
<
label
>&
)
noexcept
{
// nop
}
// -- modifiers --------------------------------------------------------------
// -- modifiers --------------------------------------------------------------
/// Increments the counter by 1.
/// Increments the counter by 1.
...
@@ -62,6 +68,13 @@ public:
...
@@ -62,6 +68,13 @@ public:
gauge_
.
inc
(
amount
);
gauge_
.
inc
(
amount
);
}
}
/// Increments the counter by 1.
/// @returns The new value of the counter.
template
<
class
T
=
ValueType
>
std
::
enable_if_t
<
std
::
is_same
<
T
,
int64_t
>::
value
,
T
>
operator
++
()
noexcept
{
return
++
gauge_
;
}
// -- observers --------------------------------------------------------------
// -- observers --------------------------------------------------------------
/// Returns the current value of the counter.
/// Returns the current value of the counter.
...
...
libcaf_core/test/telemetry/counter.cpp
View file @
9f6f11bf
...
@@ -25,25 +25,27 @@
...
@@ -25,25 +25,27 @@
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
double
counters
can
only
increment
)
{
CAF_TEST
(
double
counters
can
only
increment
)
{
telemetry
::
dbl_counter
g
;
telemetry
::
dbl_counter
c
;
CAF_MESSAGE
(
"counters start at 0"
);
CAF_MESSAGE
(
"counters start at 0"
);
CAF_CHECK_EQUAL
(
g
.
value
(),
0.0
);
CAF_CHECK_EQUAL
(
c
.
value
(),
0.0
);
CAF_MESSAGE
(
"counters are incrementable"
);
CAF_MESSAGE
(
"counters are incrementable"
);
g
.
inc
();
c
.
inc
();
g
.
inc
(
2.0
);
c
.
inc
(
2.0
);
CAF_CHECK_EQUAL
(
g
.
value
(),
3.0
);
CAF_CHECK_EQUAL
(
c
.
value
(),
3.0
);
CAF_MESSAGE
(
"users can create counters with custom start values"
);
CAF_MESSAGE
(
"users can create counters with custom start values"
);
CAF_CHECK_EQUAL
(
telemetry
::
dbl_counter
{
42.0
}.
value
(),
42.0
);
CAF_CHECK_EQUAL
(
telemetry
::
dbl_counter
{
42.0
}.
value
(),
42.0
);
}
}
CAF_TEST
(
integer
counters
can
only
increment
)
{
CAF_TEST
(
integer
counters
can
only
increment
)
{
telemetry
::
int_counter
g
;
telemetry
::
int_counter
c
;
CAF_MESSAGE
(
"counters start at 0"
);
CAF_MESSAGE
(
"counters start at 0"
);
CAF_CHECK_EQUAL
(
g
.
value
(),
0
);
CAF_CHECK_EQUAL
(
c
.
value
(),
0
);
CAF_MESSAGE
(
"counters are incrementable"
);
CAF_MESSAGE
(
"counters are incrementable"
);
g
.
inc
();
c
.
inc
();
g
.
inc
(
2
);
c
.
inc
(
2
);
CAF_CHECK_EQUAL
(
g
.
value
(),
3
);
CAF_CHECK_EQUAL
(
c
.
value
(),
3
);
CAF_MESSAGE
(
"integer counters also support operator++"
);
CAF_CHECK_EQUAL
(
++
c
,
4
);
CAF_MESSAGE
(
"users can create counters with custom start values"
);
CAF_MESSAGE
(
"users can create counters with custom start values"
);
CAF_CHECK_EQUAL
(
telemetry
::
int_counter
{
42
}.
value
(),
42
);
CAF_CHECK_EQUAL
(
telemetry
::
int_counter
{
42
}.
value
(),
42
);
}
}
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