Skip to content

Commit

Permalink
[memprof] Make the raw binary format the default.
Browse files Browse the repository at this point in the history
Set the default memprof serialization format as binary. 9 tests are
updated to use print_text=true. Also fixed an issue with concatenation
of default and test specified options (missing separator).

Differential Revision: https://reviews.llvm.org/D113617
  • Loading branch information
snehasish committed Nov 11, 2021
1 parent 545866c commit aacaebc
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/lib/memprof/memprof_flags.inc
Expand Up @@ -35,7 +35,7 @@ MEMPROF_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true,
"realloc(p, 0) is equivalent to free(p) by default (Same as the "
"POSIX standard). If set to false, realloc(p, 0) will return a "
"pointer to an allocated space which can not be used.")
MEMPROF_FLAG(bool, print_text, 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.")
4 changes: 2 additions & 2 deletions compiler-rt/test/memprof/TestCases/atexit_stats.cpp
@@ -1,8 +1,8 @@
// Check atexit option.

// RUN: %clangxx_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr:atexit=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=log_path=stderr:atexit=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOATEXIT
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:atexit=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:atexit=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOATEXIT

// CHECK: MemProfiler exit stats:
// CHECK: Stats: {{[0-9]+}}M malloced ({{[0-9]+}}M for overhead) by {{[0-9]+}} calls
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/memprof/TestCases/dump_process_map.cpp
@@ -1,8 +1,8 @@
// Check print_module_map option.

// RUN: %clangxx_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr:print_module_map=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=log_path=stderr:print_module_map=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOMAP
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:print_module_map=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:print_module_map=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOMAP

// CHECK: Process memory map follows:
// CHECK: dump_process_map.cpp.tmp
Expand Down
16 changes: 8 additions & 8 deletions compiler-rt/test/memprof/TestCases/log_path_test.cpp
Expand Up @@ -3,19 +3,19 @@
//
// RUN: %clangxx_memprof %s -o %t

// stderr log_path
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always
// stderr print_text=true:log_path
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always

// Good log_path.
// Good print_text=true:log_path.
// RUN: rm -f %t.log.*
// RUN: %env_memprof_opts=log_path=%t.log %run %t
// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t
// RUN: FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log.*

// Invalid log_path.
// RUN: %env_memprof_opts=log_path=/dev/null/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always
// Invalid print_text=true:log_path.
// RUN: %env_memprof_opts=print_text=true:log_path=/dev/null/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always

// Too long log_path.
// RUN: %env_memprof_opts=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
// Too long print_text=true:log_path.
// RUN: %env_memprof_opts=print_text=true:log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-LONG --dump-input=always

// Specifying the log name via the __memprof_profile_filename variable.
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/test/memprof/TestCases/malloc-size-too-big.cpp
@@ -1,8 +1,8 @@
// RUN: %clangxx_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SUMMARY
// RUN: %env_memprof_opts=log_path=stderr:allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SUMMARY
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
// Test print_summary
// RUN: %env_memprof_opts=log_path=stderr:allocator_may_return_null=0:print_summary=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOSUMMARY
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:allocator_may_return_null=0:print_summary=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOSUMMARY

#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/memprof/TestCases/memprof_merge_mib.cpp
@@ -1,6 +1,6 @@
// RUN: %clangxx_memprof %s -o %t

// RUN: %env_memprof_opts=log_path=stdout %run %t | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stdout %run %t | FileCheck %s

#include <sanitizer/memprof_interface.h>
#include <stdlib.h>
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/memprof/TestCases/memprof_profile_dump.cpp
@@ -1,7 +1,7 @@
// RUN: %clangxx_memprof %s -o %t

// RUN: %env_memprof_opts=log_path=stdout %run %t | FileCheck --check-prefix=CHECK-TEXT %s
// RUN: %env_memprof_opts=log_path=stdout,print_text=false %run %t > %t.memprofraw
// RUN: %env_memprof_opts=print_text=true:log_path=stdout %run %t | FileCheck --check-prefix=CHECK-TEXT %s
// RUN: %env_memprof_opts=print_text=true:log_path=stdout,print_text=false %run %t > %t.memprofraw
// RUN: od -c -N 8 %t.memprofraw | FileCheck --check-prefix=CHECK-RAW %s

#include <sanitizer/memprof_interface.h>
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/test/memprof/TestCases/stress_dtls.c
Expand Up @@ -7,9 +7,9 @@
// RUN: %clang_memprof %s -ldl -pthread -o %t
// RUN: %run %t 0 3
// RUN: %run %t 2 3
// RUN: %env_memprof_opts=log_path=stderr:verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=log_path=stderr:verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=log_path=stderr:verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
// CHECK: ==__tls_get_addr:
// CHECK: Creating thread 0
// CHECK: ==__tls_get_addr:
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/memprof/TestCases/test_malloc_load_store.c
Expand Up @@ -3,10 +3,10 @@
// before exit.

// RUN: %clang_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// RUN: %clang_memprof -DFREE -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// This is actually:
// Memory allocation stack id = STACKID
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/memprof/TestCases/test_memintrin.cpp
@@ -1,6 +1,6 @@
// Check profile with calls to memory intrinsics.

// RUN: %clangxx_memprof -O0 %s -o %t && %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_memprof -O0 %s -o %t && %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// This is actually:
// Memory allocation stack id = STACKIDP
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/test/memprof/TestCases/test_new_load_store.cpp
Expand Up @@ -3,14 +3,14 @@
// before exit.

// RUN: %clangxx_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// RUN: %clangxx_memprof -DFREE -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// Try again with callbacks instead of inline sequences
// RUN: %clangxx_memprof -mllvm -memprof-use-callbacks -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// This is actually:
// Memory allocation stack id = STACKID
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/test/memprof/TestCases/test_terse.cpp
Expand Up @@ -3,10 +3,10 @@
// deallocated before exit.

// RUN: %clangxx_memprof -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr:print_terse=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:print_terse=1 %run %t 2>&1 | FileCheck %s

// RUN: %clangxx_memprof -DFREE -O0 %s -o %t
// RUN: %env_memprof_opts=log_path=stderr:print_terse=1 %run %t 2>&1 | FileCheck %s
// RUN: %env_memprof_opts=print_text=true:log_path=stderr:print_terse=1 %run %t 2>&1 | FileCheck %s

// CHECK: MIB:[[STACKID:[0-9]+]]/1/40.00/40/40/20.00/20/20/[[AVELIFETIME:[0-9]+]].00/[[AVELIFETIME]]/[[AVELIFETIME]]/{{[01]}}/0/0/0
// CHECK: Stack for id [[STACKID]]:
Expand Down
@@ -1,4 +1,4 @@
// RUN: %clangxx_memprof -O0 %s -o %t && %env_memprof_opts=log_path=stderr %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_memprof -O0 %s -o %t && %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s

// This is actually:
// Memory allocation stack id = STACKID
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/memprof/lit.cfg.py
Expand Up @@ -33,6 +33,7 @@ def get_required_attr(config, attr_name):
default_memprof_opts_str = ':'.join(default_memprof_opts)
if default_memprof_opts_str:
config.environment['MEMPROF_OPTIONS'] = default_memprof_opts_str
default_memprof_opts_str += ':'
config.substitutions.append(('%env_memprof_opts=',
'env MEMPROF_OPTIONS=' + default_memprof_opts_str))

Expand Down

0 comments on commit aacaebc

Please sign in to comment.