From: Eric Wong <p5p@yhbt.net>
To: spew@80x24.org
Subject: [PATCH] trace arena
Date: Sun, 3 Mar 2024 23:22:03 +0000 [thread overview]
Message-ID: <20240303232203.1002150-1-p5p@yhbt.net> (raw)
---
sv.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/sv.c b/sv.c
index 9c7f3ba..a04e1dc 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 <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+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;
@@ -1091,6 +1130,8 @@ Perl_more_bodies (pTHX_ const svtype sv_type, const size_t body_size,
#if defined(DEBUGGING) && !defined(PERL_GLOBAL_STRUCT)
static bool done_sanity_check;
+ trace_arena(sv_type, arena_size, good_arena_size);
+
/* PERL_GLOBAL_STRUCT cannot coexist with global
* variables like done_sanity_check. */
if (!done_sanity_check) {
next reply other threads:[~2024-03-03 23:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 23:22 Eric Wong [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-03-03 23:25 [PATCH] trace arena Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240303232203.1002150-1-p5p@yhbt.net \
--to=p5p@yhbt.net \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).