trace_event_memory_overhead.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_TRACE_EVENT_MEMORY_OVERHEAD_H_
  5. #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <string>
  9. #include "base/base_export.h"
  10. namespace base {
  11. class RefCountedString;
  12. class Value;
  13. namespace trace_event {
  14. class ProcessMemoryDump;
  15. // Used to estimate the memory overhead of the tracing infrastructure.
  16. class BASE_EXPORT TraceEventMemoryOverhead {
  17. public:
  18. enum ObjectType : uint32_t {
  19. kOther = 0,
  20. kTraceBuffer,
  21. kTraceBufferChunk,
  22. kTraceEvent,
  23. kUnusedTraceEvent,
  24. kTracedValue,
  25. kConvertableToTraceFormat,
  26. kHeapProfilerAllocationRegister,
  27. kHeapProfilerTypeNameDeduplicator,
  28. kHeapProfilerStackFrameDeduplicator,
  29. kStdString,
  30. kBaseValue,
  31. kTraceEventMemoryOverhead,
  32. kFrameMetrics,
  33. kLast
  34. };
  35. TraceEventMemoryOverhead();
  36. TraceEventMemoryOverhead(const TraceEventMemoryOverhead&) = delete;
  37. TraceEventMemoryOverhead& operator=(const TraceEventMemoryOverhead&) = delete;
  38. ~TraceEventMemoryOverhead();
  39. // Use this method to account the overhead of an object for which an estimate
  40. // is known for both the allocated and resident memory.
  41. void Add(ObjectType object_type,
  42. size_t allocated_size_in_bytes,
  43. size_t resident_size_in_bytes);
  44. // Similar to Add() above, but assumes that
  45. // |resident_size_in_bytes| == |allocated_size_in_bytes|.
  46. void Add(ObjectType object_type, size_t allocated_size_in_bytes);
  47. // Specialized profiling functions for commonly used object types.
  48. void AddString(const std::string& str);
  49. void AddValue(const Value& value);
  50. void AddRefCountedString(const RefCountedString& str);
  51. // Call this after all the Add* methods above to account the memory used by
  52. // this TraceEventMemoryOverhead instance itself.
  53. void AddSelf();
  54. // Retrieves the count, that is, the count of Add*(|object_type|, ...) calls.
  55. size_t GetCount(ObjectType object_type) const;
  56. // Adds up and merges all the values from |other| to this instance.
  57. void Update(const TraceEventMemoryOverhead& other);
  58. void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const;
  59. private:
  60. struct ObjectCountAndSize {
  61. size_t count;
  62. size_t allocated_size_in_bytes;
  63. size_t resident_size_in_bytes;
  64. };
  65. ObjectCountAndSize allocated_objects_[ObjectType::kLast];
  66. void AddInternal(ObjectType object_type,
  67. size_t count,
  68. size_t allocated_size_in_bytes,
  69. size_t resident_size_in_bytes);
  70. };
  71. } // namespace trace_event
  72. } // namespace base
  73. #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_