Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Side by Side Diff: base/trace_event/process_memory_dump.h

Issue 987043003: [tracing] Introduce support for userland memory allocators dumps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mmaps_en
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ 5 #ifndef BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ 6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/containers/small_map.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/trace_event/memory_allocator_dump.h"
9 #include "base/trace_event/process_memory_maps.h" 13 #include "base/trace_event/process_memory_maps.h"
10 #include "base/trace_event/process_memory_totals.h" 14 #include "base/trace_event/process_memory_totals.h"
11 15
12 namespace base { 16 namespace base {
13 namespace trace_event { 17 namespace trace_event {
14 18
15 class ConvertableToTraceFormat; 19 class ConvertableToTraceFormat;
20 class MemoryDumpManager;
16 21
17 // ProcessMemoryDump is as a strongly typed container which enforces the data 22 // ProcessMemoryDump is as a strongly typed container which enforces the data
18 // model for each memory dump point and holds the dumps produced by the 23 // model for each memory dump point and holds the dumps produced by the
19 // MemoryDumpProvider(s) for a specific process. 24 // MemoryDumpProvider(s) for a specific process.
20 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump 25 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump
21 // will compose a key-value dictionary of the various dumps obtained at trace 26 // will compose a key-value dictionary of the various dumps obtained at trace
22 // dump point time. 27 // dump point time.
23 class BASE_EXPORT ProcessMemoryDump { 28 class BASE_EXPORT ProcessMemoryDump {
24 public: 29 public:
30 using AllocatorDumpsMap =
31 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>;
32
25 ProcessMemoryDump(); 33 ProcessMemoryDump();
26 ~ProcessMemoryDump(); 34 ~ProcessMemoryDump();
27 35
28 // Called at trace generation time to populate the TracedValue. 36 // Called at trace generation time to populate the TracedValue.
29 void AsValueInto(TracedValue* value) const; 37 void AsValueInto(TracedValue* value) const;
30 38
31 ProcessMemoryTotals* process_totals() { return &process_totals_; } 39 ProcessMemoryTotals* process_totals() { return &process_totals_; }
32 bool has_process_totals() const { return has_process_totals_; } 40 bool has_process_totals() const { return has_process_totals_; }
33 void set_has_process_totals() { has_process_totals_ = true; } 41 void set_has_process_totals() { has_process_totals_ = true; }
34 42
35 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } 43 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; }
36 bool has_process_mmaps() const { return has_process_mmaps_; } 44 bool has_process_mmaps() const { return has_process_mmaps_; }
37 void set_has_process_mmaps() { has_process_mmaps_ = true; } 45 void set_has_process_mmaps() { has_process_mmaps_ = true; }
38 46
47 // Creates a new MemoryAllocatorDump with the given name and returns the
48 // empty object back to the caller. The |name| must be unique in the dump.
49 // ProcessMemoryDump handles the memory ownership of the created object.
50 // |parent| can be used to specify a hierarchical relationship of the
51 // allocator dumps.
52 MemoryAllocatorDump* AddAllocatorDump(const std::string& name);
nduca 2015/03/12 04:04:10 Add->Create?
Primiano Tucci (use gerrit) 2015/03/13 19:39:07 Done.
53 MemoryAllocatorDump* AddAllocatorDump(const std::string& name,
54 MemoryAllocatorDump* parent);
55
56 // Returns a MemoryAllocatorDump given its name or nullptr if not found.
57 MemoryAllocatorDump* GetAllocatorDump(const std::string& name) const;
58
59 // Returns the map of the MemoryAllocatorDumps added to this dump.
60 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; }
61
62 protected:
63 // TODO(primiano): remove this once crbug.com/466121 gets fixed (see similar
64 // comment in memory_dump_manager.cc) for more context.
65 friend class MemoryDumpManager;
66 MemoryAllocatorDump* last_allocator_dump() const {
67 return allocator_dumps_storage_.empty() ? nullptr
68 : allocator_dumps_storage_.back();
69 }
70
39 private: 71 private:
40 ProcessMemoryTotals process_totals_; 72 ProcessMemoryTotals process_totals_;
41 bool has_process_totals_; 73 bool has_process_totals_;
42 74
43 ProcessMemoryMaps process_mmaps_; 75 ProcessMemoryMaps process_mmaps_;
44 bool has_process_mmaps_; 76 bool has_process_mmaps_;
45 77
78 // A maps of "allocator_name" -> MemoryAllocatorDump populated by
79 // allocator dump providers.
80 AllocatorDumpsMap allocator_dumps_;
81
82 // ProcessMemoryDump handles the memory ownership of all its belongings.
83 ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_;
84
46 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); 85 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump);
47 }; 86 };
48 87
49 } // namespace trace_event 88 } // namespace trace_event
50 } // namespace base 89 } // namespace base
51 90
52 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ 91 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698