0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 00:02:34 +01:00

ircd::stats: Add signed integer, chrono specializations; use panic exception.

This commit is contained in:
Jason Volk 2020-12-22 23:26:56 -08:00
parent dfa75cd421
commit 9f0c081ac8
2 changed files with 221 additions and 4 deletions

View file

@ -52,11 +52,25 @@ namespace ircd::stats
template<> struct item<uint64_t *>;
template<> struct item<uint32_t *>;
template<> struct item<uint16_t *>;
template<> struct item<int64_t *>;
template<> struct item<int32_t *>;
template<> struct item<int16_t *>;
template<> struct item<nanoseconds *>;
template<> struct item<microseconds *>;
template<> struct item<milliseconds *>;
template<> struct item<seconds *>;
// Value-carrying items
template<> struct item<uint64_t>;
template<> struct item<uint32_t>;
template<> struct item<uint16_t>;
template<> struct item<int64_t>;
template<> struct item<int32_t>;
template<> struct item<int16_t>;
template<> struct item<nanoseconds>;
template<> struct item<microseconds>;
template<> struct item<milliseconds>;
template<> struct item<seconds>;
extern const size_t NAME_MAX_LEN;
extern std::vector<item<void> *> items;
@ -184,6 +198,22 @@ struct ircd::stats::item<uint64_t>
using int_item<uint64_t>::operator=;
};
template<>
struct ircd::stats::item<int64_t *>
:ptr_item<int64_t>
{
using ptr_item<int64_t>::ptr_item;
using ptr_item<int64_t>::operator=;
};
template<>
struct ircd::stats::item<int64_t>
:int_item<int64_t>
{
using int_item<int64_t>::int_item;
using int_item<int64_t>::operator=;
};
template<>
struct ircd::stats::item<uint32_t *>
:ptr_item<uint32_t>
@ -200,6 +230,22 @@ struct ircd::stats::item<uint32_t>
using int_item<uint32_t>::operator=;
};
template<>
struct ircd::stats::item<int32_t *>
:ptr_item<int32_t>
{
using ptr_item<int32_t>::ptr_item;
using ptr_item<int32_t>::operator=;
};
template<>
struct ircd::stats::item<int32_t>
:int_item<int32_t>
{
using int_item<int32_t>::int_item;
using int_item<int32_t>::operator=;
};
template<>
struct ircd::stats::item<uint16_t *>
:ptr_item<uint16_t>
@ -215,3 +261,83 @@ struct ircd::stats::item<uint16_t>
using int_item<uint16_t>::int_item;
using int_item<uint16_t>::operator=;
};
template<>
struct ircd::stats::item<int16_t *>
:ptr_item<int16_t>
{
using ptr_item<int16_t>::ptr_item;
using ptr_item<int16_t>::operator=;
};
template<>
struct ircd::stats::item<int16_t>
:int_item<int16_t>
{
using int_item<int16_t>::int_item;
using int_item<int16_t>::operator=;
};
template<>
struct ircd::stats::item<ircd::nanoseconds *>
:ptr_item<nanoseconds>
{
using ptr_item<nanoseconds>::ptr_item;
using ptr_item<nanoseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::nanoseconds>
:int_item<nanoseconds>
{
using int_item<nanoseconds>::int_item;
using int_item<nanoseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::microseconds *>
:ptr_item<microseconds>
{
using ptr_item<microseconds>::ptr_item;
using ptr_item<microseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::microseconds>
:int_item<microseconds>
{
using int_item<microseconds>::int_item;
using int_item<microseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::milliseconds *>
:ptr_item<milliseconds>
{
using ptr_item<milliseconds>::ptr_item;
using ptr_item<milliseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::milliseconds>
:int_item<milliseconds>
{
using int_item<milliseconds>::int_item;
using int_item<milliseconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::seconds *>
:ptr_item<seconds>
{
using ptr_item<seconds>::ptr_item;
using ptr_item<seconds>::operator=;
};
template<>
struct ircd::stats::item<ircd::seconds>
:int_item<seconds>
{
using int_item<seconds>::int_item;
using int_item<seconds>::operator=;
};

View file

@ -35,7 +35,7 @@ ircd::stats::string(const mutable_buffer &buf,
{
const auto &item
{
dynamic_cast<const stats::item<uint64_t *> &>(item_)
dynamic_cast<const stats::ptr_item<uint64_t> &>(item_)
};
assert(item.val);
@ -44,11 +44,76 @@ ircd::stats::string(const mutable_buffer &buf,
buf, "%lu", *item.val
};
}
else if(item_.type == typeid(int64_t *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<int64_t> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%ld", *item.val
};
}
else if(item_.type == typeid(nanoseconds *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<nanoseconds> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%ld", item.val->count()
};
}
else if(item_.type == typeid(microseconds *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<microseconds> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%ld", item.val->count()
};
}
else if(item_.type == typeid(milliseconds *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<milliseconds> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%ld", item.val->count()
};
}
else if(item_.type == typeid(seconds *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<seconds> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%ld", item.val->count()
};
}
else if(item_.type == typeid(uint32_t *))
{
const auto &item
{
dynamic_cast<const stats::item<uint32_t *> &>(item_)
dynamic_cast<const stats::ptr_item<uint32_t> &>(item_)
};
assert(item.val);
@ -57,11 +122,24 @@ ircd::stats::string(const mutable_buffer &buf,
buf, "%u", *item.val
};
}
else if(item_.type == typeid(int32_t *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<int32_t> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%d", *item.val
};
}
else if(item_.type == typeid(uint16_t *))
{
const auto &item
{
dynamic_cast<const stats::item<uint16_t *> &>(item_)
dynamic_cast<const stats::ptr_item<uint16_t> &>(item_)
};
assert(item.val);
@ -70,7 +148,20 @@ ircd::stats::string(const mutable_buffer &buf,
buf, "%u", *item.val
};
}
else throw error
else if(item_.type == typeid(int16_t *))
{
const auto &item
{
dynamic_cast<const stats::ptr_item<int16_t> &>(item_)
};
assert(item.val);
return fmt::sprintf
{
buf, "%d", *item.val
};
}
else throw invalid
{
"Unsupported value type '%s'",
item_.type.name(),