From 20d0ea70c2f87193757263295f3e873f7f65f425 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 26 Mar 2019 22:03:48 -0700 Subject: [PATCH] ircd::ios: Add tsc counters to hook state. --- include/ircd/ios.h | 3 +++ ircd/ios.cc | 15 ++++++++++++++- modules/console.cc | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/ircd/ios.h b/include/ircd/ios.h index 3a134d285..8fdf579d5 100644 --- a/include/ircd/ios.h +++ b/include/ircd/ios.h @@ -78,6 +78,8 @@ struct ircd::ios::descriptor uint64_t alloc_bytes{0}; uint64_t frees {0}; uint64_t free_bytes{0}; + uint64_t slice_total {0}; + uint64_t slice_last {0}; descriptor(const string_view &name); descriptor(descriptor &&) = delete; @@ -94,6 +96,7 @@ struct ircd::ios::handler static bool fault(handler *const &); ios::descriptor *descriptor; + uint64_t slice_start {0}; }; template diff --git a/ircd/ios.cc b/ircd/ios.cc index 8fed68ca1..f0ddc9958 100644 --- a/ircd/ios.cc +++ b/ircd/ios.cc @@ -144,7 +144,17 @@ ircd::ios::handler::fault(handler *const &handler) assert(handler && handler->descriptor); auto &descriptor(*handler->descriptor); ++descriptor.faults; - return false; + bool ret(false); + + // leave() isn't called if we return false so the tsc counter + // needs to be tied off here instead. + if(!ret) + { + descriptor.slice_last = rdtsc() - handler->slice_start; + descriptor.slice_total += descriptor.slice_last; + } + + return ret; } void @@ -152,6 +162,8 @@ ircd::ios::handler::leave(handler *const &handler) { assert(handler && handler->descriptor); auto &descriptor(*handler->descriptor); + descriptor.slice_last = rdtsc() - handler->slice_start; + descriptor.slice_total += descriptor.slice_last; } void @@ -160,6 +172,7 @@ ircd::ios::handler::enter(handler *const &handler) assert(handler && handler->descriptor); auto &descriptor(*handler->descriptor); ++descriptor.calls; + handler->slice_start = rdtsc(); } void diff --git a/modules/console.cc b/modules/console.cc index 72fba0e33..b6f644bca 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -811,6 +811,7 @@ console_cmd__ios(opt &out, const string_view &line) << " " << std::left << std::setw(48) << "NAME" << " " << std::right << std::setw(6) << "FAULTS" << " " << std::right << std::setw(10) << "CALLS" + << " " << std::right << std::setw(15) << "CYCLES" << " " << std::right << std::setw(10) << "ALLOCS" << " " << std::right << std::setw(10) << "FREES" << " " << std::right << std::setw(26) << "ALLOCATED" @@ -827,6 +828,7 @@ console_cmd__ios(opt &out, const string_view &line) << " " << std::left << std::setw(48) << d.name << " " << std::right << std::setw(6) << d.faults << " " << std::right << std::setw(10) << d.calls + << " " << std::right << std::setw(15) << d.slice_total << " " << std::right << std::setw(10) << d.allocs << " " << std::right << std::setw(10) << d.frees << " " << std::right << std::setw(26) << pretty(iec(d.alloc_bytes))