Skip to content

Commit faaa028

Browse files
committed
Extention of activity_stats_t.
New field m_current_activity_time added to activity_stats_t.
1 parent 586f913 commit faaa028

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dev/so_5/stats/work_thread_activity.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cstdint>
1515
#include <chrono>
1616
#include <iostream>
17+
#include <optional>
1718
#include <type_traits>
1819

1920
namespace so_5
@@ -58,6 +59,14 @@ struct activity_stats_t
5859

5960
//! Average time for one event.
6061
duration_t m_avg_time{};
62+
63+
//! Duration of the current activity.
64+
//!
65+
//! This value is defined only if the current activity is present.
66+
//! Otherwise it will be nullopt.
67+
//!
68+
//! \since v.5.8.5
69+
std::optional< duration_t > m_current_activity_time;
6170
};
6271

6372
/*!
@@ -75,7 +84,10 @@ operator<<( std::ostream & to, const activity_stats_t & what )
7584

7685
to << "[count=" << what.m_count
7786
<< ";total=" << to_ms(what.m_total_time)
78-
<< "ms;avg=" << to_ms(what.m_avg_time) << "ms]";
87+
<< "ms;avg=" << to_ms(what.m_avg_time) << "ms";
88+
if( what.m_current_activity_time )
89+
to << ";current=" << to_ms(*what.m_current_activity_time) << "ms";
90+
to << ']';
7991

8092
return to;
8193
}
@@ -150,9 +162,12 @@ update_stats_from_current_time(
150162
activity_stats_t & value_to_update,
151163
clock_type_t::time_point activity_started_at )
152164
{
165+
const auto current_activity_time =
166+
clock_type_t::now() - activity_started_at;
167+
value_to_update.m_current_activity_time = current_activity_time;
153168
update_stats_from_duration(
154169
value_to_update,
155-
clock_type_t::now() - activity_started_at );
170+
current_activity_time );
156171
}
157172

158173
} /* namespace details */

0 commit comments

Comments
 (0)