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=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF 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 775461F461 for ; Sun, 7 Apr 2024 10:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1712485215; bh=72zrAPhExINBN/YlNq7UdLve/6Vmr1VDTkOQcVOwFpA=; h=From:To:Subject:Date:From; b=iURvnD2KvcolFIlx6DggFhQ2P8Zzplsq+vDbXx+fhk/WeuaqObmlMC2iS8pGkiWyu kuhmp3tq0x8fmF+ImBLYTOaNnttiZX8de7bPPsx+MpPaH8tmIAwRW5Ya4fLhIAyyyl y079/901A/GI31bQ/o8DWAuljHNVz+j4kYb2DQRg= From: Eric Wong To: spew@80x24.org Subject: [PATCH] trace-replay: fill pages after allocation Date: Sun, 7 Apr 2024 10:20:15 +0000 Message-ID: <20240407102015.832776-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This makes it easier to track memory usage via `time -v' with the GNU time(1) command (not the `time' sh builtin). --- lib/Devel/Mwrap/trace-replay.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Devel/Mwrap/trace-replay.h b/lib/Devel/Mwrap/trace-replay.h index c43cc0f..944db60 100644 --- a/lib/Devel/Mwrap/trace-replay.h +++ b/lib/Devel/Mwrap/trace-replay.h @@ -78,6 +78,20 @@ static void store_ptr(uintptr_t old, void *cur) kh_val(old2cur, k) = (uintptr_t)cur; } +static size_t page_size; + +static void fill(char *c, size_t n) +{ + static uintptr_t max_seen; + + if (n > page_size) + if (((uintptr_t)c - page_size + n) < max_seen) + max_seen = (uintptr_t)c + n * page_size; + + for (size_t i = 0; i < n; i += page_size) + c[i] = 0x1; +} + int main(int argc, char *argv[]) { tr_ms = create_mspace(0, 0); @@ -93,6 +107,7 @@ int main(int argc, char *argv[]) } as; int truncated = 0; + page_size = getpagesize(); old2cur = ptrmap_init(); // don't fill buf all the way so we can do small reads in ENSURE_FILL: @@ -140,6 +155,7 @@ int main(int argc, char *argv[]) err(1, "malloc(%zu) => %p", as.do_malloc.size, (void *)as.do_malloc.ret); + fill(cur, as.do_malloc.size); store_ptr(as.do_malloc.ret, cur); break; @@ -150,6 +166,7 @@ int main(int argc, char *argv[]) err(1, "calloc(%zu) => %p", as.do_calloc.size, (void *)as.do_calloc.ret); + fill(cur, as.do_calloc.size); store_ptr(as.do_calloc.ret, cur); break; @@ -174,6 +191,7 @@ int main(int argc, char *argv[]) cur, as.do_realloc.size, (void *)as.do_realloc.ret); + fill(rp, as.do_realloc.size); store_ptr(as.do_realloc.ret, rp); break; case TR_MEMALIGN: @@ -190,6 +208,7 @@ int main(int argc, char *argv[]) as.do_memalign.size, (void *)as.do_memalign.ret); } + fill(cur, as.do_memalign.size); store_ptr(as.do_memalign.ret, cur); break; default: