base/threading: remove ScopedTracker placed for experiments
[chromium-blink-merge.git] / base / trace_event / trace_event_memory_overhead.h
blob8ecf12dc969eb4f0dc26516061450cff5d229509
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 // Adds up and merges all the values from |other| to this instance.
47 void Update(const TraceEventMemoryOverhead& other);
49 void DumpInto(const char* base_name, ProcessMemoryDump* pmd) const;
51 private:
52 struct ObjectCountAndSize {
53 size_t count;
54 size_t allocated_size_in_bytes;
55 size_t resident_size_in_bytes;
57 using map_type = SmallMap<hash_map<const char*, ObjectCountAndSize>, 16>;
58 map_type allocated_objects_;
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);
65 DISALLOW_COPY_AND_ASSIGN(TraceEventMemoryOverhead);
68 } // namespace trace_event
69 } // namespace base
71 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_OVERHEAD_H_