OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/containers/small_map.h" |
| 11 |
| 12 namespace base { |
| 13 |
| 14 class RefCountedString; |
| 15 class Value; |
| 16 |
| 17 namespace trace_event { |
| 18 |
| 19 class ProcessMemoryDump; |
| 20 |
| 21 // Used to estimate the memory overhead of the tracing infrastructure. |
| 22 class BASE_EXPORT TraceEventMemoryOverhead { |
| 23 public: |
| 24 TraceEventMemoryOverhead(); |
| 25 ~TraceEventMemoryOverhead(); |
| 26 |
| 27 // Use this method to account the overhead of an object for which an estimate |
| 28 // is known for both the allocated and resident memory. |
| 29 void Add(const char* object_type, |
| 30 size_t allocated_size_in_bytes, |
| 31 size_t resident_size_in_bytes); |
| 32 |
| 33 // Similar to Add() above, but assumes that |
| 34 // |resident_size_in_bytes| == |allocated_size_in_bytes|. |
| 35 void Add(const char* object_type, size_t allocated_size_in_bytes); |
| 36 |
| 37 // Specialized profiling functions for commonly used object types. |
| 38 void AddString(const std::string& str); |
| 39 void AddValue(const Value& value); |
| 40 void AddRefCountedString(const RefCountedString& str); |
| 41 |
| 42 // Call this after all the Add* methods above to account the memory used by |
| 43 // this TraceEventMemoryOverhead instance itself. |
| 44 void AddSelf(); |
| 45 |
| 46 // Adds up and merges all the values from |other| to this instance. |
| 47 void Update(const TraceEventMemoryOverhead& other); |
| 48 |
| 49 void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const; |
| 50 |
| 51 private: |
| 52 struct ObjectCountAndSize { |
| 53 size_t count; |
| 54 size_t allocated_size_in_bytes; |
| 55 size_t resident_size_in_bytes; |
| 56 }; |
| 57 using map_type = SmallMap<hash_map<const char*, ObjectCountAndSize>, 16>; |
| 58 map_type allocated_objects_; |
| 59 |
| 60 void AddOrCreateInternal(const char* object_type, |
| 61 size_t count, |
| 62 size_t allocated_size_in_bytes, |
| 63 size_t resident_size_in_bytes); |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead); |
| 66 }; |
| 67 |
| 68 } // namespace trace_event |
| 69 } // namespace base |
| 70 |
| 71 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_ |
OLD | NEW |