See RFC for background: http://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html Follow on companion to the clang/llvm instrumentation support in D85948 and committed earlier. This patch adds the compiler-rt runtime support for the memory profiling. Note that much of this support was cloned from asan (and then greatly simplified and renamed). For example the interactions with the sanitizer_common allocators, error handling, interception, etc. The bulk of the memory profiling specific code can be found in the MemInfoBlock, MemInfoBlockCache, and related classes defined and used in memprof_allocator.cpp. For now, the memory profile is dumped to text (stderr by default, but honors the sanitizer_common log_path flag). It is dumped in either a default verbose format, or an optional terse format. This patch also adds a set of tests for the core functionality. Differential Revision: https://reviews.llvm.org/D87120
43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
// Check profile with a single new call and set of loads and stores. Ensures
|
|
// we get the same profile regardless of whether the memory is deallocated
|
|
// before exit.
|
|
|
|
// RUN: %clangxx_memprof -O0 %s -o %t
|
|
// RUN: %env_memprof_opts= %run %t 2>&1 | FileCheck %s
|
|
|
|
// RUN: %clangxx_memprof -DFREE -O0 %s -o %t
|
|
// RUN: %env_memprof_opts= %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= %run %t 2>&1 | FileCheck %s
|
|
|
|
// This is actually:
|
|
// Memory allocation stack id = STACKID
|
|
// alloc_count 1, size (ave/min/max) 40.00 / 40 / 40
|
|
// but we need to look for them in the same CHECK to get the correct STACKID.
|
|
// CHECK: Memory allocation stack id = [[STACKID:[0-9]+]]{{[[:space:]].*}}alloc_count 1, size (ave/min/max) 40.00 / 40 / 40
|
|
// CHECK-NEXT: access_count (ave/min/max): 20.00 / 20 / 20
|
|
// CHECK-NEXT: lifetime (ave/min/max): [[AVELIFETIME:[0-9]+]].00 / [[AVELIFETIME]] / [[AVELIFETIME]]
|
|
// CHECK-NEXT: num migrated: 0, num lifetime overlaps: 0, num same alloc cpu: 0, num same dealloc_cpu: 0
|
|
// CHECK: Stack for id [[STACKID]]:
|
|
// CHECK-NEXT: #0 {{.*}} in operator new
|
|
// CHECK-NEXT: #1 {{.*}} in main {{.*}}:[[@LINE+6]]
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main() {
|
|
int *p = new int[10];
|
|
for (int i = 0; i < 10; i++)
|
|
p[i] = i;
|
|
int j = 0;
|
|
for (int i = 0; i < 10; i++)
|
|
j += p[i];
|
|
#ifdef FREE
|
|
delete p;
|
|
#endif
|
|
|
|
return 0;
|
|
}
|