[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.
This commit is contained in:
@@ -301,7 +301,8 @@ struct Allocator {
|
||||
|
||||
~Allocator() {
|
||||
atomic_store_relaxed(&destructing, 1);
|
||||
FinishAndWrite();
|
||||
if (flags()->dump_at_exit)
|
||||
FinishAndWrite();
|
||||
}
|
||||
|
||||
static void PrintCallback(const uptr Key, LockedMemInfoBlock *const &Value,
|
||||
|
||||
@@ -38,4 +38,7 @@ MEMPROF_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true,
|
||||
MEMPROF_FLAG(bool, print_text, false,
|
||||
"If set, prints the heap profile in text format. Else use the raw binary serialization format.")
|
||||
MEMPROF_FLAG(bool, print_terse, false,
|
||||
"If set, prints memory profile in a terse format. Only applicable if print_text = true.")
|
||||
"If set, prints memory profile in a terse format. Only applicable "
|
||||
"if print_text = true.")
|
||||
MEMPROF_FLAG(bool, dump_at_exit, true,
|
||||
"If set, dump profiles when the program terminates.")
|
||||
|
||||
16
compiler-rt/test/memprof/TestCases/dump_at_exit.cpp
Normal file
16
compiler-rt/test/memprof/TestCases/dump_at_exit.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %clangxx_memprof %s -o %t
|
||||
|
||||
// RUN: %env_memprof_opts=print_text=true:log_path=stdout:dump_at_exit=false %run %t | count 0
|
||||
// RUN: %env_memprof_opts=print_text=true:log_path=stdout:dump_at_exit=true %run %t | FileCheck %s
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
char *x = (char *)malloc(10);
|
||||
memset(x, 0, 10);
|
||||
free(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CHECK: Recorded MIBs
|
||||
Reference in New Issue
Block a user