diff --git a/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp b/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp
index 1fc0675bbef894..fc66a5b945cfcd 100644
--- a/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp
+++ b/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp
@@ -112,6 +112,7 @@ BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtrparsedChunkQueue.release())
, m_startingScript(false)
+ , m_lastBytesReceivedTime(0.0)
{
ASSERT(m_outstandingTokenLimit > 0);
ASSERT(m_pendingTokenLimit > 0);
@@ -122,15 +123,12 @@ BackgroundHTMLParser::~BackgroundHTMLParser()
{
}
-void BackgroundHTMLParser::appendRawBytesFromParserThread(const char* data, int dataLength)
-{
- ASSERT(m_decoder);
- updateDocument(m_decoder->decode(data, dataLength));
-}
-
-void BackgroundHTMLParser::appendRawBytesFromMainThread(std::unique_ptr> buffer)
+void BackgroundHTMLParser::appendRawBytesFromMainThread(std::unique_ptr> buffer, double bytesReceivedTime)
{
ASSERT(m_decoder);
+ m_lastBytesReceivedTime = bytesReceivedTime;
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, queueDelay, ("Parser.AppendBytesDelay", 1, 5000, 50));
+ queueDelay.count(monotonicallyIncreasingTimeMS() - bytesReceivedTime);
updateDocument(m_decoder->decode(buffer->data(), buffer->size()));
}
@@ -180,6 +178,7 @@ void BackgroundHTMLParser::resumeFrom(std::unique_ptr checkpoint)
m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint);
m_startingScript = false;
m_parsedChunkQueue->clear();
+ m_lastBytesReceivedTime = monotonicallyIncreasingTimeMS();
pumpTokenizer();
}
@@ -293,6 +292,12 @@ void BackgroundHTMLParser::sendTokensToMainThread()
std::unique_ptr chunk = wrapUnique(new HTMLDocumentParser::ParsedChunk);
TRACE_EVENT_WITH_FLOW0("blink,loading", "BackgroundHTMLParser::sendTokensToMainThread", chunk.get(), TRACE_EVENT_FLAG_FLOW_OUT);
+ if (!m_pendingPreloads.isEmpty()) {
+ double delay = monotonicallyIncreasingTimeMS() - m_lastBytesReceivedTime;
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, preloadTokenizeDelay, ("Parser.PreloadTokenizeDelay", 1, 10000, 50));
+ preloadTokenizeDelay.count(delay);
+ }
+
chunk->preloads.swap(m_pendingPreloads);
if (m_viewportDescription.set)
chunk->viewport = m_viewportDescription;
diff --git a/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.h b/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.h
index 3f2c4601807781..85564bb1daa4b9 100644
--- a/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.h
+++ b/third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.h
@@ -78,9 +78,7 @@ class BackgroundHTMLParser {
String unparsedInput;
};
- void appendRawBytesFromParserThread(const char* data, int dataLength);
-
- void appendRawBytesFromMainThread(std::unique_ptr>);
+ void appendRawBytesFromMainThread(std::unique_ptr>, double bytesReceivedTime);
void setDecoder(std::unique_ptr);
void flush();
void resumeFrom(std::unique_ptr);
@@ -128,6 +126,7 @@ class BackgroundHTMLParser {
RefPtr m_parsedChunkQueue;
bool m_startingScript;
+ double m_lastBytesReceivedTime;
};
} // namespace blink
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
index eee5367bedca27..ae3ed16a83cceb 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp
@@ -1024,6 +1024,7 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length)
return;
if (shouldUseThreading()) {
+ double bytesReceivedTime = monotonicallyIncreasingTimeMS();
if (!m_haveBackgroundParser)
startBackgroundParser();
@@ -1031,7 +1032,7 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length)
memcpy(buffer->data(), data, length);
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser::appendBytes", "size", (unsigned)length);
- postTaskToLookaheadParser(threadSafeBind(&BackgroundHTMLParser::appendRawBytesFromMainThread, m_backgroundParser, passed(std::move(buffer))));
+ postTaskToLookaheadParser(threadSafeBind(&BackgroundHTMLParser::appendRawBytesFromMainThread, m_backgroundParser, passed(std::move(buffer)), bytesReceivedTime));
return;
}
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 5ef2c93c7e9cb4..ce58180faf88c4 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -37423,6 +37423,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
+
+ csharrison@chromium.org
+
+ The delay from when bytes are received on the main thread to when the
+ BackgroundHTMLParser starts tokenizing them. Always a shorter time than the
+ time emitted to Parser.PreloadTokenizeDelay.
+
+
+
csharrison@chromium.org
@@ -37454,6 +37463,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
+
+ csharrison@chromium.org
+
+ The delay from when bytes are received on the main thread to when they are
+ tokenized and preloads are sent back to the main parser. Always a greater
+ time than the time emitted to Parser.AppendBytesDelay.
+
+
+
haraken@chromium.org