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

Side by Side Diff: third_party/WebKit/Source/platform/PartitionAllocMemoryDumpProvider.cpp

Issue 1375643002: [tracing] directly use memory-infra from blink -> base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 #include "config.h" 5 #include "config.h"
6 #include "platform/PartitionAllocMemoryDumpProvider.h" 6 #include "platform/PartitionAllocMemoryDumpProvider.h"
7 7
8 #include "public/platform/WebMemoryAllocatorDump.h" 8 #include "base/trace_event/memory_allocator_dump.h"
9 #include "public/platform/WebProcessMemoryDump.h" 9 #include "base/trace_event/process_memory_dump.h"
10 #include "wtf/Partitions.h" 10 #include "wtf/Partitions.h"
11 #include "wtf/text/WTFString.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 namespace { 15 namespace {
15 16
16 using namespace WTF; 17 using namespace WTF;
18 using base::trace_event::MemoryAllocatorDump;
17 19
18 const char kPartitionAllocDumpName[] = "partition_alloc"; 20 const char kPartitionAllocDumpName[] = "partition_alloc";
19 const char kPartitionsDumpName[] = "partitions"; 21 const char kPartitionsDumpName[] = "partitions";
20 22
21 String getPartitionDumpName(const char* partitionName) 23 String getPartitionDumpName(const char* partitionName)
22 { 24 {
23 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpNa me, partitionName); 25 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpNa me, partitionName);
24 } 26 }
25 27
26 // This class is used to invert the dependency of PartitionAlloc on the 28 // This class is used to invert the dependency of PartitionAlloc on the
27 // PartitionAllocMemoryDumpProvider. This implements an interface that will 29 // PartitionAllocMemoryDumpProvider. This implements an interface that will
28 // be called with memory statistics for each bucket in the allocator. 30 // be called with memory statistics for each bucket in the allocator.
29 class PartitionStatsDumperImpl final : public PartitionStatsDumper { 31 class PartitionStatsDumperImpl final : public PartitionStatsDumper {
30 public: 32 public:
31 PartitionStatsDumperImpl(WebProcessMemoryDump* memoryDump, WebMemoryDumpLeve lOfDetail levelOfDetail) 33 PartitionStatsDumperImpl(base::trace_event::ProcessMemoryDump* memoryDump, b ase::trace_event::MemoryDumpLevelOfDetail levelOfDetail)
32 : m_memoryDump(memoryDump) 34 : m_memoryDump(memoryDump)
33 , m_uid(0) 35 , m_uid(0)
34 , m_totalActiveBytes(0) 36 , m_totalActiveBytes(0)
35 { 37 {
36 } 38 }
37 39
38 // PartitionStatsDumper implementation. 40 // PartitionStatsDumper implementation.
39 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override; 41 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override;
40 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override; 42 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override;
41 43
42 size_t totalActiveBytes() const { return m_totalActiveBytes; } 44 size_t totalActiveBytes() const { return m_totalActiveBytes; }
43 45
44 private: 46 private:
45 WebProcessMemoryDump* m_memoryDump; 47 base::trace_event::ProcessMemoryDump* m_memoryDump;
46 unsigned long m_uid; 48 unsigned long m_uid;
47 size_t m_totalActiveBytes; 49 size_t m_totalActiveBytes;
48 }; 50 };
49 51
50 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats) 52 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats)
51 { 53 {
52 m_totalActiveBytes += memoryStats->totalActiveBytes; 54 m_totalActiveBytes += memoryStats->totalActiveBytes;
53 String dumpName = getPartitionDumpName(partitionName); 55 MemoryAllocatorDump* allocatorDump = m_memoryDump->CreateAllocatorDump(getPa rtitionDumpName(partitionName).toUTF8StdString());
54 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName);
55 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); 56 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes);
56 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes); 57 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes);
57 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes); 58 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes);
58 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes); 59 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes);
59 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes); 60 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes);
60 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes); 61 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes);
61 } 62 }
62 63
63 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats) 64 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats)
64 { 65 {
65 ASSERT(memoryStats->isValid); 66 ASSERT(memoryStats->isValid);
66 String dumpName = getPartitionDumpName(partitionName); 67 String dumpName = getPartitionDumpName(partitionName);
67 if (memoryStats->isDirectMap) 68 if (memoryStats->isDirectMap)
68 dumpName.append(String::format("/directMap_%lu", ++m_uid)); 69 dumpName.append(String::format("/directMap_%lu", ++m_uid));
69 else 70 else
70 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memor yStats->bucketSlotSize))); 71 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memor yStats->bucketSlotSize)));
71 72
72 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName); 73 MemoryAllocatorDump* allocatorDump = m_memoryDump->CreateAllocatorDump(dumpN ame.toUTF8StdString());
73 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes); 74 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes);
74 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes); 75 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes);
75 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize); 76 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize);
76 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes); 77 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes);
77 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardab leBytes); 78 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardab leBytes);
78 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocated PageSize); 79 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocated PageSize);
79 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePa ges); 80 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePa ges);
80 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages) ; 81 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages) ;
81 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPage s); 82 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPage s);
82 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages); 83 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages);
83 } 84 }
84 85
85 } // namespace 86 } // namespace
86 87
87 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() 88 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance()
88 { 89 {
89 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); 90 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ());
90 return &instance; 91 return &instance;
91 } 92 }
92 93
93 bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail l evelOfDetail, WebProcessMemoryDump* memoryDump) 94 bool PartitionAllocMemoryDumpProvider::OnMemoryDump(const base::trace_event::Mem oryDumpArgs& args,
95 base::trace_event::ProcessMemoryDump* memoryDump)
94 { 96 {
95 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail); 97 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, args.level_of_deta il);
96 98
97 WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDu mp( 99 MemoryAllocatorDump* partitionsDump = memoryDump->CreateAllocatorDump(
98 String::format("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName)); 100 String::format("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName).to UTF8StdString());
99 101
100 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. 102 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics.
101 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail ::Light, &partitionStatsDumper); 103 WTF::Partitions::dumpMemoryStats(args.level_of_detail == base::trace_event:: MemoryDumpLevelOfDetail::LIGHT, &partitionStatsDumper);
102 104
103 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAlloc atorDump(String(Partitions::kAllocatedObjectPoolName)); 105 MemoryAllocatorDump* allocatedObjectsDump = memoryDump->CreateAllocatorDump( Partitions::kAllocatedObjectPoolName);
104 allocatedObjectsDump->AddScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); 106 allocatedObjectsDump->AddScalar(MemoryAllocatorDump::kNameSize, MemoryAlloca torDump::kUnitsBytes, partitionStatsDumper.totalActiveBytes());
105 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); 107 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid());
106 108
107 return true; 109 return true;
108 } 110 }
109 111
110 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() 112 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider()
111 { 113 {
112 } 114 }
113 115
114 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() 116 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider()
115 { 117 {
116 } 118 }
117 119
118 } // namespace blink 120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698