29 #include <type_traits> 152 statset *create_statset (
void)
const;
184 template <
typename Duration>
185 void get_stat_values_with_converted_timers (
const statset &statsetr,
stat_value *output_stats)
const;
186 template <
typename Duration>
189 template <
typename Duration>
190 void add_stat_values_with_converted_timers (
const statset &statsetr,
stat_value *output_stats)
const;
191 template <
typename Duration>
195 std::size_t get_stat_count ()
const;
197 const char *get_value_name (std::size_t value_index)
const;
198 std::size_t get_values_memsize (
void)
const;
204 template <
bool IsAtomic>
206 template <
bool IsAtomic>
208 template <
bool IsAtomic>
210 template <
bool IsAtomic>
213 template <
bool IsAtomic>
218 template <
typename Duration>
221 template <
bool IsAtomic,
typename Duration>
225 template <
bool IsAtomic,
typename Duration>
249 template <
bool IsAtomic>
253 assert (
id < get_stat_count ());
254 assert (m_stat_defs[
id].
m_type == stat_definition::type::COUNTER);
257 statsetr.
m_values[m_stat_defs[
id].m_offset] += incr;
263 generic_increment<false> (statsetr,
id, incr);
269 generic_increment<true> (statsetr,
id, incr);
272 template <
bool IsAtomic>
276 assert (
id < get_stat_count ());
277 assert (m_stat_defs[
id].
m_type == stat_definition::type::TIMER);
280 statsetr.
m_values[m_stat_defs[
id].m_offset] += d.count ();
283 template <
bool IsAtomic>
288 generic_time (statsetr,
id, nowpt - statsetr.
m_timept);
295 generic_time<false> (statsetr,
id, d);
301 generic_time<false> (statsetr,
id);
307 generic_time<true> (statsetr,
id, d);
313 generic_time<true> (statsetr,
id);
316 template <
bool IsAtomic>
321 assert (
id < get_stat_count ());
322 assert (m_stat_defs[
id].
m_type == stat_definition::type::COUNTER_AND_TIMER);
325 std::size_t offset = m_stat_defs[
id].m_offset;
327 statsetr.
m_values[offset + 1] += d.count ();
330 template <
bool IsAtomic>
335 generic_time_and_increment (statsetr,
id, incr, nowpt - statsetr.
m_timept);
342 generic_time_and_increment<false> (statsetr,
id, incr, d);
348 generic_time_and_increment<false> (statsetr,
id, incr);
355 generic_time_and_increment<true> (statsetr,
id, incr, d);
361 generic_time_and_increment<true> (statsetr,
id, incr);
364 template <
typename Duration>
368 duration default_duration (default_duration_count);
369 Duration desired_duration = std::chrono::duration_cast<Duration> (default_duration);
370 return desired_duration.count ();
373 template <
bool IsAtomic,
typename Duration>
378 std::size_t offset = 0;
379 for (
stat_id id = 0;
id < get_stat_count ();
id++)
381 offset = m_stat_defs[
id].m_offset;
382 switch (m_stat_defs[
id].
m_type)
385 output_stats[offset] = statsetr.
m_values[offset];
388 output_stats[offset] = convert_timeval<Duration> (statsetr.
m_values[offset]);
391 output_stats[offset] = statsetr.
m_values[offset];
392 output_stats[offset + 1] = convert_timeval<Duration> (statsetr.
m_values[offset + 1]);
401 template <
typename Duration>
405 return generic_get_stat_values_with_converted_timers<false, Duration> (statsetr, output_stats);
408 template <
typename Duration>
413 return generic_get_stat_values_with_converted_timers<true, Duration> (statsetr, output_stats);
416 template <
bool IsAtomic,
typename Duration>
421 std::size_t offset = 0;
422 for (
stat_id id = 0;
id < get_stat_count ();
id++)
424 offset = m_stat_defs[
id].m_offset;
425 switch (m_stat_defs[
id].
m_type)
428 output_stats[offset] += statsetr.
m_values[offset];
431 output_stats[offset] += convert_timeval<Duration> (statsetr.
m_values[offset]);
434 output_stats[offset] += statsetr.
m_values[offset];
435 output_stats[offset + 1] += convert_timeval<Duration> (statsetr.
m_values[offset + 1]);
444 template <
typename Duration>
448 return generic_add_stat_values_with_converted_timers<false, Duration> (statsetr, output_stats);
451 template <
typename Duration>
456 return generic_add_stat_values_with_converted_timers<true, Duration> (statsetr, output_stats);
463 template<
bool IsAtomic>
465 : m_value_count (value_count)
467 , m_timept (
clock::now ())
472 template<
bool IsAtomic>
482 template<
bool IsAtomic>
490 template<
bool IsAtomic>
497 template<
bool IsAtomic>
504 template<
bool IsAtomic>
515 template<
bool IsAtomic>
519 , m_timept (
clock::now ())
524 template<
bool IsAtomic>
531 template<
bool IsAtomic>
540 template<
bool IsAtomic>
547 template<
bool IsAtomic>
558 template<
bool IsAtomic>
560 const char *stat_timer_name)
561 : m_stat_counter (stat_counter_name)
562 , m_stat_timer (stat_timer_name)
567 template<
bool IsAtomic>
574 template<
bool IsAtomic>
582 template<
bool IsAtomic>
590 template<
bool IsAtomic>
597 template<
bool IsAtomic>
604 template<
bool IsAtomic>
611 template<
bool IsAtomic>
625 timept = clock::now ();
generic_value< IsAtomic > m_stat_value
void increment(statset &statsetr, stat_id id, stat_value incr=1) const
void generic_time(generic_statset< IsAtomic > &statsetr, stat_id id, duration d) const
stat_value get_count(void)
void time_and_increment(statset &statsetr, stat_id id, duration d, stat_value incr=1) const
generic_stat_counter_and_timer(void)
generic_value< false > stat_value
typename std::conditional< IsAtomic, std::atomic< std::uint64_t >, std::uint64_t >::type generic_value
stat_definition * m_stat_defs
std::size_t m_value_count
static const std::size_t MAX_VALUE_COUNT
stat_definition & operator=(const stat_definition &other)
void get_stat_values_with_converted_timers(const statset &statsetr, stat_value *output_stats) const
std::string * m_value_names
void generic_add_stat_values_with_converted_timers(const generic_statset< IsAtomic > &statsetr, stat_value *output_stats) const
void generic_get_stat_values_with_converted_timers(const generic_statset< IsAtomic > &statsetr, stat_value *output_stats) const
const char * get_count_name(void)
void time_and_increment(duration d, stat_value incr=1)
void generic_time_and_increment(generic_statset< IsAtomic > &statsetr, stat_id id, stat_value incr, duration d) const
stat_value get_time(void)
generic_statset(void)=delete
std::size_t get_value_count(void) const
clock::time_point time_point
std::chrono::high_resolution_clock clock
void add_stat_values_with_converted_timers(const statset &statsetr, stat_value *output_stats) const
void time(statset &statsetr, stat_id id, duration d) const
const char * get_name(void)
generic_stat_counter(const char *name=NULL)
stat_value get_count(void)
friend class statset_definition
generic_stat_timer(const char *name=NULL)
generic_value< IsAtomic > * m_values
generic_stat_timer< IsAtomic > m_stat_timer
void generic_increment(generic_statset< IsAtomic > &statsetr, stat_id id, stat_value incr) const
const char * get_name(void)
stat_value convert_timeval(stat_value nanosecs) const
generic_stat_counter< IsAtomic > m_stat_counter
generic_value< IsAtomic > m_stat_value
void increment(stat_value incr=1)
const char * m_names[MAX_VALUE_COUNT]
const char * get_time_name(void)
void reset_timept(time_point &timept)
stat_value get_time(void)