| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | |
| 6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/base_export.h" | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/trace_event/memory_allocator_dump_guid.h" | |
| 15 #include "base/values.h" | |
| 16 | |
| 17 namespace base { | |
| 18 namespace trace_event { | |
| 19 | |
| 20 class MemoryDumpManager; | |
| 21 class ProcessMemoryDump; | |
| 22 class TracedValue; | |
| 23 | |
| 24 // Data model for user-land memory allocator dumps. | |
| 25 class BASE_EXPORT MemoryAllocatorDump { | |
| 26 public: | |
| 27 // MemoryAllocatorDump is owned by ProcessMemoryDump. | |
| 28 MemoryAllocatorDump(const std::string& absolute_name, | |
| 29 ProcessMemoryDump* process_memory_dump, | |
| 30 const MemoryAllocatorDumpGuid& guid); | |
| 31 MemoryAllocatorDump(const std::string& absolute_name, | |
| 32 ProcessMemoryDump* process_memory_dump); | |
| 33 ~MemoryAllocatorDump(); | |
| 34 | |
| 35 // Standard attribute |name|s for the AddScalar and AddString() methods. | |
| 36 static const char kNameSize[]; // To represent allocated space. | |
| 37 static const char kNameObjectsCount[]; // To represent number of objects. | |
| 38 | |
| 39 // Standard attribute |unit|s for the AddScalar and AddString() methods. | |
| 40 static const char kUnitsBytes[]; // Unit name to represent bytes. | |
| 41 static const char kUnitsObjects[]; // Unit name to represent #objects. | |
| 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 | |
| 58 // Absolute name, unique within the scope of an entire ProcessMemoryDump. | |
| 59 const std::string& absolute_name() const { return absolute_name_; } | |
| 60 | |
| 61 // Called at trace generation time to populate the TracedValue. | |
| 62 void AsValueInto(TracedValue* value) const; | |
| 63 | |
| 64 // Get the ProcessMemoryDump instance that owns this. | |
| 65 ProcessMemoryDump* process_memory_dump() const { | |
| 66 return process_memory_dump_; | |
| 67 } | |
| 68 | |
| 69 // |guid| is an optional global dump identifier, unique across all processes | |
| 70 // within the scope of a global dump. It is only required when using the | |
| 71 // graph APIs (see TODO_method_name) to express retention / suballocation or | |
| 72 // cross process sharing. See crbug.com/492102 for design docs. | |
| 73 // Subsequent MemoryAllocatorDump(s) with the same |absolute_name| are | |
| 74 // expected to have the same guid. | |
| 75 const MemoryAllocatorDumpGuid& guid() const { return guid_; } | |
| 76 | |
| 77 TracedValue* attributes_for_testing() const { return attributes_.get(); } | |
| 78 | |
| 79 private: | |
| 80 const std::string absolute_name_; | |
| 81 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this). | |
| 82 scoped_refptr<TracedValue> attributes_; | |
| 83 MemoryAllocatorDumpGuid guid_; | |
| 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 | |
| 89 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); | |
| 90 }; | |
| 91 | |
| 92 } // namespace trace_event | |
| 93 } // namespace base | |
| 94 | |
| 95 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | |
| OLD | NEW |