Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "public/platform/WebString.h" | |
| 10 #include "wtf/Partitions.h" | 11 #include "wtf/Partitions.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; |
| 17 | 18 |
| 18 const char kPartitionAllocDumpName[] = "partition_alloc"; | 19 const char kPartitionAllocDumpName[] = "partition_alloc"; |
| 19 const char kPartitionsDumpName[] = "partitions"; | 20 const char kPartitionsDumpName[] = "partitions"; |
| 20 | 21 |
| 21 String getPartitionDumpName(const char* partitionName) | 22 String getPartitionDumpName(const char* partitionName) |
| 22 { | 23 { |
| 23 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpNa me, partitionName); | 24 return String::format("%s/%s/%s", kPartitionAllocDumpName, kPartitionsDumpNa me, partitionName); |
| 24 } | 25 } |
| 25 | 26 |
| 27 std::string ToStdString(const String& str) { | |
| 28 return std::string(reinterpret_cast<const char*>(str.ascii().data())); | |
|
esprehn
2015/09/28 18:03:14
This cast doesn't make sense, data() is already a
Primiano Tucci (use gerrit)
2015/09/28 19:07:40
Yeah, just a leftover of doing character8() which
| |
| 29 } | |
| 30 | |
| 26 // This class is used to invert the dependency of PartitionAlloc on the | 31 // This class is used to invert the dependency of PartitionAlloc on the |
| 27 // PartitionAllocMemoryDumpProvider. This implements an interface that will | 32 // PartitionAllocMemoryDumpProvider. This implements an interface that will |
| 28 // be called with memory statistics for each bucket in the allocator. | 33 // be called with memory statistics for each bucket in the allocator. |
| 29 class PartitionStatsDumperImpl final : public PartitionStatsDumper { | 34 class PartitionStatsDumperImpl final : public PartitionStatsDumper { |
| 30 public: | 35 public: |
| 31 PartitionStatsDumperImpl(WebProcessMemoryDump* memoryDump, WebMemoryDumpLeve lOfDetail levelOfDetail) | 36 PartitionStatsDumperImpl(base::trace_event::ProcessMemoryDump* memoryDump, b ase::trace_event::MemoryDumpLevelOfDetail levelOfDetail) |
| 32 : m_memoryDump(memoryDump) | 37 : m_memoryDump(memoryDump) |
| 33 , m_uid(0) | 38 , m_uid(0) |
| 34 , m_totalActiveBytes(0) | 39 , m_totalActiveBytes(0) |
| 35 { | 40 { |
| 36 } | 41 } |
| 37 | 42 |
| 38 // PartitionStatsDumper implementation. | 43 // PartitionStatsDumper implementation. |
| 39 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override; | 44 void partitionDumpTotals(const char* partitionName, const PartitionMemorySta ts*) override; |
| 40 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override; | 45 void partitionsDumpBucketStats(const char* partitionName, const PartitionBuc ketMemoryStats*) override; |
| 41 | 46 |
| 42 size_t totalActiveBytes() const { return m_totalActiveBytes; } | 47 size_t totalActiveBytes() const { return m_totalActiveBytes; } |
| 43 | 48 |
| 44 private: | 49 private: |
| 45 WebProcessMemoryDump* m_memoryDump; | 50 base::trace_event::ProcessMemoryDump* m_memoryDump; |
| 46 unsigned long m_uid; | 51 unsigned long m_uid; |
| 47 size_t m_totalActiveBytes; | 52 size_t m_totalActiveBytes; |
| 48 }; | 53 }; |
| 49 | 54 |
| 50 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats) | 55 void PartitionStatsDumperImpl::partitionDumpTotals(const char* partitionName, co nst PartitionMemoryStats* memoryStats) |
| 51 { | 56 { |
| 52 m_totalActiveBytes += memoryStats->totalActiveBytes; | 57 m_totalActiveBytes += memoryStats->totalActiveBytes; |
| 53 String dumpName = getPartitionDumpName(partitionName); | 58 base::trace_event::MemoryAllocatorDump* allocatorDump = m_memoryDump->Create AllocatorDump(ToStdString(getPartitionDumpName(partitionName))); |
| 54 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName); | |
| 55 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); | 59 allocatorDump->AddScalar("size", "bytes", memoryStats->totalResidentBytes); |
| 56 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes); | 60 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->tot alActiveBytes); |
| 57 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes); | 61 allocatorDump->AddScalar("virtual_size", "bytes", memoryStats->totalMmappedB ytes); |
| 58 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes); | 62 allocatorDump->AddScalar("virtual_committed_size", "bytes", memoryStats->tot alCommittedBytes); |
| 59 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes); | 63 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->totalDe committableBytes); |
| 60 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes); | 64 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->totalDisc ardableBytes); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats) | 67 void PartitionStatsDumperImpl::partitionsDumpBucketStats(const char* partitionNa me, const PartitionBucketMemoryStats* memoryStats) |
| 64 { | 68 { |
| 65 ASSERT(memoryStats->isValid); | 69 ASSERT(memoryStats->isValid); |
| 66 String dumpName = getPartitionDumpName(partitionName); | 70 String dumpName = getPartitionDumpName(partitionName); |
| 67 if (memoryStats->isDirectMap) | 71 if (memoryStats->isDirectMap) |
| 68 dumpName.append(String::format("/directMap_%lu", ++m_uid)); | 72 dumpName.append(String::format("/directMap_%lu", ++m_uid)); |
| 69 else | 73 else |
| 70 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memor yStats->bucketSlotSize))); | 74 dumpName.append(String::format("/bucket_%u", static_cast<unsigned>(memor yStats->bucketSlotSize))); |
| 71 | 75 |
| 72 WebMemoryAllocatorDump* allocatorDump = m_memoryDump->createMemoryAllocatorD ump(dumpName); | 76 base::trace_event::MemoryAllocatorDump* allocatorDump = m_memoryDump->Create AllocatorDump(ToStdString(dumpName)); |
| 73 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes); | 77 allocatorDump->AddScalar("size", "bytes", memoryStats->residentBytes); |
| 74 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes); | 78 allocatorDump->AddScalar("allocated_objects_size", "bytes", memoryStats->act iveBytes); |
| 75 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize); | 79 allocatorDump->AddScalar("slot_size", "bytes", memoryStats->bucketSlotSize); |
| 76 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes); | 80 allocatorDump->AddScalar("decommittable_size", "bytes", memoryStats->decommi ttableBytes); |
| 77 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardab leBytes); | 81 allocatorDump->AddScalar("discardable_size", "bytes", memoryStats->discardab leBytes); |
| 78 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocated PageSize); | 82 allocatorDump->AddScalar("total_pages_size", "bytes", memoryStats->allocated PageSize); |
| 79 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePa ges); | 83 allocatorDump->AddScalar("active_pages", "objects", memoryStats->numActivePa ges); |
| 80 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages) ; | 84 allocatorDump->AddScalar("full_pages", "objects", memoryStats->numFullPages) ; |
| 81 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPage s); | 85 allocatorDump->AddScalar("empty_pages", "objects", memoryStats->numEmptyPage s); |
| 82 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages); | 86 allocatorDump->AddScalar("decommitted_pages", "objects", memoryStats->numDec ommittedPages); |
| 83 } | 87 } |
| 84 | 88 |
| 85 } // namespace | 89 } // namespace |
| 86 | 90 |
| 87 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() | 91 PartitionAllocMemoryDumpProvider* PartitionAllocMemoryDumpProvider::instance() |
| 88 { | 92 { |
| 89 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); | 93 DEFINE_STATIC_LOCAL(PartitionAllocMemoryDumpProvider, instance, ()); |
| 90 return &instance; | 94 return &instance; |
| 91 } | 95 } |
| 92 | 96 |
| 93 bool PartitionAllocMemoryDumpProvider::onMemoryDump(WebMemoryDumpLevelOfDetail l evelOfDetail, WebProcessMemoryDump* memoryDump) | 97 bool PartitionAllocMemoryDumpProvider::OnMemoryDump(const base::trace_event::Mem oryDumpArgs& args, |
| 98 base::trace_event::ProcessMemoryDump* memo ryDump) | |
| 94 { | 99 { |
| 95 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, levelOfDetail); | 100 PartitionStatsDumperImpl partitionStatsDumper(memoryDump, args.level_of_deta il); |
| 96 | 101 |
| 97 WebMemoryAllocatorDump* partitionsDump = memoryDump->createMemoryAllocatorDu mp( | 102 base::trace_event::MemoryAllocatorDump* partitionsDump = memoryDump->CreateA llocatorDump( |
| 98 String::format("%s/%s", kPartitionAllocDumpName, kPartitionsDumpName)); | 103 ToStdString(String::format("%s/%s", kPartitionAllocDumpName, kPartitions DumpName))); |
| 99 | 104 |
| 100 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. | 105 // This method calls memoryStats.partitionsDumpBucketStats with memory stati stics. |
| 101 WTF::Partitions::dumpMemoryStats(levelOfDetail == WebMemoryDumpLevelOfDetail ::Light, &partitionStatsDumper); | 106 WTF::Partitions::dumpMemoryStats(args.level_of_detail == base::trace_event:: MemoryDumpLevelOfDetail::LIGHT, &partitionStatsDumper); |
| 102 | 107 |
| 103 WebMemoryAllocatorDump* allocatedObjectsDump = memoryDump->createMemoryAlloc atorDump( | 108 base::trace_event::MemoryAllocatorDump* allocatedObjectsDump = memoryDump->C reateAllocatorDump( |
| 104 String::format("%s/allocated_objects", kPartitionAllocDumpName)); | 109 ToStdString(String::format("%s/allocated_objects", kPartitionAllocDumpNa me))); |
| 105 allocatedObjectsDump->AddScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); | 110 allocatedObjectsDump->AddScalar("size", "bytes", partitionStatsDumper.totalA ctiveBytes()); |
| 106 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); | 111 memoryDump->AddOwnershipEdge(allocatedObjectsDump->guid(), partitionsDump->g uid()); |
| 107 | 112 |
| 108 return true; | 113 return true; |
| 109 } | 114 } |
| 110 | 115 |
| 111 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() | 116 PartitionAllocMemoryDumpProvider::PartitionAllocMemoryDumpProvider() |
| 112 { | 117 { |
| 113 } | 118 } |
| 114 | 119 |
| 115 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() | 120 PartitionAllocMemoryDumpProvider::~PartitionAllocMemoryDumpProvider() |
| 116 { | 121 { |
| 117 } | 122 } |
| 118 | 123 |
| 119 } // namespace blink | 124 } // namespace blink |
| OLD | NEW |