Skip to content

Commit

Permalink
Add UMA in preparation of running the ParserMainThread experiment
Browse files Browse the repository at this point in the history
This patch adds the following metrics:
- queueing delay from bytes received on the main thread to bytes received
on the BackgroundHTMLParser
- preload delay measured from bytes received on the main thread to preloads
sent to the main thread

The patch also gets rid of the appendRawBytesFromParserThread method,
which was dead code.

BUG=623165,603274

Review-Url: https://codereview.chromium.org/2097973002
Cr-Commit-Position: refs/heads/master@{#402516}
  • Loading branch information
csharrison authored and Commit bot committed Jun 28, 2016
1 parent 022687c commit 8987421
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT
, m_loadingTaskRunner(std::move(loadingTaskRunner))
, m_parsedChunkQueue(config->parsedChunkQueue.release())
, m_startingScript(false)
, m_lastBytesReceivedTime(0.0)
{
ASSERT(m_outstandingTokenLimit > 0);
ASSERT(m_pendingTokenLimit > 0);
Expand All @@ -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<Vector<char>> buffer)
void BackgroundHTMLParser::appendRawBytesFromMainThread(std::unique_ptr<Vector<char>> 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()));
}

Expand Down Expand Up @@ -180,6 +178,7 @@ void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint)
m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint);
m_startingScript = false;
m_parsedChunkQueue->clear();
m_lastBytesReceivedTime = monotonicallyIncreasingTimeMS();
pumpTokenizer();
}

Expand Down Expand Up @@ -293,6 +292,12 @@ void BackgroundHTMLParser::sendTokensToMainThread()
std::unique_ptr<HTMLDocumentParser::ParsedChunk> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class BackgroundHTMLParser {
String unparsedInput;
};

void appendRawBytesFromParserThread(const char* data, int dataLength);

void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>);
void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>, double bytesReceivedTime);
void setDecoder(std::unique_ptr<TextResourceDecoder>);
void flush();
void resumeFrom(std::unique_ptr<Checkpoint>);
Expand Down Expand Up @@ -128,6 +126,7 @@ class BackgroundHTMLParser {
RefPtr<ParsedChunkQueue> m_parsedChunkQueue;

bool m_startingScript;
double m_lastBytesReceivedTime;
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,14 +1024,15 @@ void HTMLDocumentParser::appendBytes(const char* data, size_t length)
return;

if (shouldUseThreading()) {
double bytesReceivedTime = monotonicallyIncreasingTimeMS();
if (!m_haveBackgroundParser)
startBackgroundParser();

std::unique_ptr<Vector<char>> buffer = wrapUnique(new Vector<char>(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;
}

Expand Down
18 changes: 18 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37423,6 +37423,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Parser.AppendBytesDelay" units="ms">
<owner>[email protected]</owner>
<summary>
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.
</summary>
</histogram>

<histogram name="Parser.ChunkEnqueueTime" units="ms">
<owner>[email protected]</owner>
<summary>
Expand Down Expand Up @@ -37454,6 +37463,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Parser.PreloadTokenizeDelay" units="ms">
<owner>[email protected]</owner>
<summary>
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.
</summary>
</histogram>

<histogram name="PartitionAlloc.CommittedSize" units="MB">
<owner>[email protected]</owner>
<summary>
Expand Down

0 comments on commit 8987421

Please sign in to comment.