Skip to content

Commit 968e3b6

Browse files
authored
[memprof] Add flag to control profile dump at exit (#119452)
Add the `dump_at_exit` flag to control whether or not profiles should be dumped when the program exits. Since we can call `__memprof_profile_dump()` directly, we don't necessarily need to dump profiles at exit.
1 parent 8c19c24 commit 968e3b6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler-rt/lib/memprof/memprof_allocator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ struct Allocator {
301301

302302
~Allocator() {
303303
atomic_store_relaxed(&destructing, 1);
304-
FinishAndWrite();
304+
if (flags()->dump_at_exit)
305+
FinishAndWrite();
305306
}
306307

307308
static void PrintCallback(const uptr Key, LockedMemInfoBlock *const &Value,

compiler-rt/lib/memprof/memprof_flags.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ MEMPROF_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true,
3838
MEMPROF_FLAG(bool, print_text, false,
3939
"If set, prints the heap profile in text format. Else use the raw binary serialization format.")
4040
MEMPROF_FLAG(bool, print_terse, false,
41-
"If set, prints memory profile in a terse format. Only applicable if print_text = true.")
41+
"If set, prints memory profile in a terse format. Only applicable "
42+
"if print_text = true.")
43+
MEMPROF_FLAG(bool, dump_at_exit, true,
44+
"If set, dump profiles when the program terminates.")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clangxx_memprof %s -o %t
2+
3+
// RUN: %env_memprof_opts=print_text=true:log_path=stdout:dump_at_exit=false %run %t | count 0
4+
// RUN: %env_memprof_opts=print_text=true:log_path=stdout:dump_at_exit=true %run %t | FileCheck %s
5+
6+
#include <stdlib.h>
7+
#include <string.h>
8+
9+
int main() {
10+
char *x = (char *)malloc(10);
11+
memset(x, 0, 10);
12+
free(x);
13+
return 0;
14+
}
15+
16+
// CHECK: Recorded MIBs

0 commit comments

Comments
 (0)