Commit 203b334b authored by ssid's avatar ssid Committed by Commit bot

[tracing] Support BACKGROUND mode in MemoryCache dump provider

This CL adds support for BACKGROUND mode in MemoryCache dump provider,
where it just adds the total sizes of resources (given by encodedSize
of each resource).
This CL also fixes the image resources reporting which had a shared
buffer that was not reported in the ImageResource subclass.
It also fixes the SharedBuffer::onMemoryDump to dump when both shared
buffer and segments are used together.

BUG=629925

Review-Url: https://codereview.chromium.org/2337733002
Cr-Commit-Position: refs/heads/master@{#418957}
parent 76dfb1eb
...@@ -432,6 +432,14 @@ void ImageResource::finish(double loadFinishTime) ...@@ -432,6 +432,14 @@ void ImageResource::finish(double loadFinishTime)
Resource::finish(loadFinishTime); Resource::finish(loadFinishTime);
} }
void ImageResource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump) const
{
Resource::onMemoryDump(levelOfDetail, memoryDump);
const String name = getMemoryDumpName() + "/encoded_data";
if (m_image && !m_image->isNull())
m_image->data()->onMemoryDump(name, memoryDump);
}
void ImageResource::error(const ResourceError& error) void ImageResource::error(const ResourceError& error)
{ {
if (m_multipartParser) if (m_multipartParser)
......
...@@ -110,6 +110,8 @@ public: ...@@ -110,6 +110,8 @@ public:
void responseReceived(const ResourceResponse&, std::unique_ptr<WebDataConsumerHandle>) override; void responseReceived(const ResourceResponse&, std::unique_ptr<WebDataConsumerHandle>) override;
void finish(double finishTime = 0.0) override; void finish(double finishTime = 0.0) override;
void onMemoryDump(WebMemoryDumpLevelOfDetail, WebProcessMemoryDump*) const override;
// For compatibility, images keep loading even if there are HTTP errors. // For compatibility, images keep loading even if there are HTTP errors.
bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; } bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; }
......
...@@ -595,6 +595,7 @@ void MemoryCache::TypeStatistic::addResource(Resource* o) ...@@ -595,6 +595,7 @@ void MemoryCache::TypeStatistic::addResource(Resource* o)
liveSize += o->isAlive() ? o->size() : 0; liveSize += o->isAlive() ? o->size() : 0;
decodedSize += o->decodedSize(); decodedSize += o->decodedSize();
encodedSize += o->encodedSize(); encodedSize += o->encodedSize();
overheadSize += o->overheadSize();
encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSize() : 0; encodedSizeDuplicatedInDataURLs += o->url().protocolIsData() ? o->encodedSize() : 0;
} }
...@@ -732,6 +733,23 @@ void MemoryCache::updateFramePaintTimestamp() ...@@ -732,6 +733,23 @@ void MemoryCache::updateFramePaintTimestamp()
bool MemoryCache::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump) bool MemoryCache::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcessMemoryDump* memoryDump)
{ {
if (levelOfDetail == WebMemoryDumpLevelOfDetail::Background) {
Statistics stats = getStatistics();
WebMemoryAllocatorDump* dump1 = memoryDump->createMemoryAllocatorDump("web_cache/Image_resources");
dump1->addScalar("size", "bytes", stats.images.encodedSize + stats.images.overheadSize);
WebMemoryAllocatorDump* dump2 = memoryDump->createMemoryAllocatorDump("web_cache/CSS stylesheet_resources");
dump2->addScalar("size", "bytes", stats.cssStyleSheets.encodedSize + stats.cssStyleSheets.overheadSize);
WebMemoryAllocatorDump* dump3 = memoryDump->createMemoryAllocatorDump("web_cache/Script_resources");
dump3->addScalar("size", "bytes", stats.scripts.encodedSize + stats.scripts.overheadSize);
WebMemoryAllocatorDump* dump4 = memoryDump->createMemoryAllocatorDump("web_cache/XSL stylesheet_resources");
dump4->addScalar("size", "bytes", stats.xslStyleSheets.encodedSize + stats.xslStyleSheets.overheadSize);
WebMemoryAllocatorDump* dump5 = memoryDump->createMemoryAllocatorDump("web_cache/Font_resources");
dump5->addScalar("size", "bytes", stats.fonts.encodedSize + stats.fonts.overheadSize);
WebMemoryAllocatorDump* dump6 = memoryDump->createMemoryAllocatorDump("web_cache/Other_resources");
dump6->addScalar("size", "bytes", stats.other.encodedSize + stats.other.overheadSize);
return true;
}
for (const auto& resourceMapIter : m_resourceMaps) { for (const auto& resourceMapIter : m_resourceMaps) {
for (const auto& resourceIter : *resourceMapIter.value) { for (const auto& resourceIter : *resourceMapIter.value) {
Resource* resource = resourceIter.value->resource(); Resource* resource = resourceIter.value->resource();
......
...@@ -137,6 +137,7 @@ public: ...@@ -137,6 +137,7 @@ public:
size_t liveSize; size_t liveSize;
size_t decodedSize; size_t decodedSize;
size_t encodedSize; size_t encodedSize;
size_t overheadSize;
size_t encodedSizeDuplicatedInDataURLs; size_t encodedSizeDuplicatedInDataURLs;
TypeStatistic() TypeStatistic()
...@@ -145,6 +146,7 @@ public: ...@@ -145,6 +146,7 @@ public:
, liveSize(0) , liveSize(0)
, decodedSize(0) , decodedSize(0)
, encodedSize(0) , encodedSize(0)
, overheadSize(0)
, encodedSizeDuplicatedInDataURLs(0) , encodedSizeDuplicatedInDataURLs(0)
{ {
} }
......
...@@ -24,6 +24,9 @@ bool MemoryCacheDumpProvider::OnMemoryDump(const base::trace_event::MemoryDumpAr ...@@ -24,6 +24,9 @@ bool MemoryCacheDumpProvider::OnMemoryDump(const base::trace_event::MemoryDumpAr
WebMemoryDumpLevelOfDetail level; WebMemoryDumpLevelOfDetail level;
switch (args.level_of_detail) { switch (args.level_of_detail) {
case base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND:
level = blink::WebMemoryDumpLevelOfDetail::Background;
break;
case base::trace_event::MemoryDumpLevelOfDetail::LIGHT: case base::trace_event::MemoryDumpLevelOfDetail::LIGHT:
level = blink::WebMemoryDumpLevelOfDetail::Light; level = blink::WebMemoryDumpLevelOfDetail::Light;
break; break;
......
...@@ -275,12 +275,13 @@ void SharedBuffer::onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump* ...@@ -275,12 +275,13 @@ void SharedBuffer::onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*
WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpPrefix + "/shared_buffer"); WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpPrefix + "/shared_buffer");
dump->addScalar("size", "bytes", m_buffer.size()); dump->addScalar("size", "bytes", m_buffer.size());
memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
} else { }
if (m_segments.size()) {
// If there is data in the segments, then it should have been allocated // If there is data in the segments, then it should have been allocated
// using fastMalloc. // using fastMalloc.
const String dataDumpName = dumpPrefix + "/segments"; const String dataDumpName = dumpPrefix + "/segments";
auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName);
dump->addScalar("size", "bytes", m_size); dump->addScalar("size", "bytes", m_size - m_buffer.size());
memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllocatedObjectPoolName));
} }
} }
......
...@@ -39,6 +39,7 @@ namespace blink { ...@@ -39,6 +39,7 @@ namespace blink {
// TODO(hajimehoshi): Remove this and use base::trace_event:: // TODO(hajimehoshi): Remove this and use base::trace_event::
// MemoryDumpLevelOfDetail instead. // MemoryDumpLevelOfDetail instead.
enum class WebMemoryDumpLevelOfDetail { enum class WebMemoryDumpLevelOfDetail {
Background,
Light, Light,
Detailed Detailed
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment