Index: Source/platform/fonts/opentype/OpenTypeSanitizer.cpp |
diff --git a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp |
index d17f9f9b3adb0e7bc8134749a64ebaaca4a651db..90500b7cac1ebde94f3b7731b1e4c97c73d33621 100644 |
--- a/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp |
+++ b/Source/platform/fonts/opentype/OpenTypeSanitizer.cpp |
@@ -31,12 +31,32 @@ |
#include "config.h" |
#include "platform/fonts/opentype/OpenTypeSanitizer.h" |
-#include "platform/SharedBuffer.h" |
#include "opentype-sanitiser.h" |
#include "ots-memory-stream.h" |
+#include "platform/SharedBuffer.h" |
+#include "public/platform/Platform.h" |
+#include "wtf/CurrentTime.h" |
namespace blink { |
+static void recordDecodeSpeedHistogram(SharedBuffer* buffer, double decodeTime, size_t decodedSize) |
+{ |
+ if (decodeTime <= 0) |
+ return; |
+ |
+ const char* histogramName = "WebFont.DecodeSpeed.SFNT"; |
+ if (buffer->size() >= 4) { |
+ const char* data = buffer->data(); |
+ if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') |
+ histogramName = "WebFont.DecodeSpeed.WOFF"; |
+ else if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == '2') |
+ histogramName = "WebFont.DecodeSpeed.WOFF2"; |
+ } |
+ |
+ double kbPerSecond = decodedSize / (1000 * decodeTime); |
+ blink::Platform::current()->histogramCustomCounts(histogramName, kbPerSecond, 0, 500000, 50); |
+} |
+ |
PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() |
{ |
if (!m_buffer) |
@@ -57,10 +77,12 @@ PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() |
// much larger than the original. |
ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); |
+ double start = currentTime(); |
if (!ots::Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->data()), m_buffer->size())) |
return nullptr; |
const size_t transcodeLen = output.Tell(); |
+ recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); |
return SharedBuffer::create(static_cast<unsigned char*>(output.get()), transcodeLen); |
} |