From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.6 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C96221F44D for ; Sun, 3 Mar 2024 23:25:43 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] trace arena Date: Sun, 3 Mar 2024 23:25:43 +0000 Message-ID: <20240303232543.1017112-1-p5p@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- sv.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sv.c b/sv.c index 9c7f3ba..77b679e 100644 --- a/sv.c +++ b/sv.c @@ -297,6 +297,44 @@ Public API: ++PL_sv_count; \ } STMT_END +#define TRACE_ARENA 1 +#if TRACE_ARENA +#include +#include +#include +static time_t trace_start = -1; +static int trace_arena_alloc; + +static void __attribute__((constructor)) init_arena_trace(void) +{ + const char *t = getenv("TRACE_ARENA"); + if (t && *t) + trace_arena_alloc = 1; +} + +static void trace_arena(const svtype sv_type, size_t req, size_t actual) +{ + struct timespec ts; + + if (!trace_arena_alloc) + return; + + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + if (trace_start < 0) { + trace_start = ts.tv_sec + 10; + } else if (trace_start > 0) { + if (ts.tv_sec > trace_start) + trace_start = 0; + } + if (!trace_start) + dprintf(2, "%ld %u %zu -> %zu\n", + ts.tv_sec, sv_type, req, actual); +} +#else /* !TRACE_ARENA */ +static void trace_arena(const svtype sv_type, size_t req, size_t actual) +{ +} +#endif /* TRACE_ARENA */ /* make some more SVs by adding another arena */ @@ -306,6 +344,7 @@ S_more_sv(pTHX) SV* sv; char *chunk; /* must use New here to match call to */ Newx(chunk,PERL_ARENA_SIZE,char); /* Safefree() in sv_free_arenas() */ + trace_arena(SVt_NULL, 0, PERL_ARENA_SIZE); sv_add_arena(chunk, PERL_ARENA_SIZE, 0); uproot_SV(sv); return sv; @@ -1102,6 +1141,7 @@ Perl_more_bodies (pTHX_ const svtype sv_type, const size_t body_size, assert (bodies_by_type[i].type == i); } #endif + trace_arena(sv_type, arena_size, good_arena_size); assert(arena_size);