Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / base / trace_event / trace_event_memory_overhead.h
blob25853d11d1284d7658085fe6125e72b6fcd97d8c
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.
5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_
6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_
8 #include "base/base_export.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/containers/small_map.h"
12 namespace base {
14 class RefCountedString;
15 class Value;
17 namespace trace_event {
19 class ProcessMemoryDump;
21 // Used to estimate the memory overhead of the tracing infrastructure.
22 class BASE_EXPORT TraceEventMemoryOverhead {
23 public:
24 TraceEventMemoryOverhead();
25 ~TraceEventMemoryOverhead();
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);
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);
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);
42 // Call this after all the Add* methods above to account the memory used by
43 // this TraceEventMemoryOverhead instance itself.
44 void AddSelf();
46 // Retrieves the count, that is, the count of Add*(|object_type|, ...) calls.
47 size_t GetCount(const char* object_type) const;
49 // Adds up and merges all the values from |other| to this instance.
50 void Update(const TraceEventMemoryOverhead& other);
52 void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const;
54 private:
55 struct ObjectCountAndSize {
56 size_t count;
57 size_t allocated_size_in_bytes;
58 size_t resident_size_in_bytes;
60 using map_type = SmallMap<hash_map<const char*, ObjectCountAndSize>, 16>;
61 map_type allocated_objects_;
63 void AddOrCreateInternal(const char* object_type,
64 size_t count,
65 size_t allocated_size_in_bytes,
66 size_t resident_size_in_bytes);
68 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead);
71 } // namespace trace_event
72 } // namespace base
74 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_