4747using namespace std ::string_view_literals;
4848
4949/* ************************** ADD STAT CALLBACKS ***************************/
50-
51- // Generic add_stat<T>. Uses std::to_string which requires heap allocation.
52- template <typename T>
53- void add_stat (Cookie& cookie,
54- const AddStatFn& add_stat_callback,
55- const char * name,
56- const T& val) {
57- add_stat_callback (name, std::to_string (val), &cookie);
58- }
59-
60- void add_stat (Cookie& cookie,
61- const AddStatFn& add_stat_callback,
62- const char * name,
63- const std::string& value) {
64- add_stat_callback (name, value, cookie);
65- }
66-
67- void add_stat (Cookie& cookie,
68- const AddStatFn& add_stat_callback,
69- const char * name,
70- const char * value) {
50+ static void add_stat (Cookie& cookie,
51+ const AddStatFn& add_stat_callback,
52+ std::string_view name,
53+ std::string_view value) {
7154 add_stat_callback (name, value, cookie);
7255}
7356
74- void add_stat (Cookie& cookie,
75- const AddStatFn& add_stat_callback,
76- const char * name,
77- const bool value) {
78- if (value) {
79- add_stat (cookie, add_stat_callback, name, " true" );
80- } else {
81- add_stat (cookie, add_stat_callback, name, " false" );
82- }
83- }
84-
8557static void append_stats (std::string_view key,
8658 std::string_view value,
8759 Cookie& cookie) {
@@ -658,7 +630,7 @@ static cb::engine_errc stat_runtimes_executor(const std::string& arg,
658630 .isEmpty ()) {
659631 add_stat (cookie,
660632 appendStatsFn,
661- GlobalTask::getTaskIdString (id). c_str () ,
633+ GlobalTask::getTaskIdString (id),
662634 stats.taskRuntimeHistogram [static_cast <int >(id)]
663635 .to_string ());
664636 }
@@ -683,7 +655,7 @@ static cb::engine_errc stat_scheduler_executor(const std::string& arg,
683655 .isEmpty ()) {
684656 add_stat (cookie,
685657 appendStatsFn,
686- GlobalTask::getTaskIdString (id). c_str () ,
658+ GlobalTask::getTaskIdString (id),
687659 stats.taskSchedulingHistogram [static_cast <int >(id)]
688660 .to_string ());
689661 }
0 commit comments