xref: /freebsd/contrib/llvm-project/compiler-rt/include/sanitizer/memprof_interface.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1e8d8bef9SDimitry Andric //===-- sanitizer/memprof_interface.h --------------------------*- C++ -*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric //
9e8d8bef9SDimitry Andric // This file is a part of MemProfiler (MemProf).
10e8d8bef9SDimitry Andric //
11e8d8bef9SDimitry Andric // Public interface header.
12e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
13e8d8bef9SDimitry Andric #ifndef SANITIZER_MEMPROF_INTERFACE_H
14e8d8bef9SDimitry Andric #define SANITIZER_MEMPROF_INTERFACE_H
15e8d8bef9SDimitry Andric 
16e8d8bef9SDimitry Andric #include <sanitizer/common_interface_defs.h>
17e8d8bef9SDimitry Andric 
18e8d8bef9SDimitry Andric #ifdef __cplusplus
19e8d8bef9SDimitry Andric extern "C" {
20e8d8bef9SDimitry Andric #endif
21e8d8bef9SDimitry Andric /// Records access to a memory region (<c>[addr, addr+size)</c>).
22e8d8bef9SDimitry Andric ///
23e8d8bef9SDimitry Andric /// This memory must be previously allocated by your program.
24e8d8bef9SDimitry Andric ///
25e8d8bef9SDimitry Andric /// \param addr Start of memory region.
26e8d8bef9SDimitry Andric /// \param size Size of memory region.
27*5f757f3fSDimitry Andric void SANITIZER_CDECL __memprof_record_access_range(void const volatile *addr,
28*5f757f3fSDimitry Andric                                                    size_t size);
29e8d8bef9SDimitry Andric 
30e8d8bef9SDimitry Andric /// Records access to a memory address <c><i>addr</i></c>.
31e8d8bef9SDimitry Andric ///
32e8d8bef9SDimitry Andric /// This memory must be previously allocated by your program.
33e8d8bef9SDimitry Andric ///
34e8d8bef9SDimitry Andric /// \param addr Accessed memory address
35*5f757f3fSDimitry Andric void SANITIZER_CDECL __memprof_record_access(void const volatile *addr);
36e8d8bef9SDimitry Andric 
37e8d8bef9SDimitry Andric /// User-provided callback on MemProf errors.
38e8d8bef9SDimitry Andric ///
39e8d8bef9SDimitry Andric /// You can provide a function that would be called immediately when MemProf
40e8d8bef9SDimitry Andric /// detects an error. This is useful in cases when MemProf detects an error but
41e8d8bef9SDimitry Andric /// your program crashes before the MemProf report is printed.
42*5f757f3fSDimitry Andric void SANITIZER_CDECL __memprof_on_error(void);
43e8d8bef9SDimitry Andric 
44e8d8bef9SDimitry Andric /// Prints accumulated statistics to <c>stderr</c> (useful for calling from the
45e8d8bef9SDimitry Andric /// debugger).
46*5f757f3fSDimitry Andric void SANITIZER_CDECL __memprof_print_accumulated_stats(void);
47e8d8bef9SDimitry Andric 
48e8d8bef9SDimitry Andric /// User-provided default option settings.
49e8d8bef9SDimitry Andric ///
50e8d8bef9SDimitry Andric /// You can provide your own implementation of this function to return a string
51e8d8bef9SDimitry Andric /// containing MemProf runtime options (for example,
52e8d8bef9SDimitry Andric /// <c>verbosity=1:print_stats=1</c>).
53e8d8bef9SDimitry Andric ///
54e8d8bef9SDimitry Andric /// \returns Default options string.
55*5f757f3fSDimitry Andric const char *SANITIZER_CDECL __memprof_default_options(void);
56e8d8bef9SDimitry Andric 
57e8d8bef9SDimitry Andric /// Prints the memory profile to the current profile file.
58e8d8bef9SDimitry Andric ///
59e8d8bef9SDimitry Andric /// \returns 0 on success.
60*5f757f3fSDimitry Andric int SANITIZER_CDECL __memprof_profile_dump(void);
61*5f757f3fSDimitry Andric 
62*5f757f3fSDimitry Andric /// Closes the existing file descriptor, if it is valid and not stdout or
63*5f757f3fSDimitry Andric /// stderr, and resets the internal state such that the profile filename is
64*5f757f3fSDimitry Andric /// reopened on the next profile dump attempt. This can be used to enable
65*5f757f3fSDimitry Andric /// multiple rounds of profiling on the same binary.
66*5f757f3fSDimitry Andric void SANITIZER_CDECL __memprof_profile_reset(void);
67e8d8bef9SDimitry Andric 
68e8d8bef9SDimitry Andric #ifdef __cplusplus
69e8d8bef9SDimitry Andric } // extern "C"
70e8d8bef9SDimitry Andric #endif
71e8d8bef9SDimitry Andric 
72e8d8bef9SDimitry Andric #endif // SANITIZER_MEMPROF_INTERFACE_H
73