Strip font name of special characters before dumping

The font name can contain special characters in some OS that is
considered as delimiters ('/') by the traces. This causes error in the
dump name. This CL strips the fone name obtained before adding it to
traces.

This also adds discardable memory size for resources in cache.

BUG=532838

Review URL: https://codereview.chromium.org/1346993006
This commit is contained in:
ssid 2015-10-01 12:41:35 -07:00 committed by Commit bot
parent 77a53de20d
commit 60df542afc
2 changed files with 17 additions and 4 deletions

View File

@ -14,6 +14,8 @@
#include "SkTraceMemoryDump.h"
#include "SkTypeface.h"
#include <cctype>
//#define SPEW_PURGE_STATUS
namespace {
@ -427,11 +429,18 @@ static void sk_trace_dump_visitor(const SkGlyphCache& cache, void* context) {
*counter += 1;
const SkTypeface* face = cache.getScalerContext()->getTypeface();
SkString fontName;
face->getFamilyName(&fontName);
const SkScalerContextRec& rec = cache.getScalerContext()->getRec();
SkString dumpName = SkStringPrintf("%s/%s_%3d/index_%d",
SkString fontName;
face->getFamilyName(&fontName);
// Replace all special characters with '_'.
for (size_t index = 0; index < fontName.size(); ++index) {
if (!std::isalnum(fontName[index])) {
fontName[index] = '_';
}
}
SkString dumpName = SkStringPrintf("%s/%s_%d/index_%d",
gGlyphCacheDumpName, fontName.c_str(), rec.fFontID, index);
dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", cache.getMemoryUsed());

View File

@ -679,6 +679,10 @@ static void sk_trace_dump_visitor(const SkResourceCache::Rec& rec, void* context
SkDiscardableMemory* discardable = rec.diagnostic_only_getDiscardable();
if (discardable) {
dump->setDiscardableMemoryBacking(dumpName.c_str(), *discardable);
// The discardable memory size will be calculated by dumper, but we also dump what we think
// the size of object in memory is irrespective of whether object is live or dead.
dump->dumpNumericValue(dumpName.c_str(), "discardable_size", "bytes", rec.bytesUsed());
} else {
dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed());
dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);