malloc_dump_provider.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_
  5. #define BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_
  6. #include "base/macros.h"
  7. #include "base/memory/singleton.h"
  8. #include "base/synchronization/lock.h"
  9. #include "base/trace_event/memory_dump_provider.h"
  10. #include "build/build_config.h"
  11. #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) || \
  12. defined(OS_WIN) || defined(OS_MAC)
  13. #define MALLOC_MEMORY_TRACING_SUPPORTED
  14. #endif
  15. namespace base {
  16. namespace trace_event {
  17. // Dump provider which collects process-wide memory stats.
  18. class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider {
  19. public:
  20. // Name of the allocated_objects dump. Use this to declare suballocator dumps
  21. // from other dump providers.
  22. static const char kAllocatedObjects[];
  23. static MallocDumpProvider* GetInstance();
  24. // MemoryDumpProvider implementation.
  25. bool OnMemoryDump(const MemoryDumpArgs& args,
  26. ProcessMemoryDump* pmd) override;
  27. // Used by out-of-process heap-profiling. When malloc is profiled by an
  28. // external process, that process will be responsible for emitting metrics on
  29. // behalf of this one. Thus, MallocDumpProvider should not do anything.
  30. void EnableMetrics();
  31. void DisableMetrics();
  32. private:
  33. friend struct DefaultSingletonTraits<MallocDumpProvider>;
  34. MallocDumpProvider();
  35. ~MallocDumpProvider() override;
  36. bool emit_metrics_on_memory_dump_ = true;
  37. base::Lock emit_metrics_on_memory_dump_lock_;
  38. DISALLOW_COPY_AND_ASSIGN(MallocDumpProvider);
  39. };
  40. } // namespace trace_event
  41. } // namespace base
  42. #endif // BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_