0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-18 18:08:21 +02:00

ircd::prof: Add x-platform cputime reporting alternative interface.

This commit is contained in:
Jason Volk 2019-04-05 16:56:51 -07:00
parent e29ebb0b98
commit 9d8fe82126
3 changed files with 67 additions and 4 deletions

View file

@ -1222,7 +1222,7 @@ dnl
BOOST_VERSION_MIN="1.66" BOOST_VERSION_MIN="1.66"
BOOST_VERSION_MIN_PATCH="0" 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_CPPFLAGS, [])
AC_SUBST(BOOST_LDFLAGS, []) 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_FILESYSTEM
AX_BOOST_COROUTINE AX_BOOST_COROUTINE
AX_BOOST_CONTEXT AX_BOOST_CONTEXT
AX_BOOST_CHRONO
boost_linkage="shared" 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-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 else
AM_COND_IF([MINGW], AM_COND_IF([MINGW],

View file

@ -16,6 +16,7 @@ namespace ircd::prof
struct init; struct init;
struct type; struct type;
struct event; struct event;
struct times;
struct system; struct system;
enum dpl :uint8_t; enum dpl :uint8_t;
enum counter :uint8_t; enum counter :uint8_t;
@ -24,8 +25,10 @@ namespace ircd::prof
IRCD_EXCEPTION(ircd::error, error) IRCD_EXCEPTION(ircd::error, error)
// Monotonic reference cycles uint64_t cycles(); ///< Monotonic reference cycles (since system boot)
uint64_t cycles(); 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 // Observe
system &hotsample(system &) noexcept; system &hotsample(system &) noexcept;
@ -54,6 +57,17 @@ namespace ircd
using prof::cycles; 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 struct ircd::prof::system
:std::array<std::array<uint64_t, 2>, 7> :std::array<std::array<uint64_t, 2>, 7>
{ {

View file

@ -12,6 +12,8 @@
#include <RB_INC_SYS_IOCTL_H #include <RB_INC_SYS_IOCTL_H
#include <RB_INC_SYS_MMAN_H #include <RB_INC_SYS_MMAN_H
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <boost/chrono/chrono.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
namespace ircd::prof namespace ircd::prof
{ {
@ -646,3 +648,49 @@ ircd::prof::debug(std::ostream &s,
return 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;
}