mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 19:28:52 +02:00
ircd::prof: Add x-platform cputime reporting alternative interface.
This commit is contained in:
parent
e29ebb0b98
commit
9d8fe82126
3 changed files with 67 additions and 4 deletions
|
@ -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],
|
||||
|
|
|
@ -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<std::array<uint64_t, 2>, 7>
|
||||
{
|
||||
|
|
48
ircd/prof.cc
48
ircd/prof.cc
|
@ -12,6 +12,8 @@
|
|||
#include <RB_INC_SYS_IOCTL_H
|
||||
#include <RB_INC_SYS_MMAN_H
|
||||
#include <linux/perf_event.h>
|
||||
#include <boost/chrono/chrono.hpp>
|
||||
#include <boost/chrono/process_cpu_clocks.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue