16 #include <boost/algorithm/string.hpp>
19 #include <fmt/format.h>
23 #include <string_view>
39 {
"counter",
"{0:nEntries|10d}" },
40 {
"histogram",
"{0:nEntries|10d}" },
41 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
42 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
43 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
44 "|{0:min|#12.5g} |{0:max|#12.5g}" },
45 {
"counter:BinomialCounter",
46 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
67 class fmt::formatter<json_fmt_arg> {
69 template <
typename ParseContext>
71 auto fmt_begin =
ctx.begin();
73 if ( fmt_begin == fmt_end ) {
78 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
79 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
80 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
84 template <
typename FormatContext>
85 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx ) {
86 const auto& j = json_arg.payload;
87 if ( currentFormat.size() == 0 ) {
91 std::string_view type_key{
type };
93 auto entry =
registry.find( type_key );
95 auto sep = type_key.rfind(
':' );
96 while ( sep != type_key.npos && entry ==
registry.end() ) {
98 type_key.remove_suffix( type_key.size() - sep );
100 sep = type_key.rfind(
':' );
109 return fmt::format_to(
ctx.out(), entry->second, json_arg );
112 auto actualFormat =
fmt::format(
"{{:{}", currentFormat ) +
"}";
113 switch ( currentFormat.back() ) {
115 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<unsigned int>() );
117 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<double>() );
119 actualFormat[actualFormat.size() - 2] =
'g';
120 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<double>() * 100 );
122 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
134 template <
typename stream>
139 if (
type ==
"statentity" ) {
140 using boost::algorithm::icontains;
141 bool isBinomial = icontains(
id,
"eff" ) || icontains(
id,
"acc" ) || icontains(
id,
"filt" ) ||
142 icontains(
id,
"fltr" ) || icontains(
id,
"pass" );
144 nj[
"type"] = isBinomial ?
"counter:BinomialCounter" :
"counter:StatCounter";
145 return printCounter(
log,
id, nj );
149 ( std::string_view{
type }.substr( 0, 23 ) ==
"counter:BinomialCounter" ?
'*' :
' ' ),
175 if ( std::string_view( ent.
type ).substr( 0, 8 ) ==
"counter:" || ent.
type ==
"statentity" ||
176 ent.
type ==
"histogram" ) {
202 for (
auto& entity :
m_monitoringEntities ) { sortedEntities[entity.component][entity.name] = entity.toJSON(); }
204 for (
auto& [algoName, entityMap] : sortedEntities ) {
206 unsigned int nbCounters =
208 return a + ( j.second.at(
"empty" ).
template get<bool>() ? 0 : 1 );
210 if ( 0 == nbCounters )
continue;
212 log <<
MSG::INFO <<
"Number of counters : " << nbCounters <<
"\n"
213 <<
" | Counter | # | "
214 <<
" sum | mean/eff^* | rms/err^* | min | max |";
217 if ( !p.second.at(
"empty" ).template get<bool>() ) {
219 printCounter( log, p.first, p.second );