Skip to content

Commit

Permalink
[tracing] Adding Skia memory dump provider with cache totals
Browse files Browse the repository at this point in the history
This CL adds a dump provider to dump skia memory statistics to
chrome://tracing. The dump provider dumps only the totals of
SkGlyphCache and SkResourceCache.

BUG=503168

Review URL: https://codereview.chromium.org/1253403002

Cr-Commit-Position: refs/heads/master@{#340674}
  • Loading branch information
ssiddhartha authored and Commit bot committed Jul 28, 2015
1 parent 574c7ea commit 59c9691
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions content/browser/browser_main_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "net/base/network_change_notifier.h"
#include "net/socket/client_socket_factory.h"
#include "net/ssl/ssl_config_service.h"
#include "skia/ext/skia_memory_dump_provider.h"
#include "ui/base/clipboard/clipboard.h"

#if defined(USE_AURA) || (defined(OS_MACOSX) && !defined(OS_IOS))
Expand Down Expand Up @@ -631,6 +632,8 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
// Enable the dump providers.
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
HostSharedBitmapManager::current());
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
skia::SkiaMemoryDumpProvider::GetInstance());

#if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
trace_memory_controller_.reset(new base::trace_event::TraceMemoryController(
Expand Down
4 changes: 4 additions & 0 deletions content/renderer/render_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "base/threading/simple_thread.h"
#include "base/threading/thread_local.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "cc/base/switches.h"
Expand Down Expand Up @@ -128,6 +129,7 @@
#include "net/base/net_errors.h"
#include "net/base/port_util.h"
#include "skia/ext/event_tracer_impl.h"
#include "skia/ext/skia_memory_dump_provider.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebThread.h"
#include "third_party/WebKit/public/web/WebCache.h"
Expand Down Expand Up @@ -738,6 +740,8 @@ void RenderThreadImpl::Init() {
GetContentClient()->renderer()->RenderThreadStarted();

InitSkiaEventTracer();
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
skia::SkiaMemoryDumpProvider::GetInstance());

const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
Expand Down
2 changes: 2 additions & 0 deletions skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ component("skia") {
"ext/platform_device_mac.cc",
"ext/platform_device_win.cc",
"ext/recursive_gaussian_convolution.cc",
"ext/skia_memory_dump_provider.cc",
"ext/skia_utils_base.cc",
"ext/skia_utils_ios.mm",
"ext/skia_utils_mac.mm",
Expand Down Expand Up @@ -600,6 +601,7 @@ test("skia_unittests") {
"ext/platform_canvas_unittest.cc",
"ext/recursive_gaussian_convolution_unittest.cc",
"ext/refptr_unittest.cc",
"ext/skia_memory_dump_provider_unittest.cc",
"ext/skia_utils_ios_unittest.mm",
"ext/skia_utils_mac_unittest.mm",
]
Expand Down
42 changes: 42 additions & 0 deletions skia/ext/skia_memory_dump_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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_memory_dump_provider.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 "third_party/skia/include/core/SkGraphics.h"
#include "third_party/skia/src/core/SkResourceCache.h"

namespace skia {

// static
SkiaMemoryDumpProvider* SkiaMemoryDumpProvider::GetInstance() {
return Singleton<SkiaMemoryDumpProvider,
LeakySingletonTraits<SkiaMemoryDumpProvider>>::get();
}

SkiaMemoryDumpProvider::SkiaMemoryDumpProvider() {}

SkiaMemoryDumpProvider::~SkiaMemoryDumpProvider() {}

bool SkiaMemoryDumpProvider::OnMemoryDump(
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.

return true;
}

} // namespace skia
34 changes: 34 additions & 0 deletions skia/ext/skia_memory_dump_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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_SKIA_MEMORY_DUMP_PROVIDER_H_
#define SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_

#include "base/memory/singleton.h"
#include "base/trace_event/memory_dump_provider.h"
#include "third_party/skia/include/core/SkTypes.h"

namespace skia {

class SK_API SkiaMemoryDumpProvider
: public base::trace_event::MemoryDumpProvider {
public:
static SkiaMemoryDumpProvider* GetInstance();

// base::trace_event::MemoryDumpProvider implementation:
bool OnMemoryDump(
base::trace_event::ProcessMemoryDump* process_memory_dump) override;

private:
friend struct DefaultSingletonTraits<SkiaMemoryDumpProvider>;

SkiaMemoryDumpProvider();
~SkiaMemoryDumpProvider() override;

DISALLOW_COPY_AND_ASSIGN(SkiaMemoryDumpProvider);
};

} // namespace skia

#endif // SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_
21 changes: 21 additions & 0 deletions skia/ext/skia_memory_dump_provider_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 "base/trace_event/process_memory_dump.h"
#include "skia/ext/skia_memory_dump_provider.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace skia {

TEST(SkiaMemoryDumpProviderTest, OnMemoryDump) {
scoped_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
new base::trace_event::ProcessMemoryDump(nullptr));
SkiaMemoryDumpProvider::GetInstance()->OnMemoryDump(
process_memory_dump.get());

ASSERT_TRUE(process_memory_dump->GetAllocatorDump("skia/sk_font_cache"));
ASSERT_TRUE(process_memory_dump->GetAllocatorDump("skia/sk_resource_cache"));
}

} // namespace skia
1 change: 1 addition & 0 deletions skia/skia_chrome.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'ext/recursive_gaussian_convolution.cc',
'ext/SkDiscardableMemory_chrome.cc',
'ext/SkMemory_new_handler.cpp',
'ext/skia_memory_dump_provider.cc',
'ext/skia_utils_base.cc',
'ext/skia_utils_ios.mm',
'ext/skia_utils_mac.mm',
Expand Down
1 change: 1 addition & 0 deletions skia/skia_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'ext/platform_canvas_unittest.cc',
'ext/recursive_gaussian_convolution_unittest.cc',
'ext/refptr_unittest.cc',
'ext/skia_memory_dump_provider_unittest.cc',
'ext/skia_utils_ios_unittest.mm',
'ext/skia_utils_mac_unittest.mm',
],
Expand Down

0 comments on commit 59c9691

Please sign in to comment.