Skip to content

[memprof] Add flag to control profile dump at exit #119452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler-rt/lib/memprof/memprof_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion compiler-rt/lib/memprof/memprof_flags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 16 additions & 0 deletions compiler-rt/test/memprof/TestCases/dump_at_exit.cpp
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is count 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count N will pass if it reads N lines from stdin. So this just checks that there is no output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah count is a utility we bundle with LLVM for testing. TIL.

// 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
Loading