memprof_stack.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- memprof_stack.cpp ------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of MemProfiler, a memory profiler.
  10. //
  11. // Code for MemProf stack trace.
  12. //===----------------------------------------------------------------------===//
  13. #include "memprof_stack.h"
  14. #include "memprof_internal.h"
  15. #include "sanitizer_common/sanitizer_atomic.h"
  16. namespace __memprof {
  17. static atomic_uint32_t malloc_context_size;
  18. void SetMallocContextSize(u32 size) {
  19. atomic_store(&malloc_context_size, size, memory_order_release);
  20. }
  21. u32 GetMallocContextSize() {
  22. return atomic_load(&malloc_context_size, memory_order_acquire);
  23. }
  24. } // namespace __memprof
  25. void __sanitizer::BufferedStackTrace::UnwindImpl(uptr pc, uptr bp,
  26. void *context,
  27. bool request_fast,
  28. u32 max_depth) {
  29. using namespace __memprof;
  30. size = 0;
  31. if (UNLIKELY(!memprof_inited))
  32. return;
  33. request_fast = StackTrace::WillUseFastUnwind(request_fast);
  34. MemprofThread *t = GetCurrentThread();
  35. if (request_fast) {
  36. if (t) {
  37. Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(),
  38. true);
  39. }
  40. return;
  41. }
  42. Unwind(max_depth, pc, bp, context, 0, 0, false);
  43. }
  44. // ------------------ Interface -------------- {{{1
  45. extern "C" {
  46. SANITIZER_INTERFACE_ATTRIBUTE
  47. void __sanitizer_print_stack_trace() {
  48. using namespace __memprof;
  49. PRINT_CURRENT_STACK();
  50. }
  51. } // extern "C"