diff options
author | ssid <ssid@chromium.org> | 2015-09-03 12:10:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-03 19:10:42 +0000 |
commit | 70405030c538d9075a7ddaf7ba212e4be3b558cf (patch) | |
tree | 41a44a3fc925f2b7d33ba75fbd95d8929327af67 /skia | |
parent | cbf0dc0aa638da93f90810af77f3f7607c5146a1 (diff) | |
download | chromium_src-70405030c538d9075a7ddaf7ba212e4be3b558cf.zip chromium_src-70405030c538d9075a7ddaf7ba212e4be3b558cf.tar.gz chromium_src-70405030c538d9075a7ddaf7ba212e4be3b558cf.tar.bz2 |
[tracing] Add SkResourceCache statistics to chrome://tracing (chrome side)
This CL adds the statistics of SkResourceCache to tracing.
See crrev.com/1313793004 for the skia side changes.
BUG=503168
Review URL: https://codereview.chromium.org/1319473003
Cr-Commit-Position: refs/heads/master@{#347207}
Diffstat (limited to 'skia')
-rw-r--r-- | skia/BUILD.gn | 1 | ||||
-rw-r--r-- | skia/ext/SkDiscardableMemory_chrome.cc | 7 | ||||
-rw-r--r-- | skia/ext/SkDiscardableMemory_chrome.h | 10 | ||||
-rw-r--r-- | skia/ext/SkTraceMemoryDump_chrome.cc | 76 | ||||
-rw-r--r-- | skia/ext/SkTraceMemoryDump_chrome.h | 68 | ||||
-rw-r--r-- | skia/ext/skia_memory_dump_provider.cc | 27 | ||||
-rw-r--r-- | skia/ext/skia_memory_dump_provider_unittest.cc | 4 | ||||
-rw-r--r-- | skia/skia_chrome.gypi | 1 |
8 files changed, 181 insertions, 13 deletions
diff --git a/skia/BUILD.gn b/skia/BUILD.gn index 6a4af4c..1e566ed 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -280,6 +280,7 @@ component("skia") { # Chrome sources. "ext/SkDiscardableMemory_chrome.cc", "ext/SkMemory_new_handler.cpp", + "ext/SkTraceMemoryDump_chrome.cc", "ext/analysis_canvas.cc", "ext/benchmarking_canvas.cc", "ext/convolver.cc", diff --git a/skia/ext/SkDiscardableMemory_chrome.cc b/skia/ext/SkDiscardableMemory_chrome.cc index 1a98720..30a7f93 100644 --- a/skia/ext/SkDiscardableMemory_chrome.cc +++ b/skia/ext/SkDiscardableMemory_chrome.cc @@ -26,6 +26,13 @@ SkDiscardableMemoryChrome::SkDiscardableMemoryChrome( : discardable_(memory.Pass()) { } +base::trace_event::MemoryAllocatorDump* +SkDiscardableMemoryChrome::CreateMemoryAllocatorDump( + const char* name, + base::trace_event::ProcessMemoryDump* pmd) const { + return discardable_->CreateMemoryAllocatorDump(name, pmd); +} + SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) { return new SkDiscardableMemoryChrome( base::DiscardableMemoryAllocator::GetInstance() diff --git a/skia/ext/SkDiscardableMemory_chrome.h b/skia/ext/SkDiscardableMemory_chrome.h index 1be4516..93a7807 100644 --- a/skia/ext/SkDiscardableMemory_chrome.h +++ b/skia/ext/SkDiscardableMemory_chrome.h @@ -10,8 +10,14 @@ namespace base { class DiscardableMemory; + +namespace trace_event { +class MemoryAllocatorDump; +class ProcessMemoryDump; } +} // namespace base + // This class implements the SkDiscardableMemory interface using // base::DiscardableMemory. class SK_API SkDiscardableMemoryChrome : public SkDiscardableMemory { @@ -23,6 +29,10 @@ public: void* data() override; void unlock() override; + base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( + const char* name, + base::trace_event::ProcessMemoryDump* pmd) const; + private: friend class SkDiscardableMemory; diff --git a/skia/ext/SkTraceMemoryDump_chrome.cc b/skia/ext/SkTraceMemoryDump_chrome.cc new file mode 100644 index 0000000..a530904 --- /dev/null +++ b/skia/ext/SkTraceMemoryDump_chrome.cc @@ -0,0 +1,76 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/SkTraceMemoryDump_chrome.h" + +#include "base/trace_event/memory_allocator_dump.h" +#include "base/trace_event/memory_dump_manager.h" +#include "base/trace_event/process_memory_dump.h" +#include "skia/ext/SkDiscardableMemory_chrome.h" + +namespace skia { + +namespace { +const char kMallocBackingType[] = "malloc"; +} + +SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( + base::trace_event::ProcessMemoryDump* process_memory_dump) + : SkTraceMemoryDump_Chrome("", process_memory_dump) {} + +SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( + const char* dump_name_prefix, + base::trace_event::ProcessMemoryDump* process_memory_dump) + : dump_name_prefix_(dump_name_prefix), + process_memory_dump_(process_memory_dump) {} + +SkTraceMemoryDump_Chrome::~SkTraceMemoryDump_Chrome() {} + +void SkTraceMemoryDump_Chrome::dumpNumericValue(const char* dumpName, + const char* valueName, + const char* units, + uint64_t value) { + auto dump = GetOrCreateAllocatorDump(dumpName); + dump->AddScalar(valueName, units, value); +} + +void SkTraceMemoryDump_Chrome::setMemoryBacking(const char* dumpName, + const char* backingType, + const char* backingObjectId) { + if (strcmp(backingType, kMallocBackingType) == 0) { + auto dump = GetOrCreateAllocatorDump(dumpName); + const char* system_allocator_name = + base::trace_event::MemoryDumpManager::GetInstance() + ->system_allocator_pool_name(); + if (system_allocator_name) { + process_memory_dump_->AddSuballocation(dump->guid(), + system_allocator_name); + } + } else { + NOTREACHED(); + } +} + +void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking( + const char* dumpName, + const SkDiscardableMemory& discardableMemoryObject) { + std::string name = dump_name_prefix_ + dumpName; + DCHECK(!process_memory_dump_->GetAllocatorDump(name)); + const SkDiscardableMemoryChrome& discardable_memory_obj = + static_cast<const SkDiscardableMemoryChrome&>(discardableMemoryObject); + auto dump = discardable_memory_obj.CreateMemoryAllocatorDump( + name.c_str(), process_memory_dump_); + DCHECK(dump); +} + +base::trace_event::MemoryAllocatorDump* +SkTraceMemoryDump_Chrome::GetOrCreateAllocatorDump(const char* dumpName) { + std::string name = dump_name_prefix_ + dumpName; + auto dump = process_memory_dump_->GetAllocatorDump(name); + if (!dump) + dump = process_memory_dump_->CreateAllocatorDump(name); + return dump; +} + +} // namespace skia diff --git a/skia/ext/SkTraceMemoryDump_chrome.h b/skia/ext/SkTraceMemoryDump_chrome.h new file mode 100644 index 0000000..dcdfc8f --- /dev/null +++ b/skia/ext/SkTraceMemoryDump_chrome.h @@ -0,0 +1,68 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SKIA_EXT_SK_TRACE_MEMORY_DUMP_CHROME_H_ +#define SKIA_EXT_SK_TRACE_MEMORY_DUMP_CHROME_H_ + +#include <string> + +#include "base/macros.h" +#include "third_party/skia/include/core/SkTraceMemoryDump.h" + +namespace base { +namespace trace_event { +class MemoryAllocatorDump; +class ProcessMemoryDump; +} +} + +namespace skia { + +class SkTraceMemoryDump_Chrome : public SkTraceMemoryDump { + public: + // This should never outlive the OnMemoryDump call since the + // ProcessMemoryDump is valid only in that timeframe. Optional + // |dump_name_prefix| argument specifies the prefix appended to the dump + // name skia provides. By defualt it is taken as empty string. + SkTraceMemoryDump_Chrome( + base::trace_event::ProcessMemoryDump* process_memory_dump); + + SkTraceMemoryDump_Chrome( + const char* dump_name_prefix, + base::trace_event::ProcessMemoryDump* process_memory_dump); + + ~SkTraceMemoryDump_Chrome() override; + + // SkTraceMemoryDump implementation: + void dumpNumericValue(const char* dumpName, + const char* valueName, + const char* units, + uint64_t value) override; + void setMemoryBacking(const char* dumpName, + const char* backingType, + const char* backingObjectId) override; + void setDiscardableMemoryBacking( + const char* dumpName, + const SkDiscardableMemory& discardableMemoryObject) override; + + protected: + base::trace_event::ProcessMemoryDump* process_memory_dump() { + return process_memory_dump_; + } + + private: + base::trace_event::ProcessMemoryDump* process_memory_dump_; + + std::string dump_name_prefix_; + + // Helper to create allocator dumps. + base::trace_event::MemoryAllocatorDump* GetOrCreateAllocatorDump( + const char* dumpName); + + DISALLOW_COPY_AND_ASSIGN(SkTraceMemoryDump_Chrome); +}; + +} // namespace skia + +#endif // SKIA_EXT_SK_TRACE_MEMORY_DUMP_CHROME_H_ diff --git a/skia/ext/skia_memory_dump_provider.cc b/skia/ext/skia_memory_dump_provider.cc index 3944ad4..1323699 100644 --- a/skia/ext/skia_memory_dump_provider.cc +++ b/skia/ext/skia_memory_dump_provider.cc @@ -7,6 +7,7 @@ #include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/process_memory_dump.h" +#include "skia/ext/SkTraceMemoryDump_chrome.h" #include "third_party/skia/include/core/SkGraphics.h" #include "third_party/skia/src/core/SkResourceCache.h" @@ -25,17 +26,21 @@ SkiaMemoryDumpProvider::~SkiaMemoryDumpProvider() {} bool SkiaMemoryDumpProvider::OnMemoryDump( const base::trace_event::MemoryDumpArgs& args, base::trace_event::ProcessMemoryDump* process_memory_dump) { - auto font_mad = - process_memory_dump->CreateAllocatorDump("skia/sk_font_cache"); - font_mad->AddScalar("size", "bytes", SkGraphics::GetFontCacheUsed()); - font_mad->AddScalar("count", "objects", SkGraphics::GetFontCacheCountUsed()); - - auto resource_mad = - process_memory_dump->CreateAllocatorDump("skia/sk_resource_cache"); - resource_mad->AddScalar("size", "bytes", - SkResourceCache::GetTotalBytesUsed()); - // TODO(ssid): crbug.com/503168. Add sub-allocation edges from discardable or - // malloc memory dumps to avoid double counting. + base::trace_event::MemoryAllocatorDump* font_mad = + process_memory_dump->CreateAllocatorDump("skia/sk_glyph_cache"); + font_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, + base::trace_event::MemoryAllocatorDump::kUnitsBytes, + SkGraphics::GetFontCacheUsed()); + font_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectsCount, + base::trace_event::MemoryAllocatorDump::kUnitsObjects, + SkGraphics::GetFontCacheCountUsed()); + + if (args.level_of_detail == + base::trace_event::MemoryDumpArgs::LevelOfDetail::LOW) + return true; + + SkTraceMemoryDump_Chrome skia_dumper(process_memory_dump); + SkGraphics::DumpMemoryStatistics(&skia_dumper); return true; } diff --git a/skia/ext/skia_memory_dump_provider_unittest.cc b/skia/ext/skia_memory_dump_provider_unittest.cc index 3432f18..915323b 100644 --- a/skia/ext/skia_memory_dump_provider_unittest.cc +++ b/skia/ext/skia_memory_dump_provider_unittest.cc @@ -8,6 +8,7 @@ namespace skia { +// Tests if the skia dump provider dumps without crashing. TEST(SkiaMemoryDumpProviderTest, OnMemoryDump) { scoped_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( new base::trace_event::ProcessMemoryDump(nullptr)); @@ -16,8 +17,7 @@ TEST(SkiaMemoryDumpProviderTest, OnMemoryDump) { SkiaMemoryDumpProvider::GetInstance()->OnMemoryDump( dump_args, process_memory_dump.get()); - ASSERT_TRUE(process_memory_dump->GetAllocatorDump("skia/sk_font_cache")); - ASSERT_TRUE(process_memory_dump->GetAllocatorDump("skia/sk_resource_cache")); + ASSERT_TRUE(process_memory_dump->GetAllocatorDump("skia/sk_glyph_cache")); } } // namespace skia diff --git a/skia/skia_chrome.gypi b/skia/skia_chrome.gypi index 9efc631..f6c2faf 100644 --- a/skia/skia_chrome.gypi +++ b/skia/skia_chrome.gypi @@ -49,6 +49,7 @@ 'ext/recursive_gaussian_convolution.cc', 'ext/SkDiscardableMemory_chrome.cc', 'ext/SkMemory_new_handler.cpp', + 'ext/SkTraceMemoryDump_chrome.cc', 'ext/skia_memory_dump_provider.cc', 'ext/skia_utils_base.cc', 'ext/skia_utils_ios.mm', |