From f98be1582d58a06dfc162f58ba2c99f08adc3fa7 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 31 Aug 2017 17:42:15 -0700 Subject: [PATCH] ircd::ctx: Expose stack usage functions to user. --- include/ircd/ctx/prof.h | 6 ++++++ ircd/ctx.cc | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/ircd/ctx/prof.h b/include/ircd/ctx/prof.h index 9a36fbf9d..5bb642f9a 100644 --- a/include/ircd/ctx/prof.h +++ b/include/ircd/ctx/prof.h @@ -24,6 +24,12 @@ #pragma once #define HAVE_IRCD_CTX_PROF_H +namespace ircd::ctx +{ + size_t stack_usage_here(const ctx &) __attribute__((noinline)); + size_t stack_usage_here() __attribute__((noinline)); +} + /* Profiling for the context system. These facilities provide tools and statistics. * The primary purpose here is to alert developers of unwanted context behavior, in * addition to optimizing the overall performance of the context system. diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 7488361f7..9fefe994c 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -617,7 +617,6 @@ namespace ircd::ctx::prof { time_point cur_slice_start; // Time slice state - size_t stack_usage_here(const ctx &) __attribute__((noinline)); void check_stack(); void check_slice(); void slice_start(); @@ -726,7 +725,14 @@ ircd::ctx::prof::check_stack() } size_t -ircd::ctx::prof::stack_usage_here(const ctx &ctx) +ircd::ctx::stack_usage_here() +{ + assert(current); + return stack_usage_here(*current); +} + +size_t +ircd::ctx::stack_usage_here(const ctx &ctx) { return ctx.stack_base - uintptr_t(__builtin_frame_address(0)); }