Commit 32947e78 authored by Kouhei Ueno's avatar Kouhei Ueno Committed by Commit Bot

V8ScriptRunner: Add "V8.CompileHeuristicsDecision" UMA

This CL introduces "V8.CompileHeuristicsDecision" which records
which of the script compilation function got picked, providing more insights
about how often V8 {code,parser} cache is {produced,consumed,bypassed}.

Bug: 769203
Change-Id: I7b27a1634ee5b1623330acae1ef27bc78f39742e
Reviewed-on: https://chromium-review.googlesource.com/720660Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509540}
parent c45de7bb
...@@ -68,6 +68,7 @@ const int kMaxRecursionDepth = 44; ...@@ -68,6 +68,7 @@ const int kMaxRecursionDepth = 44;
class V8CompileHistogram { class V8CompileHistogram {
public: public:
enum Cacheability { kCacheable, kNoncacheable, kInlineScript }; enum Cacheability { kCacheable, kNoncacheable, kInlineScript };
explicit V8CompileHistogram(Cacheability); explicit V8CompileHistogram(Cacheability);
~V8CompileHistogram(); ~V8CompileHistogram();
...@@ -108,6 +109,28 @@ V8CompileHistogram::~V8CompileHistogram() { ...@@ -108,6 +109,28 @@ V8CompileHistogram::~V8CompileHistogram() {
} }
} }
// Used for UMAs. Don't reorder. New values should be appended.
enum class CompileHeuristicsDecision {
kNoCacheHandler = 0,
kCachingDisabled,
kCodeTooShortToCache,
kCacheTooCold,
kProduceParserCache,
kConsumeParserCache,
kConsumeCodeCache,
kProduceCodeCache,
kStreamingCompile,
kEnumMax
};
void ReportCompileHeuristicsHistogram(CompileHeuristicsDecision decision) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
EnumerationHistogram, compile_heuristics_histogram,
("V8.CompileHeuristicsDecision",
static_cast<int>(CompileHeuristicsDecision::kEnumMax)));
compile_heuristics_histogram.Count(static_cast<int>(decision));
}
// In order to make sure all pending messages to be processed in // In order to make sure all pending messages to be processed in
// v8::Function::Call, we don't call throwStackOverflowException // v8::Function::Call, we don't call throwStackOverflowException
// directly. Instead, we create a v8::Function of // directly. Instead, we create a v8::Function of
...@@ -315,16 +338,25 @@ static CompileFn SelectCompileFunction( ...@@ -315,16 +338,25 @@ static CompileFn SelectCompileFunction(
static const int kHotHours = 72; static const int kHotHours = 72;
// Caching is not available in this case. // Caching is not available in this case.
if (!cache_handler) if (!cache_handler) {
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kNoCacheHandler);
return WTF::Bind(CompileWithoutOptions, cacheability_if_no_handler); return WTF::Bind(CompileWithoutOptions, cacheability_if_no_handler);
}
if (cache_options == kV8CacheOptionsNone) if (cache_options == kV8CacheOptionsNone) {
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kCachingDisabled);
return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable); return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable);
}
// Caching is not worthwhile for small scripts. Do not use caching // Caching is not worthwhile for small scripts. Do not use caching
// unless explicitly expected, indicated by the cache option. // unless explicitly expected, indicated by the cache option.
if (code->Length() < kMinimalCodeLength) if (code->Length() < kMinimalCodeLength) {
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kCodeTooShortToCache);
return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable); return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable);
}
// The cacheOptions will guide our strategy: // The cacheOptions will guide our strategy:
switch (cache_options) { switch (cache_options) {
...@@ -335,14 +367,17 @@ static CompileFn SelectCompileFunction( ...@@ -335,14 +367,17 @@ static CompileFn SelectCompileFunction(
cache_handler ? cache_handler->GetCachedMetadata(parser_tag) cache_handler ? cache_handler->GetCachedMetadata(parser_tag)
: nullptr); : nullptr);
if (parser_cache) { if (parser_cache) {
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kProduceParserCache);
return WTF::Bind(CompileAndConsumeCache, WrapPersistent(cache_handler), return WTF::Bind(CompileAndConsumeCache, WrapPersistent(cache_handler),
std::move(parser_cache), std::move(parser_cache),
v8::ScriptCompiler::kConsumeParserCache); v8::ScriptCompiler::kConsumeParserCache);
} }
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kConsumeParserCache);
return WTF::Bind(CompileAndProduceCache, WrapPersistent(cache_handler), return WTF::Bind(CompileAndProduceCache, WrapPersistent(cache_handler),
parser_tag, v8::ScriptCompiler::kProduceParserCache, parser_tag, v8::ScriptCompiler::kProduceParserCache,
CachedMetadataHandler::kCacheLocally); CachedMetadataHandler::kCacheLocally);
break;
} }
case kV8CacheOptionsDefault: case kV8CacheOptionsDefault:
...@@ -355,6 +390,8 @@ static CompileFn SelectCompileFunction( ...@@ -355,6 +390,8 @@ static CompileFn SelectCompileFunction(
CacheTag(kCacheTagCode, cache_handler)) CacheTag(kCacheTagCode, cache_handler))
: nullptr); : nullptr);
if (code_cache) { if (code_cache) {
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kConsumeCodeCache);
return WTF::Bind(CompileAndConsumeCache, WrapPersistent(cache_handler), return WTF::Bind(CompileAndConsumeCache, WrapPersistent(cache_handler),
std::move(code_cache), std::move(code_cache),
v8::ScriptCompiler::kConsumeCodeCache); v8::ScriptCompiler::kConsumeCodeCache);
...@@ -362,9 +399,13 @@ static CompileFn SelectCompileFunction( ...@@ -362,9 +399,13 @@ static CompileFn SelectCompileFunction(
if (cache_options != kV8CacheOptionsAlways && if (cache_options != kV8CacheOptionsAlways &&
!IsResourceHotForCaching(cache_handler, kHotHours)) { !IsResourceHotForCaching(cache_handler, kHotHours)) {
V8ScriptRunner::SetCacheTimeStamp(cache_handler); V8ScriptRunner::SetCacheTimeStamp(cache_handler);
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kCacheTooCold);
return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable); return WTF::Bind(CompileWithoutOptions, V8CompileHistogram::kCacheable);
} }
uint32_t code_cache_tag = CacheTag(kCacheTagCode, cache_handler); uint32_t code_cache_tag = CacheTag(kCacheTagCode, cache_handler);
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kProduceCodeCache);
return WTF::Bind(CompileAndProduceCache, WrapPersistent(cache_handler), return WTF::Bind(CompileAndProduceCache, WrapPersistent(cache_handler),
code_cache_tag, v8::ScriptCompiler::kProduceCodeCache, code_cache_tag, v8::ScriptCompiler::kProduceCodeCache,
CachedMetadataHandler::kSendToPlatform); CachedMetadataHandler::kSendToPlatform);
...@@ -394,6 +435,11 @@ CompileFn SelectCompileFunction(V8CacheOptions cache_options, ...@@ -394,6 +435,11 @@ CompileFn SelectCompileFunction(V8CacheOptions cache_options,
DCHECK(!resource->ErrorOccurred()); DCHECK(!resource->ErrorOccurred());
DCHECK(streamer->IsFinished()); DCHECK(streamer->IsFinished());
DCHECK(!streamer->StreamingSuppressed()); DCHECK(!streamer->StreamingSuppressed());
// Streaming compilation may involve use of code cache.
// TODO(kouhei): Consider adding further breakdown if needed.
ReportCompileHeuristicsHistogram(
CompileHeuristicsDecision::kStreamingCompile);
return WTF::Bind(PostStreamCompile, cache_options, return WTF::Bind(PostStreamCompile, cache_options,
WrapPersistent(resource->CacheHandler()), WrapPersistent(resource->CacheHandler()),
WrapPersistent(streamer)); WrapPersistent(streamer));
......
...@@ -5790,6 +5790,35 @@ uploading your change for review. These are checked by presubmit scripts. ...@@ -5790,6 +5790,35 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="2" label="Successful first layout"/> <int value="2" label="Successful first layout"/>
</enum> </enum>
<enum name="CompileHeuristicsDecision">
<int value="0" label="NoCacheHandler">
No CachedMetadataHandler was provided, thus caching functionality is
disabled.
</int>
<int value="1" label="CachingDisabled">Caching is disabled by settings.</int>
<int value="2" label="CodeTooShortToCache">
The script is too short to benefit from caching, thus caching functionality
is disabled.
</int>
<int value="3" label="CacheTooCold">
The script is not loaded often enough to benefit from caching, thus not
producing cache.
</int>
<int value="4" label="ProduceParserCache">
Parser cache is produced for the script when compiled.
</int>
<int value="5" label="ConsumeParserCache">
Consume previously generated parser cache for the script.
</int>
<int value="6" label="ProduceCodeCache">
Code cache is produced for the script when compiled.
</int>
<int value="7" label="ConsumeCodeCache">
Consume previously generated code cache for the script.
</int>
<int value="8" label="StreamingCompile">Use streamed compilation result.</int>
</enum>
<enum name="ComponentUpdaterCalls"> <enum name="ComponentUpdaterCalls">
<int value="0" label="Install"/> <int value="0" label="Install"/>
<int value="1" label="Update"/> <int value="1" label="Update"/>
...@@ -88773,6 +88773,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -88773,6 +88773,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<summary>Time spent in V8 compiler (full codegen) for eval.</summary> <summary>Time spent in V8 compiler (full codegen) for eval.</summary>
</histogram> </histogram>
<histogram name="V8.CompileHeuristicsDecision" enum="CompileHeuristicsDecision">
<owner>kouhei@chromium.org</owner>
<summary>
V8 script compile function variant which was picked. This contains
information such as {if,why} v8 {code,parser} was
{produced,consumed,bypassed}.
</summary>
</histogram>
<histogram name="V8.CompileInlineScriptMicroSeconds" units="microseconds"> <histogram name="V8.CompileInlineScriptMicroSeconds" units="microseconds">
<owner>yangguo@chromium.org</owner> <owner>yangguo@chromium.org</owner>
<summary>Time spent compiling an inline script.</summary> <summary>Time spent compiling an inline script.</summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment