aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkTraceMemoryDump.h18
-rw-r--r--src/core/SkGlyphCache.cpp19
-rw-r--r--src/core/SkResourceCache.cpp10
-rw-r--r--tests/TraceMemoryDumpTest.cpp6
4 files changed, 42 insertions, 11 deletions
diff --git a/include/core/SkTraceMemoryDump.h b/include/core/SkTraceMemoryDump.h
index d7c565f570..8383190ccc 100644
--- a/include/core/SkTraceMemoryDump.h
+++ b/include/core/SkTraceMemoryDump.h
@@ -20,6 +20,17 @@ class SkDiscardableMemory;
class SK_API SkTraceMemoryDump {
public:
/**
+ * Enum to specify the level of the requested details for the dump from the Skia objects.
+ */
+ enum LevelOfDetail {
+ // Dump only the minimal details to get the total memory usage (Usually just the totals).
+ kLight_LevelOfDetail,
+
+ // Dump the detailed breakdown of the objects in the caches.
+ kObjectsBreakdowns_LevelOfDetail
+ };
+
+ /**
* 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.
@@ -55,6 +66,13 @@ public:
const char* dumpName,
const SkDiscardableMemory& discardableMemoryObject) = 0;
+ /**
+ * Returns the type of details requested in the dump. The granularity of the dump is supposed to
+ * match the LevelOfDetail argument. The level of detail must not affect the total size
+ * reported, but only granularity of the child entries.
+ */
+ virtual LevelOfDetail getRequestedDetails() const = 0;
+
protected:
virtual ~SkTraceMemoryDump() { }
};
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 9bee4e5f75..3f64d6ed48 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -427,16 +427,16 @@ static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) {
*counter += 1;
const SkTypeface* face = cache.getScalerContext()->getTypeface();
- SkString font_name;
- face->getFamilyName(&font_name);
+ SkString fontName;
+ face->getFamilyName(&fontName);
const SkScalerContextRec& rec = cache.getScalerContext()->getRec();
- SkString dump_name = SkStringPrintf("%s/%s_%3d/index_%d",
- gGlyphCacheDumpName, font_name.c_str(), rec.fFontID, index);
+ SkString dumpName = SkStringPrintf("%s/%s_%3d/index_%d",
+ gGlyphCacheDumpName, fontName.c_str(), rec.fFontID, index);
- dump->dumpNumericValue(dump_name.c_str(), "size", "bytes", cache.getMemoryUsed());
- dump->dumpNumericValue(dump_name.c_str(), "glyph_count", "objects", cache.countCachedGlyphs());
- dump->setMemoryBacking(dump_name.c_str(), "malloc", nullptr);
+ dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUsed());
+ dump->dumpNumericValue(dumpName.c_str(), "glyph_count", "objects", cache.countCachedGlyphs());
+ dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
}
void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
@@ -448,6 +448,11 @@ void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
dump->dumpNumericValue(gGlyphCacheDumpName, "budget_glyph_count", "objects",
SkGraphics::GetFontCacheCountLimit());
+ if (dump->getRequestedDetails() == SkTraceMemoryDump::kLight_LevelOfDetail) {
+ dump->setMemoryBacking(gGlyphCacheDumpName, "malloc", nullptr);
+ return;
+ }
+
int counter = 0;
SkGlyphCacheDumpContext context = { &counter, dump };
SkGlyphCache::VisitAll(sk_trace_dump_visitor, &context);
diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp
index 54091f1fd4..a1234e1fef 100644
--- a/src/core/SkResourceCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -675,16 +675,18 @@ void SkResourceCache::TestDumpMemoryStatistics() {
static void sk_trace_dump_visitor(const SkResourceCache::Rec& rec, void* context) {
SkTraceMemoryDump* dump = static_cast<SkTraceMemoryDump*>(context);
- SkString dump_name = SkStringPrintf("skia/sk_resource_cache/%s_%p", rec.getCategory(), &rec);
+ SkString dumpName = SkStringPrintf("skia/sk_resource_cache/%s_%p", rec.getCategory(), &rec);
SkDiscardableMemory* discardable = rec.diagnostic_only_getDiscardable();
if (discardable) {
- dump->setDiscardableMemoryBacking(dump_name.c_str(), *discardable);
+ dump->setDiscardableMemoryBacking(dumpName.c_str(), *discardable);
} else {
- dump->dumpNumericValue(dump_name.c_str(), "size", "bytes", rec.bytesUsed());
- dump->setMemoryBacking(dump_name.c_str(), "malloc", nullptr);
+ dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed());
+ dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
}
}
void SkResourceCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
+ // Since resource could be backed by malloc or discardable, the cache always dumps detailed
+ // stats to be accurate.
VisitAll(sk_trace_dump_visitor, dump);
}
diff --git a/tests/TraceMemoryDumpTest.cpp b/tests/TraceMemoryDumpTest.cpp
index cda0076318..a8cdbfeb55 100644
--- a/tests/TraceMemoryDumpTest.cpp
+++ b/tests/TraceMemoryDumpTest.cpp
@@ -24,9 +24,15 @@ public:
void setDiscardableMemoryBacking(
const char* dumpName,
const SkDiscardableMemory& discardableMemoryObject) override { }
+ LevelOfDetail getRequestedDetails() const override {
+ return SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail;
+ }
};
DEF_TEST(SkTraceMemoryDump, reporter) {
TestSkTraceMemoryDump x;
x.dumpNumericValue("foobar", "size", "bytes", 42);
+ if (x.getRequestedDetails() == SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail) {
+ x.dumpNumericValue("foobar/object1", "size", "bytes", 23);
+ }
}