[tracing] Add infrastructure to account memory overhead of tracing.
[chromium-blink-merge.git] / base / trace_event / trace_event_memory_overhead.h
blob99a8beb303fcba3efba620272015facb3d6ca1b9
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 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.
34 void AddSelf();
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;
41 private:
42 struct ObjectCountAndSize {
43 size_t count;
44 size_t size_in_bytes;
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,
52 size_t count,
53 size_t size_in_bytes);
55 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead);
58 } // namespace trace_event
59 } // namespace base
61 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_