mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::stats: Add buffer-based stringifier to interface; simplify.
This commit is contained in:
parent
1ff8217682
commit
4b20747e06
2 changed files with 27 additions and 5 deletions
|
@ -56,6 +56,7 @@ namespace ircd::stats
|
||||||
extern const size_t NAME_MAX_LEN;
|
extern const size_t NAME_MAX_LEN;
|
||||||
extern std::map<string_view, item<void> *> items;
|
extern std::map<string_view, item<void> *> items;
|
||||||
|
|
||||||
|
string_view string(const mutable_buffer &, const item<void> &);
|
||||||
std::ostream &operator<<(std::ostream &, const item<void> &);
|
std::ostream &operator<<(std::ostream &, const item<void> &);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,15 @@ ircd::stats::items
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::stats::operator<<(std::ostream &s,
|
ircd::stats::operator<<(std::ostream &s,
|
||||||
const item<void> &item_)
|
const item<void> &item_)
|
||||||
|
{
|
||||||
|
thread_local char tmp[256];
|
||||||
|
s << string(tmp, item_);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::string_view
|
||||||
|
ircd::stats::string(const mutable_buffer &buf,
|
||||||
|
const item<void> &item_)
|
||||||
{
|
{
|
||||||
if(item_.type == typeid(uint64_t *))
|
if(item_.type == typeid(uint64_t *))
|
||||||
{
|
{
|
||||||
|
@ -30,7 +39,10 @@ ircd::stats::operator<<(std::ostream &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(item.val);
|
assert(item.val);
|
||||||
s << *item.val;
|
return fmt::sprintf
|
||||||
|
{
|
||||||
|
buf, "%lu", *item.val
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else if(item_.type == typeid(uint32_t *))
|
else if(item_.type == typeid(uint32_t *))
|
||||||
{
|
{
|
||||||
|
@ -40,7 +52,10 @@ ircd::stats::operator<<(std::ostream &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(item.val);
|
assert(item.val);
|
||||||
s << *item.val;
|
return fmt::sprintf
|
||||||
|
{
|
||||||
|
buf, "%u", *item.val
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else if(item_.type == typeid(uint16_t *))
|
else if(item_.type == typeid(uint16_t *))
|
||||||
{
|
{
|
||||||
|
@ -50,10 +65,16 @@ ircd::stats::operator<<(std::ostream &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(item.val);
|
assert(item.val);
|
||||||
s << *item.val;
|
return fmt::sprintf
|
||||||
|
{
|
||||||
|
buf, "%u", *item.val
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
else throw error
|
||||||
return s;
|
{
|
||||||
|
"Unsupported value type '%s'",
|
||||||
|
item_.type.name(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue