aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar primiano <primiano@chromium.org>2015-08-20 08:00:32 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-20 08:00:32 -0700
commit9a5bd7e860a6b132146e0247c0da0a1510225b97 (patch)
tree95d3668816956d8452a9dceffc0220e01df87160
parent99fe82260633fcf5d92cca38d12ef0937ecca61c (diff)
Introduce interface for memory dumps
BUG=chromium:503168 Review URL: https://codereview.chromium.org/1300103004
-rw-r--r--include/core/SkTraceMemoryDump.h62
-rw-r--r--tests/TraceMemoryDumpTest.cpp32
2 files changed, 94 insertions, 0 deletions
diff --git a/include/core/SkTraceMemoryDump.h b/include/core/SkTraceMemoryDump.h
new file mode 100644
index 0000000000..d7c565f570
--- /dev/null
+++ b/include/core/SkTraceMemoryDump.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTraceMemoryDump_DEFINED
+#define SkTraceMemoryDump_DEFINED
+
+#include "SkTypes.h"
+
+class SkDiscardableMemory;
+
+/**
+ * Interface for memory tracing.
+ * This interface is meant to be passed as argument to the memory dump methods of Skia objects.
+ * The implementation of this interface is provided by the embedder.
+ */
+class SK_API SkTraceMemoryDump {
+public:
+ /**
+ * Appends a new memory dump (i.e. a row) to the trace memory infrastructure.
+ * If dumpName does not exist yet, a new one is created. Otherwise, a new column is appended to
+ * the previously created dump.
+ * Arguments:
+ * dumpName: an absolute, slash-separated, name for the item being dumped
+ * e.g., "skia/CacheX/EntryY".
+ * valueName: a string indicating the name of the column.
+ * e.g., "size", "active_size", "number_of_objects".
+ * This string is supposed to be long lived and is NOT copied.
+ * units: a string indicating the units for the value.
+ * e.g., "bytes", "objects".
+ * This string is supposed to be long lived and is NOT copied.
+ * value: the actual value being dumped.
+ */
+ virtual void dumpNumericValue(const char* dumpName,
+ const char* valueName,
+ const char* units,
+ uint64_t value) = 0;
+
+ /**
+ * Sets the memory backing for an existing dump.
+ * backingType and backingObjectId are used by the embedder to associate the memory dumped via
+ * dumpNumericValue with the corresponding dump that backs the memory.
+ */
+ virtual void setMemoryBacking(const char* dumpName,
+ const char* backingType,
+ const char* backingObjectId) = 0;
+
+ /**
+ * Specialization for memory backed by discardable memory.
+ */
+ virtual void setDiscardableMemoryBacking(
+ const char* dumpName,
+ const SkDiscardableMemory& discardableMemoryObject) = 0;
+
+protected:
+ virtual ~SkTraceMemoryDump() { }
+};
+
+#endif
diff --git a/tests/TraceMemoryDumpTest.cpp b/tests/TraceMemoryDumpTest.cpp
new file mode 100644
index 0000000000..cda0076318
--- /dev/null
+++ b/tests/TraceMemoryDumpTest.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTraceMemoryDump.h"
+
+#include "Test.h"
+
+/*
+ * Build test for SkTraceMemoryDump.
+ */
+class TestSkTraceMemoryDump : public SkTraceMemoryDump {
+public:
+ TestSkTraceMemoryDump() { }
+ ~TestSkTraceMemoryDump() override { }
+
+ 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 { }
+};
+
+DEF_TEST(SkTraceMemoryDump, reporter) {
+ TestSkTraceMemoryDump x;
+ x.dumpNumericValue("foobar", "size", "bytes", 42);
+}