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
35 lines
1020 B
C++
35 lines
1020 B
C++
// The for loop in the backticks below requires bash.
|
|
// REQUIRES: shell
|
|
//
|
|
// RUN: %clangxx_memprof %s -o %t
|
|
|
|
// Regular run.
|
|
// RUN: %run %t 2> %t.out
|
|
// RUN: FileCheck %s --check-prefix=CHECK-GOOD < %t.out
|
|
|
|
// Good log_path.
|
|
// RUN: rm -f %t.log.*
|
|
// RUN: %env_memprof_opts=log_path=%t.log %run %t 2> %t.out
|
|
// RUN: FileCheck %s --check-prefix=CHECK-GOOD < %t.log.*
|
|
|
|
// Invalid log_path.
|
|
// RUN: %env_memprof_opts=log_path=/dev/null/INVALID not %run %t 2> %t.out
|
|
// RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
|
|
|
|
// Too long log_path.
|
|
// RUN: %env_memprof_opts=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
|
|
// RUN: not %run %t 2> %t.out
|
|
// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
int main(int argc, char **argv) {
|
|
char *x = (char *)malloc(10);
|
|
memset(x, 0, 10);
|
|
free(x);
|
|
return 0;
|
|
}
|
|
// CHECK-GOOD: Memory allocation stack id
|
|
// CHECK-INVALID: ERROR: Can't open file: /dev/null/INVALID
|
|
// CHECK-LONG: ERROR: Path is too long: 01234
|