From f751ca2a58c58e08039e889a8625bba032deda11 Mon Sep 17 00:00:00 2001 From: John Daggett Date: Thu, 19 Sep 2013 10:56:49 +0900 Subject: [PATCH] Bug 838105 - add debug logging code for userfont cache. r=birtles --- gfx/thebes/gfxUserFontSet.cpp | 59 +++++++++++++++++++++++++++++++++++ gfx/thebes/gfxUserFontSet.h | 11 +++++++ 2 files changed, 70 insertions(+) diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 1b461d3e08f6..954e13e359e6 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -899,6 +899,11 @@ gfxUserFontSet::UserFontCache::CacheFont(gfxFontEntry *aFontEntry) gfxUserFontData *data = aFontEntry->mUserFontData; sUserFonts->PutEntry(Key(data->mURI, data->mPrincipal, aFontEntry, data->mPrivate)); + +#ifdef DEBUG_USERFONT_CACHE + printf("userfontcache added fontentry: %p\n", aFontEntry); + Dump(); +#endif } void @@ -915,6 +920,11 @@ gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry *aFontEntry) // would no longer find the entry (bug 838105). sUserFonts->EnumerateEntries( gfxUserFontSet::UserFontCache::Entry::RemoveIfMatches, aFontEntry); + +#ifdef DEBUG_USERFONT_CACHE + printf("userfontcache removed fontentry: %p\n", aFontEntry); + Dump(); +#endif } gfxFontEntry* @@ -944,3 +954,52 @@ gfxUserFontSet::UserFontCache::Shutdown() sUserFonts = nullptr; } } + +#ifdef DEBUG_USERFONT_CACHE + +PLDHashOperator +gfxUserFontSet::UserFontCache::Entry::DumpEntry(Entry* aEntry, void* aUserData) +{ + nsresult rv; + + nsAutoCString principalURISpec; + + nsCOMPtr principalURI; + rv = aEntry->mPrincipal->GetURI(getter_AddRefs(principalURI)); + if (NS_SUCCEEDED(rv)) { + principalURI->GetSpec(principalURISpec); + } + + bool setDomain = false; + nsCOMPtr domainURI; + + aEntry->mPrincipal->GetDomain(getter_AddRefs(domainURI)); + if (domainURI) { + setDomain = true; + } + + NS_ASSERTION(aEntry->mURI, "null URI in userfont cache entry"); + + printf("userfontcache fontEntry: %p fonturihash: %8.8x family: %s domainset: %s principal: [%s]\n", + aEntry->mFontEntry, + nsURIHashKey::HashKey(aEntry->mURI), + NS_ConvertUTF16toUTF8(aEntry->mFontEntry->FamilyName()).get(), + (setDomain ? "true" : "false"), + principalURISpec.get() + ); + return PL_DHASH_NEXT; +} + +void +gfxUserFontSet::UserFontCache::Dump() +{ + if (!sUserFonts) { + return; + } + + printf("userfontcache dump count: %d ========\n", sUserFonts->Count()); + sUserFonts->EnumerateEntries(Entry::DumpEntry, nullptr); + printf("userfontcache dump ==================\n"); +} + +#endif diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 40ad9fb5ac2e..e2d424c00071 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -22,6 +22,8 @@ class gfxMixedFontFamily; class nsFontFaceLoader; +//#define DEBUG_USERFONT_CACHE + // parsed CSS @font-face rule information // lifetime: from when @font-face rule processed until font is loaded struct gfxFontFaceSrc { @@ -270,6 +272,11 @@ public: // Clear everything so that we don't leak URIs and Principals. static void Shutdown(); +#ifdef DEBUG_USERFONT_CACHE + // dump contents + static void Dump(); +#endif + private: // Helper that we use to observe the empty-cache notification // from nsICacheService. @@ -349,6 +356,10 @@ public: static PLDHashOperator RemoveIfMatches(Entry* aEntry, void* aUserData); static PLDHashOperator DisconnectSVG(Entry* aEntry, void* aUserData); +#ifdef DEBUG_USERFONT_CACHE + static PLDHashOperator DumpEntry(Entry* aEntry, void* aUserData); +#endif + private: static uint32_t HashFeatures(const nsTArray& aFeatures) {