[tracing] Add support for skia caches to dump memory stats
Dump the memory statistics of resource cache and glyph cache using the SkTraceMemoryDump interface. BUG=chromium:503168 Review URL: https://codereview.chromium.org/1313793004
This commit is contained in:
parent
8504717550
commit
33c594c961
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
class SkData;
|
class SkData;
|
||||||
class SkImageGenerator;
|
class SkImageGenerator;
|
||||||
|
class SkTraceMemoryDump;
|
||||||
|
|
||||||
class SK_API SkGraphics {
|
class SK_API SkGraphics {
|
||||||
public:
|
public:
|
||||||
@ -114,6 +115,12 @@ public:
|
|||||||
static size_t GetResourceCacheSingleAllocationByteLimit();
|
static size_t GetResourceCacheSingleAllocationByteLimit();
|
||||||
static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
|
static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps memory usage of caches using the SkTraceMemoryDump interface. See SkTraceMemoryDump
|
||||||
|
* for usage of this method.
|
||||||
|
*/
|
||||||
|
static void DumpMemoryStatistics(SkTraceMemoryDump* dump);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applications with command line options may pass optional state, such
|
* Applications with command line options may pass optional state, such
|
||||||
* as cache sizes, here, for instance:
|
* as cache sizes, here, for instance:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "SkLazyPtr.h"
|
#include "SkLazyPtr.h"
|
||||||
#include "SkPath.h"
|
#include "SkPath.h"
|
||||||
#include "SkTemplates.h"
|
#include "SkTemplates.h"
|
||||||
|
#include "SkTraceMemoryDump.h"
|
||||||
#include "SkTypeface.h"
|
#include "SkTypeface.h"
|
||||||
|
|
||||||
//#define SPEW_PURGE_STATUS
|
//#define SPEW_PURGE_STATUS
|
||||||
@ -19,6 +20,14 @@ namespace {
|
|||||||
|
|
||||||
SkGlyphCache_Globals* create_globals() { return new SkGlyphCache_Globals; }
|
SkGlyphCache_Globals* create_globals() { return new 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
|
} // namespace
|
||||||
|
|
||||||
SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals);
|
SK_DECLARE_STATIC_LAZY_PTR(SkGlyphCache_Globals, globals, create_globals);
|
||||||
@ -424,6 +433,40 @@ void SkGlyphCache::Dump() {
|
|||||||
SkGlyphCache::VisitAll(dump_visitor, &counter);
|
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) {
|
void SkGlyphCache::VisitAll(Visitor visitor, void* context) {
|
||||||
SkGlyphCache_Globals& globals = get_globals();
|
SkGlyphCache_Globals& globals = get_globals();
|
||||||
AutoAcquire ac(globals.fLock);
|
AutoAcquire ac(globals.fLock);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
|
|
||||||
class SkPaint;
|
class SkPaint;
|
||||||
|
class SkTraceMemoryDump;
|
||||||
|
|
||||||
class SkGlyphCache_Globals;
|
class SkGlyphCache_Globals;
|
||||||
|
|
||||||
@ -97,9 +98,12 @@ public:
|
|||||||
return fScalerContext->isSubpixel();
|
return fScalerContext->isSubpixel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the approx RAM usage for this cache. */
|
||||||
|
size_t getMemoryUsed() const { return fMemoryUsed; }
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
/* AuxProc/Data allow a client to associate data with this cache entry. Multiple clients can
|
/** AuxProc/Data allow a client to associate data with this cache entry. Multiple clients can
|
||||||
use this, as their data is keyed with a function pointer. In addition to serving as a
|
use this, as their data is keyed with a function pointer. In addition to serving as a
|
||||||
key, the function pointer is called with the data when the glyphcache object is deleted,
|
key, the function pointer is called with the data when the glyphcache object is deleted,
|
||||||
so the client can cleanup their data as well.
|
so the client can cleanup their data as well.
|
||||||
@ -141,6 +145,11 @@ public:
|
|||||||
|
|
||||||
static void Dump();
|
static void Dump();
|
||||||
|
|
||||||
|
/** Dump memory usage statistics of all the attaches caches in the process using the
|
||||||
|
SkTraceMemoryDump interface.
|
||||||
|
*/
|
||||||
|
static void DumpMemoryStatistics(SkTraceMemoryDump* dump);
|
||||||
|
|
||||||
typedef void (*Visitor)(const SkGlyphCache&, void* context);
|
typedef void (*Visitor)(const SkGlyphCache&, void* context);
|
||||||
static void VisitAll(Visitor, void* context);
|
static void VisitAll(Visitor, void* context);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "SkBlitter.h"
|
#include "SkBlitter.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkGeometry.h"
|
#include "SkGeometry.h"
|
||||||
|
#include "SkGlyphCache.h"
|
||||||
#include "SkMath.h"
|
#include "SkMath.h"
|
||||||
#include "SkMatrix.h"
|
#include "SkMatrix.h"
|
||||||
#include "SkOpts.h"
|
#include "SkOpts.h"
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#include "SkPathEffect.h"
|
#include "SkPathEffect.h"
|
||||||
#include "SkPixelRef.h"
|
#include "SkPixelRef.h"
|
||||||
#include "SkRefCnt.h"
|
#include "SkRefCnt.h"
|
||||||
|
#include "SkResourceCache.h"
|
||||||
#include "SkRTConf.h"
|
#include "SkRTConf.h"
|
||||||
#include "SkScalerContext.h"
|
#include "SkScalerContext.h"
|
||||||
#include "SkShader.h"
|
#include "SkShader.h"
|
||||||
@ -64,6 +66,13 @@ void SkGraphics::Term() {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
|
||||||
|
SkResourceCache::DumpMemoryStatistics(dump);
|
||||||
|
SkGlyphCache::DumpMemoryStatistics(dump);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static const char kFontCacheLimitStr[] = "font-cache-limit";
|
static const char kFontCacheLimitStr[] = "font-cache-limit";
|
||||||
static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
|
static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "SkMutex.h"
|
#include "SkMutex.h"
|
||||||
#include "SkPixelRef.h"
|
#include "SkPixelRef.h"
|
||||||
#include "SkResourceCache.h"
|
#include "SkResourceCache.h"
|
||||||
|
#include "SkTraceMemoryDump.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -669,3 +670,19 @@ static void dump_visitor(const SkResourceCache::Rec& rec, void*) {
|
|||||||
void SkResourceCache::TestDumpMemoryStatistics() {
|
void SkResourceCache::TestDumpMemoryStatistics() {
|
||||||
VisitAll(dump_visitor, nullptr);
|
VisitAll(dump_visitor, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
SkDiscardableMemory* discardable = rec.diagnostic_only_getDiscardable();
|
||||||
|
if (discardable) {
|
||||||
|
dump->setDiscardableMemoryBacking(dump_name.c_str(), *discardable);
|
||||||
|
} else {
|
||||||
|
dump->dumpNumericValue(dump_name.c_str(), "size", "bytes", rec.bytesUsed());
|
||||||
|
dump->setMemoryBacking(dump_name.c_str(), "malloc", nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkResourceCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
|
||||||
|
VisitAll(sk_trace_dump_visitor, dump);
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
class SkCachedData;
|
class SkCachedData;
|
||||||
class SkDiscardableMemory;
|
class SkDiscardableMemory;
|
||||||
|
class SkTraceMemoryDump;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache object for bitmaps (with possible scale in X Y as part of the key).
|
* Cache object for bitmaps (with possible scale in X Y as part of the key).
|
||||||
@ -152,6 +153,11 @@ public:
|
|||||||
|
|
||||||
static void TestDumpMemoryStatistics();
|
static void TestDumpMemoryStatistics();
|
||||||
|
|
||||||
|
/** Dump memory usage statistics of every Rec in the cache using the
|
||||||
|
SkTraceMemoryDump interface.
|
||||||
|
*/
|
||||||
|
static void DumpMemoryStatistics(SkTraceMemoryDump* dump);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the DiscardableFactory used by the global cache, or nullptr.
|
* Returns the DiscardableFactory used by the global cache, or nullptr.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user