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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/memory_allocator_dump.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_MEMORY_ALLOCATOR_DUMP_H_ 5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ 6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
7 7
8 #include <string>
9
8 #include "base/base_export.h" 10 #include "base/base_export.h"
9 #include "base/basictypes.h" 11 #include "base/basictypes.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h"
11 #include "base/trace_event/memory_allocator_dump_guid.h" 14 #include "base/trace_event/memory_allocator_dump_guid.h"
12 #include "base/values.h" 15 #include "base/values.h"
13 16
14 namespace base { 17 namespace base {
15 namespace trace_event { 18 namespace trace_event {
16 19
17 class MemoryDumpManager; 20 class MemoryDumpManager;
18 class ProcessMemoryDump; 21 class ProcessMemoryDump;
19 class TracedValue; 22 class TracedValue;
20 23
21 // Data model for user-land memory allocator dumps. 24 // Data model for user-land memory allocator dumps.
22 class BASE_EXPORT MemoryAllocatorDump { 25 class BASE_EXPORT MemoryAllocatorDump {
23 public: 26 public:
24 // MemoryAllocatorDump is owned by ProcessMemoryDump. 27 // MemoryAllocatorDump is owned by ProcessMemoryDump.
25 MemoryAllocatorDump(const std::string& absolute_name, 28 MemoryAllocatorDump(const std::string& absolute_name,
26 ProcessMemoryDump* process_memory_dump, 29 ProcessMemoryDump* process_memory_dump,
27 const MemoryAllocatorDumpGuid& guid); 30 const MemoryAllocatorDumpGuid& guid);
28 MemoryAllocatorDump(const std::string& absolute_name, 31 MemoryAllocatorDump(const std::string& absolute_name,
29 ProcessMemoryDump* process_memory_dump); 32 ProcessMemoryDump* process_memory_dump);
30 ~MemoryAllocatorDump(); 33 ~MemoryAllocatorDump();
31 34
32 // Standard attribute name to model allocated space. 35 // Standard attribute |name|s for the AddScalar and AddString() methods.
33 static const char kNameSize[]; 36 static const char kNameSize[]; // To represent allocated space.
37 static const char kNameObjectsCount[]; // To represent number of objects.
34 38
35 // Standard attribute name to model total space requested by the allocator 39 // Standard attribute |unit|s for the AddScalar and AddString() methods.
36 // (e.g., amount of pages requested to the system).
37 static const char kNameOuterSize[];
38
39 // Standard attribute name to model space for allocated objects, without
40 // taking into account allocator metadata or fragmentation.
41 static const char kNameInnerSize[];
42
43 // Standard attribute name to model the number of objects allocated.
44 static const char kNameObjectsCount[];
45
46 static const char kTypeScalar[]; // Type name for scalar attributes.
47 static const char kTypeString[]; // Type name for string attributes.
48 static const char kUnitsBytes[]; // Unit name to represent bytes. 40 static const char kUnitsBytes[]; // Unit name to represent bytes.
49 static const char kUnitsObjects[]; // Unit name to represent #objects. 41 static const char kUnitsObjects[]; // Unit name to represent #objects.
50 42
43 // Constants used only internally and by tests.
44 static const char kTypeScalar[]; // Type name for scalar attributes.
45 static const char kTypeString[]; // Type name for string attributes.
46
47 // Setters for scalar attributes. Some examples:
48 // - "size" column (all dumps are expected to have at least this one):
49 // AddScalar(kNameSize, kUnitsBytes, 1234);
50 // - Some extra-column reporting internal details of the subsystem:
51 // AddScalar("number_of_freelist_entires", kUnitsObjects, 42)
52 // - Other informational column (will not be auto-added in the UI)
53 // AddScalarF("kittens_ratio", "ratio", 42.0f)
54 void AddScalar(const char* name, const char* units, uint64 value);
55 void AddScalarF(const char* name, const char* units, double value);
56 void AddString(const char* name, const char* units, const std::string& value);
57
51 // Absolute name, unique within the scope of an entire ProcessMemoryDump. 58 // Absolute name, unique within the scope of an entire ProcessMemoryDump.
52 const std::string& absolute_name() const { return absolute_name_; } 59 const std::string& absolute_name() const { return absolute_name_; }
53 60
54 // Generic attribute setter / getter.
55 void Add(const std::string& name,
56 const char* type,
57 const char* units,
58 scoped_ptr<Value> value);
59 bool Get(const std::string& name,
60 const char** out_type,
61 const char** out_units,
62 const Value** out_value) const;
63
64 // Helper setter for scalar attributes.
65 void AddScalar(const std::string& name, const char* units, uint64 value);
66 void AddScalarF(const std::string& name, const char* units, double value);
67 void AddString(const std::string& name,
68 const char* units,
69 const std::string& value);
70
71 // Called at trace generation time to populate the TracedValue. 61 // Called at trace generation time to populate the TracedValue.
72 void AsValueInto(TracedValue* value) const; 62 void AsValueInto(TracedValue* value) const;
73 63
74 // Get the ProcessMemoryDump instance that owns this. 64 // Get the ProcessMemoryDump instance that owns this.
75 ProcessMemoryDump* process_memory_dump() const { 65 ProcessMemoryDump* process_memory_dump() const {
76 return process_memory_dump_; 66 return process_memory_dump_;
77 } 67 }
78 68
79 // |guid| is an optional global dump identifier, unique across all processes 69 // |guid| is an optional global dump identifier, unique across all processes
80 // within the scope of a global dump. It is only required when using the 70 // within the scope of a global dump. It is only required when using the
81 // graph APIs (see TODO_method_name) to express retention / suballocation or 71 // graph APIs (see TODO_method_name) to express retention / suballocation or
82 // cross process sharing. See crbug.com/492102 for design docs. 72 // cross process sharing. See crbug.com/492102 for design docs.
83 // Subsequent MemoryAllocatorDump(s) with the same |absolute_name| are 73 // Subsequent MemoryAllocatorDump(s) with the same |absolute_name| are
84 // expected to have the same guid. 74 // expected to have the same guid.
85 const MemoryAllocatorDumpGuid& guid() const { return guid_; } 75 const MemoryAllocatorDumpGuid& guid() const { return guid_; }
86 76
77 TracedValue* attributes_for_testing() const { return attributes_.get(); }
78
87 private: 79 private:
88 const std::string absolute_name_; 80 const std::string absolute_name_;
89 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this). 81 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this).
90 DictionaryValue attributes_; 82 scoped_refptr<TracedValue> attributes_;
91 MemoryAllocatorDumpGuid guid_; 83 MemoryAllocatorDumpGuid guid_;
92 84
85 // A local buffer for Sprintf conversion on fastpath. Avoids allocating
86 // temporary strings on each AddScalar() call.
87 std::string string_conversion_buffer_;
88
93 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); 89 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump);
94 }; 90 };
95 91
96 } // namespace trace_event 92 } // namespace trace_event
97 } // namespace base 93 } // namespace base
98 94
99 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ 95 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
OLDNEW
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/memory_allocator_dump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698