mirror of
https://github.com/matrix-construct/construct
synced 2024-10-02 13:48:53 +02:00
ircd::util: Add microtime() util.
This commit is contained in:
parent
4e8fd35341
commit
e586d268fc
1 changed files with 17 additions and 0 deletions
|
@ -215,6 +215,23 @@ size(std::ostream &s)
|
|||
}
|
||||
|
||||
|
||||
inline std::pair<time_t, int32_t>
|
||||
microtime()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
return { tv.tv_sec, tv.tv_usec };
|
||||
}
|
||||
|
||||
inline ssize_t
|
||||
microtime(char *const &buf,
|
||||
const size_t &size)
|
||||
{
|
||||
const auto mt(microtime());
|
||||
return snprintf(buf, size, "%zd.%06d", mt.first, mt.second);
|
||||
}
|
||||
|
||||
|
||||
} // namespace util
|
||||
} // namespace ircd
|
||||
#endif // __cplusplus
|
||||
|
|
Loading…
Reference in a new issue