Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / PartitionAllocMemoryDumpProvider.cpp
blob3f5dd7c48d0177125c6eb69e26ee4419b34ee1dc
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 #include "config.h"
6 #include "platform/PartitionAllocMemoryDumpProvider.h"
8 #include "public/platform/WebMemoryAllocatorDump.h"
9 #include "public/platform/WebProcessMemoryDump.h"
10 #include "wtf/Partitions.h"
12 namespace blink {
14 namespace {
16 using namespace WTF;
18 const char kPartitionAllocDumpName[] = "partition_alloc";
19 const char kPartitionsDumpName[] = "partitions";
21 String getPartitionDumpName(const char* partitionName)
23 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpName, partitionName);
26 // This class is used to invert the dependency of PartitionAlloc on the
27 // PartitionAllocMemoryDumpProvider. This implements an interface that will
28 // be called with memory statistics for each bucket in the allocator.
29 class PartitionStatsDumperImpl final : public PartitionStatsDumper {
30 public:
31 PartitionStatsDumperImpl(WebProcessMemoryDump* memoryDump, WebMemoryDumpLevelOfDetail levelOfDetail)
32 : m_memoryDump(memoryDump)
33 , m_uid(0)
34 , m_totalActiveBytes(0)
38 // PartitionStatsDumper implementation.
39 void partitionDumpTotals(const char* partitionName, const PartitionMemoryStats*) override;
40 void partitionsDumpBucketStats(const char* partitionName, const PartitionBucketMemoryStats*) override;
42 size_t totalActiveBytes() const { return m_totalActiveBytes; }
44 private:
45 WebProcessMemoryDump* m_memoryDump;
46 unsigned long m_uid;
47 size_t m_totalActiveBytes;
50 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, const PartitionMemoryStats* memoryStats)
52 m_totalActiveBytes += memoryStats->totalActiveBytes;
53 String dumpName = getPartitionDumpName(partitionName);
54 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorDump(dumpName);
55 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes);
56 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->totalActiveBytes);
57 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedBytes);
58 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->totalCommittedBytes);
59 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDecommittableBytes);
60 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDiscardableBytes);
63 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionName, const PartitionBucketMemoryStats* memoryStats)
65 ASSERT(memoryStats->isValid);
66 String dumpName = getPartitionDumpName(partitionName);
67 if (memoryStats->isDirectMap)
68 dumpName.append(String::format("/directMap_%lu", ++m_uid));
69 else
70 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memoryStats->bucketSlotSize)));
72 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorDump(dumpName);
73 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes);
74 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->activeBytes);
75 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize);
76 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommittableBytes);
77 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardableBytes);
78 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocatedPageSize);
79 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePages);
80 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages);
81 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPages);
82 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDecommittedPages);
85 } // namespace
87 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance()
89 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ());
90 return &instance;
93 bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump)
95 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail);
97 WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDump(
98 String::format("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName));
100 // This method calls memoryStats.partitionsDumpBucketStats with memory statistics.
101 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail::Light, &partitionStatsDumper);
103 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAllocatorDump(
104 String::format("%s/allocated_objects", kPartitionAllocDumpName));
105 allocatedObjectsDump->AddScalar("size", "bytes", partitionStatsDumper.totalActiveBytes());
106 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->guid());
108 return true;
111 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider()
115 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider()
119 } // namespace blink