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"
14 class RefCountedString
;
17 namespace trace_event
{
19 class ProcessMemoryDump
;
21 // Used to estimate the memory overhead of the tracing infrastructure.
22 class BASE_EXPORT TraceEventMemoryOverhead
{
24 TraceEventMemoryOverhead();
25 ~TraceEventMemoryOverhead();
27 void Add(const char* object_type
, size_t size_in_bytes
);
28 void AddString(const std::string
& str
);
29 void AddValue(const Value
& value
);
30 void AddRefCountedString(const RefCountedString
& str
);
32 // Call this after all the Add* methods above to account the memory used by
33 // this TraceEventMemoryOverhead instance itself.
36 // Adds up and merges all the values from |other| to this instance.
37 void Update(const TraceEventMemoryOverhead
& other
);
39 void DumpInto(const char* base_name
, ProcessMemoryDump
* pmd
) const;
42 struct ObjectCountAndSize
{
46 #define TRACE_EVENT_MEMORY_OVERHEAD_MAP_SIZE 16
47 using map_type
= SmallMap
<hash_map
<const char*, ObjectCountAndSize
>,
48 TRACE_EVENT_MEMORY_OVERHEAD_MAP_SIZE
>;
49 map_type allocated_objects_
;
51 void AddOrCreateInternal(const char* object_type
,
53 size_t size_in_bytes
);
55 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead
);
58 } // namespace trace_event
61 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_