1#ifndef LIBTEDDY_DETAILS_STATS_HPP
2#define LIBTEDDY_DETAILS_STATS_HPP
4#include <libteddy/details/config.hpp>
5#ifdef LIBTEDDY_COLLECT_STATS
7# include <libteddy/details/types.hpp>
16 struct query_frequency
19 int64 totalCount_ {0};
22 struct operation_duration
24 std::chrono::time_point<std::chrono::high_resolution_clock> start_;
25 std::chrono::nanoseconds total_ {std::chrono::nanoseconds::zero()};
28 int64 applyStepCalls_ {0};
29 int64 maxUniqueNodes_ {0};
30 int64 maxAllocatedNodes_ {0};
31 query_frequency uniqueTableQueries_;
32 query_frequency applyCacheQueries_;
33 operation_duration collectGarbage_;
34 operation_duration makeNode_;
37inline auto get_stats () -> teddy_stats&
39 static teddy_stats instance;
43inline auto tick (teddy_stats::operation_duration& stat) ->
void
45 stat.start_ = std::chrono::high_resolution_clock::now();
48inline auto tock (teddy_stats::operation_duration& stat) ->
void
50 stat.total_ += std::chrono::duration_cast<std::chrono::nanoseconds>(
51 std::chrono::high_resolution_clock::now() - stat.start_
58inline auto dump_stats () ->
void
60 auto& stats = stats::get_stats();
61 std::cout <<
"Unique table"
63 <<
" hit = " << stats.uniqueTableQueries_.hitCount_ <<
"\n"
64 <<
" total = " << stats.uniqueTableQueries_.totalCount_ <<
"\n"
67 <<
" hit = " << stats.applyCacheQueries_.hitCount_ <<
"\n"
68 <<
" total = " << stats.applyCacheQueries_.totalCount_ <<
"\n"
71 <<
" total = " << stats.collectGarbage_.total_.count() <<
"ns\n"
74 <<
" total = " << stats.makeNode_.total_.count() <<
"ns\n"
77 <<
" calls = " << stats.applyStepCalls_ <<
"\n";