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

Unified Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp

Issue 2026683003: Table blob leakage tracking Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Leak tracking per table tag Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp
index 46d7870da57e8e3449392839be5bff982546d014..c3065145a386209970ccc690b91a7df3100a3d92 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp
+++ b/third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp
@@ -267,6 +267,56 @@ static hb_font_funcs_t* harfBuzzSkiaGetFontFuncs()
return harfBuzzSkiaFontFuncs;
}
+
+struct HbAllocMeta {
+ unsigned int tableSize;
+ hb_tag_t tableTag;
+};
+
+typedef HashMap<hb_tag_t, unsigned int, WTF::IntHash<hb_tag_t>, WTF::UnsignedWithZeroKeyHashTraits<hb_tag_t>> TagTracking;
+
+TagTracking* tagTracker() {
+ DEFINE_STATIC_LOCAL(TagTracking, s_TagTracking, ());
+ return &s_TagTracking;
+}
+
+void reportTagTracking() {
+ LOG(INFO) << "\n";
+ char tagBuf[4] = { 0 };
+ unsigned int totalLeftover = 0;
+ for (auto tagTrackIterator = tagTracker()->begin(); tagTrackIterator != tagTracker()->end(); ++tagTrackIterator) {
+ hb_tag_to_string(tagTrackIterator->key, tagBuf);
+ LOG(INFO) << "Tag: " << tagBuf << " leftover kb " << tagTrackIterator->value / 1024.0;
+ totalLeftover += tagTrackIterator->value;
+ }
+ LOG(INFO) << "---------------------";
+ LOG(INFO) << "Total: kb " << totalLeftover / 1024.0 << "\n";
+}
+
+void subtractFromTagTracking(hb_tag_t tag, unsigned size) {
+ auto findResult = tagTracker()->find(tag);
+ ASSERT(findResult != tagTracker()->end());
+ findResult->value -= size;
+}
+
+void tableBlobfastFree(void* p) {
+ if (p) {
+ HbAllocMeta* allocMeta = reinterpret_cast<HbAllocMeta*>(p);
+ subtractFromTagTracking(allocMeta->tableTag, allocMeta->tableSize);
+ }
+ WTF::Partitions::fastFree(p);
+ reportTagTracking();
+}
+
+void addToTagTracking(hb_tag_t tag, unsigned size) {
+ unsigned newSize = size;
+ auto tagTrackerFindResult = tagTracker()->find(tag);
+ if (tagTrackerFindResult != tagTracker()->end()) {
+ newSize += tagTrackerFindResult->value;
+ }
+ auto tagEntry = tagTracker()->set(tag, newSize);
+}
+
#if !OS(MACOSX)
static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* userData)
{
@@ -277,15 +327,24 @@ static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user
return nullptr;
}
- char* buffer = reinterpret_cast<char*>(WTF::Partitions::fastMalloc(tableSize, WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData)));
+ char* buffer = reinterpret_cast<char*>(WTF::Partitions::fastMalloc(tableSize + sizeof(HbAllocMeta), WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData)));
if (!buffer)
return nullptr;
- size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer);
+ size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer + sizeof(HbAllocMeta));
if (tableSize != actualSize) {
WTF::Partitions::fastFree(buffer);
return nullptr;
}
- return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_WRITABLE, buffer, WTF::Partitions::fastFree);
+
+ HbAllocMeta* allocMeta = reinterpret_cast<HbAllocMeta*>(buffer);
+ allocMeta->tableSize = tableSize;
+ allocMeta->tableTag = tag;
+ addToTagTracking(tag, tableSize);
+
+ hb_blob_t* returnBlob = hb_blob_create(const_cast<char*>(buffer + sizeof(HbAllocMeta)), tableSize, HB_MEMORY_MODE_WRITABLE, buffer, tableBlobfastFree);
+ LOG(INFO) << "Blob memory allocated: " << tableSize << " bytes.";
+ ASSERT(hb_blob_get_length(returnBlob) == tableSize);
+ return returnBlob;
}
#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698