Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: skia/ext/SkTraceMemoryDump_chrome.cc

Issue 1319473003: [tracing] Add SkResourceCache statistics to chrome://tracing (chrome side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@discardable_objdumps
Patch Set: Rebase. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: skia/ext/SkTraceMemoryDump_chrome.cc
diff --git a/skia/ext/SkTraceMemoryDump_chrome.cc b/skia/ext/SkTraceMemoryDump_chrome.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b55f5bd3affea40c567cf0726b2573ceb9488a9
--- /dev/null
+++ b/skia/ext/SkTraceMemoryDump_chrome.cc
@@ -0,0 +1,63 @@
+// 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/strings/string_util.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)
+ : 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 (base::CompareCaseInsensitiveASCII(backingType, kMallocBackingType) == 0) {
+ auto dump = GetOrCreateAllocatorDump(dumpName);
Primiano Tucci (use gerrit) 2015/08/30 18:28:36 why do we allow case insensitive compare here? I'd
ssid 2015/08/30 23:11:23 I mainly made it because skia could say malloc or
+ process_memory_dump_->AddSuballocation(
+ dump->guid(), base::trace_event::MemoryDumpManager::GetInstance()
+ ->system_allocator_pool_name());
+ }
+}
Primiano Tucci (use gerrit) 2015/08/30 18:28:36 also, please add a else{ NOTREACHED()} section at
ssid 2015/09/02 12:59:52 Done.
+
+void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking(
+ const char* dumpName,
+ const SkDiscardableMemory& discardableMemoryObject) {
+ DCHECK(!process_memory_dump_->GetAllocatorDump(dumpName));
+ const SkDiscardableMemoryChrome& discardable_memory_obj =
+ static_cast<const SkDiscardableMemoryChrome&>(discardableMemoryObject);
+ auto dump = discardable_memory_obj.CreateMemoryAllocatorDump(
Primiano Tucci (use gerrit) 2015/08/30 18:28:36 why are you not using the GetOrCreateAllocatorDump
ssid 2015/08/30 23:11:23 Yes it will fail if skia first calls dump and then
+ dumpName, process_memory_dump_);
+ DCHECK(dump);
+}
+
+base::trace_event::MemoryAllocatorDump*
+SkTraceMemoryDump_Chrome::GetOrCreateAllocatorDump(const char* dumpName) {
+ auto dump = process_memory_dump_->GetAllocatorDump(dumpName);
+ if (!dump)
+ dump = process_memory_dump_->CreateAllocatorDump(dumpName);
+ return dump;
+}
+
+} // namespace skia

Powered by Google App Engine
This is Rietveld 408576698