mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::json: Add stats items counting calls and cycles on input and output.
This commit is contained in:
parent
c99ae124f4
commit
d456a42cdd
2 changed files with 17 additions and 0 deletions
|
@ -35,8 +35,18 @@ namespace ircd::json
|
|||
bool valid(const string_view &, std::nothrow_t) noexcept;
|
||||
void valid(const string_view &);
|
||||
std::string why(const string_view &);
|
||||
|
||||
struct stats extern stats;
|
||||
}
|
||||
|
||||
/// Statistics counter access; unfortunately these cannot participate as
|
||||
/// ircd::stats items right now.
|
||||
struct ircd::json::stats
|
||||
{
|
||||
uint64_t print_calls {0}, print_cycles {0};
|
||||
uint64_t parse_calls {0}, parse_cycles {0};
|
||||
};
|
||||
|
||||
/// Alternative to `json::strung` which uses a fixed array rather than an
|
||||
/// allocated string as the target.
|
||||
template<size_t SIZE>
|
||||
|
|
|
@ -19,6 +19,9 @@ namespace ircd::json
|
|||
}
|
||||
#pragma GCC visibility pop
|
||||
|
||||
decltype(ircd::json::stats)
|
||||
ircd::json::stats;
|
||||
|
||||
#pragma GCC visibility push(internal)
|
||||
BOOST_FUSION_ADAPT_STRUCT
|
||||
(
|
||||
|
@ -489,6 +492,8 @@ ircd::json::printer::operator()(mutable_buffer &out,
|
|||
attr&&... a)
|
||||
const
|
||||
{
|
||||
++stats.print_calls;
|
||||
const prof::scope_cycles timer{stats.print_cycles};
|
||||
if(unlikely(!ircd::generate(out, std::forward<gen>(g), std::forward<attr>(a)...)))
|
||||
throw print_error
|
||||
{
|
||||
|
@ -542,6 +547,8 @@ ircd::json::parser::operator()(const char *&start,
|
|||
attr&&...a)
|
||||
const
|
||||
{
|
||||
++stats.parse_calls;
|
||||
const prof::scope_cycles timer{stats.parse_cycles};
|
||||
return ircd::parse<parse_error>(start, stop, std::forward<gen>(g), std::forward<attr>(a)...);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue