[PATCH] D74098: scudo: Add a dump of primary allocation sizes to malloc_info output.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 5 16:29:10 PST 2020
pcc created this revision.
pcc added a reviewer: cryptoad.
Herald added projects: Sanitizers, LLVM.
Herald added a subscriber: Sanitizers.
This will be useful for optimizing the size class map.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74098
Files:
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
compiler-rt/lib/scudo/standalone/wrappers_c.inc
Index: compiler-rt/lib/scudo/standalone/wrappers_c.inc
===================================================================
--- compiler-rt/lib/scudo/standalone/wrappers_c.inc
+++ compiler-rt/lib/scudo/standalone/wrappers_c.inc
@@ -180,8 +180,21 @@
}
INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(UNUSED int options, FILE *stream) {
- fputs("<malloc version=\"scudo-1\">", stream);
- fputs("</malloc>", stream);
+ const scudo::uptr max_size =
+ decltype(SCUDO_ALLOCATOR)::PrimaryT::SizeClassMap::MaxSize;
+ scudo::uptr sizes[max_size] = {};
+ auto callback = [](uintptr_t, size_t size, void* arg) {
+ auto *sizes = reinterpret_cast<scudo::uptr *>(arg);
+ if (size < max_size)
+ sizes[size]++;
+ };
+ SCUDO_ALLOCATOR.iterateOverChunks(0, -1ul, callback, sizes);
+
+ fputs("<malloc version=\"scudo-1\">\n", stream);
+ for (scudo::uptr i = 0; i != max_size; ++i)
+ if (sizes[i])
+ fprintf(stream, "<alloc size=\"%lu\" count=\"%lu\"/>\n", i, sizes[i]);
+ fputs("</malloc>\n", stream);
return 0;
}
Index: compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -303,7 +303,11 @@
#if !SCUDO_FUCHSIA
TEST(ScudoWrappersCTest, MallocInfo) {
- char Buffer[64];
+ // Use volatile so that the allocations don't get optimized away.
+ void *volatile P1 = malloc(1234);
+ void *volatile P2 = malloc(4321);
+
+ char Buffer[16384];
FILE *F = fmemopen(Buffer, sizeof(Buffer), "w+");
EXPECT_NE(F, nullptr);
errno = 0;
@@ -311,6 +315,11 @@
EXPECT_EQ(errno, 0);
fclose(F);
EXPECT_EQ(strncmp(Buffer, "<malloc version=\"scudo-", 23), 0);
+ EXPECT_NE(nullptr, strstr(Buffer, "<alloc size=\"1234\" count=\""));
+ EXPECT_NE(nullptr, strstr(Buffer, "<alloc size=\"4321\" count=\""));
+
+ free(P1);
+ free(P2);
}
TEST(ScudoWrappersCTest, Fork) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74098.242782.patch
Type: text/x-patch
Size: 1995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200206/96344b6c/attachment.bin>
More information about the llvm-commits
mailing list