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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGlyphCache.h" 8 #include "SkGlyphCache.h"
9 #include "SkGlyphCache_Globals.h" 9 #include "SkGlyphCache_Globals.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkLazyPtr.h" 11 #include "SkLazyPtr.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkTemplates.h" 13 #include "SkTemplates.h"
14 #include "SkTraceMemoryDump.h"
14 #include "SkTypeface.h" 15 #include "SkTypeface.h"
15 16
16 //#define SPEW_PURGE_STATUS 17 //#define SPEW_PURGE_STATUS
17 18
18 namespace { 19 namespace {
19 20
20 SkGlyphCache_Globals* create_globals() { 21 SkGlyphCache_Globals* create_globals() {
21 return SkNEW(SkGlyphCache_Globals); 22 return SkNEW(SkGlyphCache_Globals);
22 } 23 }
23 24
25 const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache";
26
27 // Used to pass context to the sk_trace_dump_visitor.
28 struct SkGlyphCacheDumpContext {
29 int* counter;
30 SkTraceMemoryDump* dump;
31 };
32
24 } // namespace 33 } // namespace
25 34
26 SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals); 35 SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals);
27 36
28 // Returns the shared globals 37 // Returns the shared globals
29 static SkGlyphCache_Globals& get_globals() { 38 static SkGlyphCache_Globals& get_globals() {
30 return *globals.get(); 39 return *globals.get();
31 } 40 }
32 41
33 /////////////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////////////
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 SkDebugf("GlyphCache [ used budget ]\n"); 432 SkDebugf("GlyphCache [ used budget ]\n");
424 SkDebugf(" bytes [ %8zu %8zu ]\n", 433 SkDebugf(" bytes [ %8zu %8zu ]\n",
425 SkGraphics::GetFontCacheUsed(), SkGraphics::GetFontCacheLimit()); 434 SkGraphics::GetFontCacheUsed(), SkGraphics::GetFontCacheLimit());
426 SkDebugf(" count [ %8zu %8zu ]\n", 435 SkDebugf(" count [ %8zu %8zu ]\n",
427 SkGraphics::GetFontCacheCountUsed(), SkGraphics::GetFontCacheCountL imit()); 436 SkGraphics::GetFontCacheCountUsed(), SkGraphics::GetFontCacheCountL imit());
428 437
429 int counter = 0; 438 int counter = 0;
430 SkGlyphCache::VisitAll(dump_visitor, &counter); 439 SkGlyphCache::VisitAll(dump_visitor, &counter);
431 } 440 }
432 441
442 static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) {
443 SkGlyphCacheDumpContext* dumpContext = static_cast<SkGlyphCacheDumpContext*> (context);
444 SkTraceMemoryDump* dump = dumpContext->dump;
445 int* counter = dumpContext->counter;
446 int index = *counter;
447 *counter += 1;
448
449 const SkTypeface* face = cache.getScalerContext()->getTypeface();
450 SkString font_name;
451 face->getFamilyName(&font_name);
452 const SkScalerContextRec& rec = cache.getScalerContext()->getRec();
453
454 SkString dump_name = SkStringPrintf("%s/%s_%3d/index_%d",
455 gGlyphCacheDumpName, font_name.c_str(), rec.fFontID, index);
456
457 dump->dumpNumericValue(dump_name.c_str(), "size", "bytes", cache.getMemoryUs ed());
458 dump->dumpNumericValue(dump_name.c_str(), "glyph_count", "objects", cache.co untCachedGlyphs());
459 dump->setMemoryBacking(dump_name.c_str(), "malloc", nullptr);
460 }
461
462 void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
463 dump->dumpNumericValue(gGlyphCacheDumpName, "size", "bytes", SkGraphics::Get FontCacheUsed());
464 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_size", "bytes",
465 SkGraphics::GetFontCacheLimit());
466 dump->dumpNumericValue(gGlyphCacheDumpName, "glyph_count", "objects",
467 SkGraphics::GetFontCacheCountUsed());
468 dump->dumpNumericValue(gGlyphCacheDumpName, "budget_glyph_count", "objects",
469 SkGraphics::GetFontCacheCountLimit());
470
471 int counter = 0;
472 SkGlyphCacheDumpContext context = { &counter, dump };
473 SkGlyphCache::VisitAll(sk_trace_dump_visitor, &context);
474 }
475
433 void SkGlyphCache::VisitAll(Visitor visitor, void* context) { 476 void SkGlyphCache::VisitAll(Visitor visitor, void* context) {
434 SkGlyphCache_Globals& globals = get_globals(); 477 SkGlyphCache_Globals& globals = get_globals();
435 AutoAcquire ac(globals.fLock); 478 AutoAcquire ac(globals.fLock);
436 SkGlyphCache* cache; 479 SkGlyphCache* cache;
437 480
438 globals.validate(); 481 globals.validate();
439 482
440 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) { 483 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) {
441 visitor(*cache, context); 484 visitor(*cache, context);
442 } 485 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 } 655 }
613 656
614 void SkGraphics::PurgeFontCache() { 657 void SkGraphics::PurgeFontCache() {
615 get_globals().purgeAll(); 658 get_globals().purgeAll();
616 SkTypefaceCache::PurgeAll(); 659 SkTypefaceCache::PurgeAll();
617 } 660 }
618 661
619 // TODO(herb): clean up TLS apis. 662 // TODO(herb): clean up TLS apis.
620 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 663 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
621 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 664 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« 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