diff options
author | Teresa Johnson <tejohnson@google.com> | 2020-09-03 15:21:20 -0700 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2020-10-16 09:47:02 -0700 |
commit | 3d4bba302d2460b9ac6463ef920c301f1f40fb41 (patch) | |
tree | a1eba35c9176ae517958fdf112a9703610bb5543 /compiler-rt/include | |
parent | 880fc4d581b091dbb68703c3e55c2ca2f94192c2 (diff) | |
download | llvm-3d4bba302d2460b9ac6463ef920c301f1f40fb41.zip llvm-3d4bba302d2460b9ac6463ef920c301f1f40fb41.tar.gz llvm-3d4bba302d2460b9ac6463ef920c301f1f40fb41.tar.bz2 |
[MemProf] Memory profiling runtime support
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
Diffstat (limited to 'compiler-rt/include')
-rw-r--r-- | compiler-rt/include/CMakeLists.txt | 1 | ||||
-rw-r--r-- | compiler-rt/include/sanitizer/memprof_interface.h | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index d47d7ba..de4cf36 100644 --- a/compiler-rt/include/CMakeLists.txt +++ b/compiler-rt/include/CMakeLists.txt @@ -5,6 +5,7 @@ if (COMPILER_RT_BUILD_SANITIZERS) sanitizer/common_interface_defs.h sanitizer/coverage_interface.h sanitizer/dfsan_interface.h + sanitizer/memprof_interface.h sanitizer/hwasan_interface.h sanitizer/linux_syscall_hooks.h sanitizer/lsan_interface.h diff --git a/compiler-rt/include/sanitizer/memprof_interface.h b/compiler-rt/include/sanitizer/memprof_interface.h new file mode 100644 index 0000000..a721260 --- /dev/null +++ b/compiler-rt/include/sanitizer/memprof_interface.h @@ -0,0 +1,60 @@ +//===-- sanitizer/memprof_interface.h --------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file is a part of MemProfiler (MemProf). +// +// Public interface header. +//===----------------------------------------------------------------------===// +#ifndef SANITIZER_MEMPROF_INTERFACE_H +#define SANITIZER_MEMPROF_INTERFACE_H + +#include <sanitizer/common_interface_defs.h> + +#ifdef __cplusplus +extern "C" { +#endif +/// Records access to a memory region (<c>[addr, addr+size)</c>). +/// +/// This memory must be previously allocated by your program. +/// +/// \param addr Start of memory region. +/// \param size Size of memory region. +void __memprof_record_access_range(void const volatile *addr, size_t size); + +/// Records access to a memory address <c><i>addr</i></c>. +/// +/// This memory must be previously allocated by your program. +/// +/// \param addr Accessed memory address +void __memprof_record_access(void const volatile *addr); + +/// User-provided callback on MemProf errors. +/// +/// You can provide a function that would be called immediately when MemProf +/// detects an error. This is useful in cases when MemProf detects an error but +/// your program crashes before the MemProf report is printed. +void __memprof_on_error(void); + +/// Prints accumulated statistics to <c>stderr</c> (useful for calling from the +/// debugger). +void __memprof_print_accumulated_stats(void); + +/// User-provided default option settings. +/// +/// You can provide your own implementation of this function to return a string +/// containing MemProf runtime options (for example, +/// <c>verbosity=1:print_stats=1</c>). +/// +/// \returns Default options string. +const char *__memprof_default_options(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // SANITIZER_MEMPROF_INTERFACE_H |