From 9d8fe82126ce6ed939fab61c6f6bafaad9511371 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 5 Apr 2019 16:56:51 -0700 Subject: [PATCH] ircd::prof: Add x-platform cputime reporting alternative interface. --- configure.ac | 5 +++-- include/ircd/prof.h | 18 +++++++++++++++-- ircd/prof.cc | 48 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index b425b0f95..277836bcb 100644 --- a/configure.ac +++ b/configure.ac @@ -1222,7 +1222,7 @@ dnl BOOST_VERSION_MIN="1.66" BOOST_VERSION_MIN_PATCH="0" -BOOST_BUILT_LIBS="system,filesystem,context,coroutine" +BOOST_BUILT_LIBS="system,filesystem,context,coroutine,chrono" AC_SUBST(BOOST_CPPFLAGS, []) AC_SUBST(BOOST_LDFLAGS, []) @@ -1306,6 +1306,7 @@ AC_HELP_STRING([--with-included-boost[[[=shared]]]], [Use the boost sources from AX_BOOST_FILESYSTEM AX_BOOST_COROUTINE AX_BOOST_CONTEXT + AX_BOOST_CHRONO boost_linkage="shared" ]) @@ -1314,7 +1315,7 @@ if [[ "$boost_linkage" = "shared" ]]; then [ AC_SUBST(BOOST_LIBS, ["-lboost_coroutine-mgw53-1_61.dll -lboost_context-mgw53-1_61.dll -lboost_thread-mgw53-1_61.dll -lboost_filesystem-mgw53-1_61.dll -lboost_system-mgw53-1_61.dll"]) ], [ - AC_SUBST(BOOST_LIBS, ["-lboost_coroutine -lboost_context -lboost_thread -lboost_filesystem -lboost_system"]) + AC_SUBST(BOOST_LIBS, ["-lboost_coroutine -lboost_context -lboost_thread -lboost_filesystem -lboost_chrono -lboost_system"]) ]) else AM_COND_IF([MINGW], diff --git a/include/ircd/prof.h b/include/ircd/prof.h index 4515640b7..b76b1fcc9 100644 --- a/include/ircd/prof.h +++ b/include/ircd/prof.h @@ -16,6 +16,7 @@ namespace ircd::prof struct init; struct type; struct event; + struct times; struct system; enum dpl :uint8_t; enum counter :uint8_t; @@ -24,8 +25,10 @@ namespace ircd::prof IRCD_EXCEPTION(ircd::error, error) - // Monotonic reference cycles - uint64_t cycles(); + uint64_t cycles(); ///< Monotonic reference cycles (since system boot) + uint64_t time_user(); ///< Nanoseconds of CPU time in userspace. + uint64_t time_kern(); ///< Nanoseconds of CPU time in kernelland. + uint64_t time_real(); ///< Nanoseconds of CPU time real. // Observe system &hotsample(system &) noexcept; @@ -54,6 +57,17 @@ namespace ircd using prof::cycles; } +struct ircd::prof::times +{ + uint64_t real {0}; + uint64_t kern {0}; + uint64_t user {0}; + + IRCD_OVERLOAD(sample) + times(sample_t); + times() = default; +}; + struct ircd::prof::system :std::array, 7> { diff --git a/ircd/prof.cc b/ircd/prof.cc index ec7829938..fdbfddeeb 100644 --- a/ircd/prof.cc +++ b/ircd/prof.cc @@ -12,6 +12,8 @@ #include +#include +#include namespace ircd::prof { @@ -646,3 +648,49 @@ ircd::prof::debug(std::ostream &s, return s; } + +// +// Interface (cross-platform) +// + +uint64_t +ircd::prof::time_real() +{ + return boost::chrono::process_real_cpu_clock::now().time_since_epoch().count(); +} + +uint64_t +ircd::prof::time_kern() +{ + return boost::chrono::process_system_cpu_clock::now().time_since_epoch().count(); +} + +uint64_t +ircd::prof::time_user() +{ + return boost::chrono::process_user_cpu_clock::now().time_since_epoch().count(); +} + +// +// times +// + +ircd::prof::times::times(sample_t) +:real{} +,kern{} +,user{} +{ + const auto tp + { + boost::chrono::process_cpu_clock::now() + }; + + const auto d + { + tp.time_since_epoch() + }; + + this->real = d.count().real; + this->kern = d.count().system; + this->user = d.count().user; +}