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

Unified Diff: src/core/SkGlyphCache.cpp

Issue 1313793004: [tracing] Add support for skia caches to dump memory stats (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Commit missed files. 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
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698