| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ | 6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 9 | 10 |
| 10 #include <unordered_map> | 11 #include <unordered_map> |
| 11 | 12 |
| 12 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 13 #include "base/containers/hash_tables.h" | |
| 14 #include "base/containers/small_map.h" | |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 | 17 |
| 19 class RefCountedString; | 18 class RefCountedString; |
| 20 class Value; | 19 class Value; |
| 21 | 20 |
| 22 namespace trace_event { | 21 namespace trace_event { |
| 23 | 22 |
| 24 class ProcessMemoryDump; | 23 class ProcessMemoryDump; |
| 25 | 24 |
| 26 // Used to estimate the memory overhead of the tracing infrastructure. | 25 // Used to estimate the memory overhead of the tracing infrastructure. |
| 27 class BASE_EXPORT TraceEventMemoryOverhead { | 26 class BASE_EXPORT TraceEventMemoryOverhead { |
| 28 public: | 27 public: |
| 28 enum ObjectType : uint32_t { |
| 29 kOther = 0, |
| 30 kTraceBuffer, |
| 31 kTraceBufferChunk, |
| 32 kTraceEvent, |
| 33 kUnusedTraceEvent, |
| 34 kTracedValue, |
| 35 kConvertableToTraceFormat, |
| 36 kHeapProfilerAllocationRegister, |
| 37 kHeapProfilerTypeNameDeduplicator, |
| 38 kHeapProfilerStackFrameDeduplicator, |
| 39 kStdString, |
| 40 kBaseValue, |
| 41 kTraceEventMemoryOverhead, |
| 42 kLast |
| 43 }; |
| 44 |
| 29 TraceEventMemoryOverhead(); | 45 TraceEventMemoryOverhead(); |
| 30 ~TraceEventMemoryOverhead(); | 46 ~TraceEventMemoryOverhead(); |
| 31 | 47 |
| 32 // Use this method to account the overhead of an object for which an estimate | 48 // Use this method to account the overhead of an object for which an estimate |
| 33 // is known for both the allocated and resident memory. | 49 // is known for both the allocated and resident memory. |
| 34 void Add(const char* object_type, | 50 void Add(ObjectType object_type, |
| 35 size_t allocated_size_in_bytes, | 51 size_t allocated_size_in_bytes, |
| 36 size_t resident_size_in_bytes); | 52 size_t resident_size_in_bytes); |
| 37 | 53 |
| 38 // Similar to Add() above, but assumes that | 54 // Similar to Add() above, but assumes that |
| 39 // |resident_size_in_bytes| == |allocated_size_in_bytes|. | 55 // |resident_size_in_bytes| == |allocated_size_in_bytes|. |
| 40 void Add(const char* object_type, size_t allocated_size_in_bytes); | 56 void Add(ObjectType object_type, size_t allocated_size_in_bytes); |
| 41 | 57 |
| 42 // Specialized profiling functions for commonly used object types. | 58 // Specialized profiling functions for commonly used object types. |
| 43 void AddString(const std::string& str); | 59 void AddString(const std::string& str); |
| 44 void AddValue(const Value& value); | 60 void AddValue(const Value& value); |
| 45 void AddRefCountedString(const RefCountedString& str); | 61 void AddRefCountedString(const RefCountedString& str); |
| 46 | 62 |
| 47 // Call this after all the Add* methods above to account the memory used by | 63 // Call this after all the Add* methods above to account the memory used by |
| 48 // this TraceEventMemoryOverhead instance itself. | 64 // this TraceEventMemoryOverhead instance itself. |
| 49 void AddSelf(); | 65 void AddSelf(); |
| 50 | 66 |
| 51 // Retrieves the count, that is, the count of Add*(|object_type|, ...) calls. | 67 // Retrieves the count, that is, the count of Add*(|object_type|, ...) calls. |
| 52 size_t GetCount(const char* object_type) const; | 68 size_t GetCount(ObjectType object_type) const; |
| 53 | 69 |
| 54 // Adds up and merges all the values from |other| to this instance. | 70 // Adds up and merges all the values from |other| to this instance. |
| 55 void Update(const TraceEventMemoryOverhead& other); | 71 void Update(const TraceEventMemoryOverhead& other); |
| 56 | 72 |
| 57 void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const; | 73 void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const; |
| 58 | 74 |
| 59 private: | 75 private: |
| 60 struct ObjectCountAndSize { | 76 struct ObjectCountAndSize { |
| 61 size_t count; | 77 size_t count; |
| 62 size_t allocated_size_in_bytes; | 78 size_t allocated_size_in_bytes; |
| 63 size_t resident_size_in_bytes; | 79 size_t resident_size_in_bytes; |
| 64 }; | 80 }; |
| 65 using map_type = | 81 ObjectCountAndSize allocated_objects_[ObjectType::kLast]; |
| 66 small_map<std::unordered_map<const char*, ObjectCountAndSize>, 16>; | |
| 67 map_type allocated_objects_; | |
| 68 | 82 |
| 69 void AddOrCreateInternal(const char* object_type, | 83 void AddInternal(ObjectType object_type, |
| 70 size_t count, | 84 size_t count, |
| 71 size_t allocated_size_in_bytes, | 85 size_t allocated_size_in_bytes, |
| 72 size_t resident_size_in_bytes); | 86 size_t resident_size_in_bytes); |
| 73 | 87 |
| 74 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead); | 88 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead); |
| 75 }; | 89 }; |
| 76 | 90 |
| 77 } // namespace trace_event | 91 } // namespace trace_event |
| 78 } // namespace base | 92 } // namespace base |
| 79 | 93 |
| 80 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ | 94 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
| OLD | NEW |