From 55fc2c6f76a0884e41d732eb94014c090b20949b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 19 Apr 2019 05:47:30 -0700 Subject: [PATCH] ircd::prof: Add callgrind hypercall suite. --- configure.ac | 1 + include/ircd/prof.h | 25 ++++++++++++++++++++++++ ircd/prof.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/configure.ac b/configure.ac index ff98e9034..3fda8109c 100644 --- a/configure.ac +++ b/configure.ac @@ -783,6 +783,7 @@ dnl instrumentation RB_CHK_SYSHEADER(malloc.h, [MALLOC_H]) RB_CHK_SYSHEADER(valgrind/valgrind.h, [VALGRIND_VALGRIND_H]) RB_CHK_SYSHEADER(valgrind/memcheck.h, [VALGRIND_MEMCHECK_H]) +RB_CHK_SYSHEADER(valgrind/callgrind.h, [VALGRIND_CALLGRIND_H]) dnl experimental RB_CHK_SYSHEADER(experimental/string_view, [EXPERIMENTAL_STRING_VIEW]) diff --git a/include/ircd/prof.h b/include/ircd/prof.h index acc1f4353..02a5b1d06 100644 --- a/include/ircd/prof.h +++ b/include/ircd/prof.h @@ -60,11 +60,36 @@ namespace ircd::prof::x86 unsigned long long rdtsc(); } +/// Callgrind hypercall suite +namespace ircd::prof::vg +{ + struct enable; + struct disable; + + void dump(const char *const reason = nullptr); + void toggle(); + void reset(); + void start() noexcept; + void stop() noexcept; +} + namespace ircd { using prof::cycles; } +struct ircd::prof::vg::enable +{ + enable() noexcept { start(); } + ~enable() noexcept { stop(); } +}; + +struct ircd::prof::vg::disable +{ + disable() noexcept { stop(); } + ~disable() noexcept { start(); } +}; + struct ircd::prof::times { uint64_t real {0}; diff --git a/ircd/prof.cc b/ircd/prof.cc index 4a9c2dc23..1f4747a3f 100644 --- a/ircd/prof.cc +++ b/ircd/prof.cc @@ -13,6 +13,7 @@ #include +#include #include @@ -772,6 +773,52 @@ ircd::prof::time_user() return boost::chrono::process_user_cpu_clock::now().time_since_epoch().count(); } +// +// prof::vg +// + +void +ircd::prof::vg::stop() +noexcept +{ + #ifdef HAVE_VALGRIND_CALLGRIND_H + CALLGRIND_STOP_INSTRUMENTATION; + #endif +} + +void +ircd::prof::vg::start() +noexcept +{ + #ifdef HAVE_VALGRIND_CALLGRIND_H + CALLGRIND_START_INSTRUMENTATION; + #endif +} + +void +ircd::prof::vg::reset() +{ + #ifdef HAVE_VALGRIND_CALLGRIND_H + CALLGRIND_ZERO_STATS; + #endif +} + +void +ircd::prof::vg::toggle() +{ + #ifdef HAVE_VALGRIND_CALLGRIND_H + CALLGRIND_TOGGLE_COLLECT; + #endif +} + +void +ircd::prof::vg::dump(const char *const reason) +{ + #ifdef HAVE_VALGRIND_CALLGRIND_H + CALLGRIND_DUMP_STATS_AT(reason); + #endif +} + // // times //