Index: src/core/SkGlyphCache.cpp |
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp |
index e719c00b8352ba01f6d4252a58ab9cb1f807e50f..ddc0b0508744bf997495c79adaa2ad8e69b2425b 100755 |
--- a/src/core/SkGlyphCache.cpp |
+++ b/src/core/SkGlyphCache.cpp |
@@ -11,6 +11,7 @@ |
#include "SkLazyPtr.h" |
#include "SkPath.h" |
#include "SkTemplates.h" |
+#include "SkTraceMemoryDump.h" |
#include "SkTypeface.h" |
//#define SPEW_PURGE_STATUS |
@@ -21,6 +22,14 @@ SkGlyphCache_Globals* create_globals() { |
return SkNEW(SkGlyphCache_Globals); |
} |
+const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; |
+ |
+// Used to pass context to the sk_trace_dump_visitor. |
+struct SkGlyphCacheDumpContext { |
+ int* counter; |
+ SkTraceMemoryDump* dump; |
+}; |
+ |
} // namespace |
SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals); |
@@ -430,6 +439,40 @@ void SkGlyphCache::Dump() { |
SkGlyphCache::VisitAll(dump_visitor, &counter); |
} |
+static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) { |
+ SkGlyphCacheDumpContext* dumpContext = static_cast<SkGlyphCacheDumpContext*>(context); |
+ SkTraceMemoryDump* dump = dumpContext->dump; |
+ int* counter = dumpContext->counter; |
+ int index = *counter; |
+ *counter += 1; |
+ |
+ const SkTypeface* face = cache.getScalerContext()->getTypeface(); |
+ SkString font_name; |
+ face->getFamilyName(&font_name); |
+ const SkScalerContextRec& rec = cache.getScalerContext()->getRec(); |
+ |
+ SkString dump_name = SkStringPrintf("%s/%s_%3d/index_%d", |
+ gGlyphCacheDumpName, font_name.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); |
+} |
+ |
+void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
+ dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::GetFontCacheUsed()); |
+ dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes", |
+ SkGraphics::GetFontCacheLimit()); |
+ dump->dumpNumericValue(gGlyphCacheDumpName, "glyph_count", "objects", |
+ SkGraphics::GetFontCacheCountUsed()); |
+ dump->dumpNumericValue(gGlyphCacheDumpName, "budget_glyph_count", "objects", |
+ SkGraphics::GetFontCacheCountLimit()); |
+ |
+ int counter = 0; |
+ SkGlyphCacheDumpContext context = { &counter, dump }; |
+ SkGlyphCache::VisitAll(sk_trace_dump_visitor, &context); |
+} |
+ |
void SkGlyphCache::VisitAll(Visitor visitor, void* context) { |
SkGlyphCache_Globals& globals = get_globals(); |
AutoAcquire ac(globals.fLock); |