[counters] Convert RuntimeCallTimerScopes to use kThreadSpecific
Converts and uses of RuntimeCallTimerScopes that switch the counter based on the thread, to use kThreadSpecific and remove the counter selection. Also moves RuntimeCallTimerScope::CounterMode to RuntimeCallStats, since now CorrectCurrentCounterId also takes it as a parameter. Bug: v8:10006 Change-Id: I14a503e0b83bb69c071f9665956de094bb33c0ba Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1928864 Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/master@{#65141}
This commit is contained in:
parent
af90964be9
commit
c60faf2ada
@ -548,10 +548,8 @@ void DeclarationScope::HoistSloppyBlockFunctions(AstNodeFactory* factory) {
|
||||
|
||||
bool DeclarationScope::Analyze(ParseInfo* info) {
|
||||
RuntimeCallTimerScope runtimeTimer(
|
||||
info->runtime_call_stats(),
|
||||
info->on_background_thread()
|
||||
? RuntimeCallCounterId::kCompileBackgroundScopeAnalysis
|
||||
: RuntimeCallCounterId::kCompileScopeAnalysis);
|
||||
info->runtime_call_stats(), RuntimeCallCounterId::kCompileScopeAnalysis,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
DCHECK_NOT_NULL(info->literal());
|
||||
DeclarationScope* scope = info->literal()->scope();
|
||||
|
||||
|
@ -1100,9 +1100,9 @@ BackgroundCompileTask::~BackgroundCompileTask() = default;
|
||||
|
||||
namespace {
|
||||
|
||||
// A scope object that ensures a parse info's runtime call stats, stack limit
|
||||
// and on_background_thread fields is set correctly during worker-thread
|
||||
// compile, and restores it after going out of scope.
|
||||
// A scope object that ensures a parse info's runtime call stats and stack limit
|
||||
// are set correctly during worker-thread compile, and restores it after going
|
||||
// out of scope.
|
||||
class OffThreadParseInfoScope {
|
||||
public:
|
||||
OffThreadParseInfoScope(
|
||||
@ -1112,7 +1112,6 @@ class OffThreadParseInfoScope {
|
||||
original_runtime_call_stats_(parse_info_->runtime_call_stats()),
|
||||
original_stack_limit_(parse_info_->stack_limit()),
|
||||
worker_thread_scope_(worker_thread_runtime_stats) {
|
||||
parse_info_->set_on_background_thread(true);
|
||||
parse_info_->set_runtime_call_stats(worker_thread_scope_.Get());
|
||||
parse_info_->set_stack_limit(GetCurrentStackPosition() - stack_size * KB);
|
||||
}
|
||||
@ -1120,7 +1119,6 @@ class OffThreadParseInfoScope {
|
||||
~OffThreadParseInfoScope() {
|
||||
parse_info_->set_stack_limit(original_stack_limit_);
|
||||
parse_info_->set_runtime_call_stats(original_runtime_call_stats_);
|
||||
parse_info_->set_on_background_thread(false);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -1170,11 +1168,9 @@ void BackgroundCompileTask::Run() {
|
||||
|
||||
bool Compiler::Analyze(ParseInfo* parse_info) {
|
||||
DCHECK_NOT_NULL(parse_info->literal());
|
||||
RuntimeCallTimerScope runtimeTimer(
|
||||
parse_info->runtime_call_stats(),
|
||||
parse_info->on_background_thread()
|
||||
? RuntimeCallCounterId::kCompileBackgroundAnalyse
|
||||
: RuntimeCallCounterId::kCompileAnalyse);
|
||||
RuntimeCallTimerScope runtimeTimer(parse_info->runtime_call_stats(),
|
||||
RuntimeCallCounterId::kCompileAnalyse,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
if (!Rewriter::Rewrite(parse_info)) return false;
|
||||
if (!DeclarationScope::Analyze(parse_info)) return false;
|
||||
return true;
|
||||
|
@ -153,9 +153,8 @@ InterpreterCompilationJob::InterpreterCompilationJob(
|
||||
InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() {
|
||||
RuntimeCallTimerScope runtimeTimerScope(
|
||||
parse_info()->runtime_call_stats(),
|
||||
parse_info()->on_background_thread()
|
||||
? RuntimeCallCounterId::kCompileBackgroundIgnition
|
||||
: RuntimeCallCounterId::kCompileIgnition);
|
||||
RuntimeCallCounterId::kCompileIgnition,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
// TODO(lpy): add support for background compilation RCS trace.
|
||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition");
|
||||
|
||||
|
@ -515,9 +515,14 @@ void RuntimeCallStats::Add(RuntimeCallStats* other) {
|
||||
}
|
||||
|
||||
// static
|
||||
void RuntimeCallStats::CorrectCurrentCounterId(
|
||||
RuntimeCallCounterId counter_id) {
|
||||
void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallCounterId counter_id,
|
||||
CounterMode mode) {
|
||||
DCHECK(IsCalledOnTheSameThread());
|
||||
if (mode == RuntimeCallStats::CounterMode::kThreadSpecific) {
|
||||
counter_id = CounterIdForThread(counter_id);
|
||||
}
|
||||
DCHECK(IsCounterAppropriateForThread(counter_id));
|
||||
|
||||
RuntimeCallTimer* timer = current_timer();
|
||||
if (timer == nullptr) return;
|
||||
RuntimeCallCounter* counter = GetCounter(counter_id);
|
||||
|
@ -1068,6 +1068,11 @@ class RuntimeCallStats final {
|
||||
public:
|
||||
enum ThreadType { kMainIsolateThread, kWorkerThread };
|
||||
|
||||
// If kExact is chosen the counter will be use as given. With kThreadSpecific,
|
||||
// if the RuntimeCallStats was created for a worker thread, then the
|
||||
// background specific version of the counter will be used instead.
|
||||
enum CounterMode { kExact, kThreadSpecific };
|
||||
|
||||
explicit V8_EXPORT_PRIVATE RuntimeCallStats(ThreadType thread_type);
|
||||
|
||||
// Starting measuring the time for a function. This will establish the
|
||||
@ -1083,7 +1088,7 @@ class RuntimeCallStats final {
|
||||
// Set counter id for the innermost measurement. It can be used to refine
|
||||
// event kind when a runtime entry counter is too generic.
|
||||
V8_EXPORT_PRIVATE void CorrectCurrentCounterId(
|
||||
RuntimeCallCounterId counter_id);
|
||||
RuntimeCallCounterId counter_id, CounterMode mode = kExact);
|
||||
|
||||
V8_EXPORT_PRIVATE void Reset();
|
||||
// Add all entries from another stats object.
|
||||
@ -1198,22 +1203,18 @@ class WorkerThreadRuntimeCallStatsScope final {
|
||||
// the time of C++ scope.
|
||||
class RuntimeCallTimerScope {
|
||||
public:
|
||||
// If kExact is chosen the counter will be use as given. With kThreadSpecific,
|
||||
// if the RuntimeCallStats was created for a worker thread, then the
|
||||
// background specific version of the counter will be used instead.
|
||||
enum CounterMode { kExact, kThreadSpecific };
|
||||
|
||||
inline RuntimeCallTimerScope(Isolate* isolate,
|
||||
RuntimeCallCounterId counter_id);
|
||||
inline RuntimeCallTimerScope(RuntimeCallStats* stats,
|
||||
RuntimeCallCounterId counter_id,
|
||||
CounterMode mode = CounterMode::kExact) {
|
||||
RuntimeCallStats::CounterMode mode =
|
||||
RuntimeCallStats::CounterMode::kExact) {
|
||||
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled() ||
|
||||
stats == nullptr)) {
|
||||
return;
|
||||
}
|
||||
stats_ = stats;
|
||||
if (mode == CounterMode::kThreadSpecific) {
|
||||
if (mode == RuntimeCallStats::CounterMode::kThreadSpecific) {
|
||||
counter_id = stats->CounterIdForThread(counter_id);
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,6 @@ class V8_EXPORT_PRIVATE ParseInfo {
|
||||
FLAG_ACCESSOR(kCoverageEnabled, coverage_enabled, set_coverage_enabled)
|
||||
FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled,
|
||||
set_block_coverage_enabled)
|
||||
FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread,
|
||||
set_on_background_thread)
|
||||
FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache)
|
||||
FLAG_ACCESSOR(kRequiresInstanceMembersInitializer,
|
||||
requires_instance_members_initializer,
|
||||
@ -306,25 +304,24 @@ class V8_EXPORT_PRIVATE ParseInfo {
|
||||
kCoverageEnabled = 1u << 10,
|
||||
kBlockCoverageEnabled = 1u << 11,
|
||||
kIsAsmWasmBroken = 1u << 12,
|
||||
kOnBackgroundThread = 1u << 13,
|
||||
kAllowEvalCache = 1u << 14,
|
||||
kRequiresInstanceMembersInitializer = 1u << 15,
|
||||
kContainsAsmModule = 1u << 16,
|
||||
kMightAlwaysOpt = 1u << 17,
|
||||
kAllowLazyCompile = 1u << 18,
|
||||
kAllowNativeSyntax = 1u << 19,
|
||||
kAllowHarmonyPublicFields = 1u << 20,
|
||||
kAllowHarmonyStaticFields = 1u << 21,
|
||||
kAllowHarmonyDynamicImport = 1u << 22,
|
||||
kAllowHarmonyImportMeta = 1u << 23,
|
||||
kAllowHarmonyOptionalChaining = 1u << 24,
|
||||
kAllowHarmonyPrivateFields = 1u << 25,
|
||||
kAllowHarmonyPrivateMethods = 1u << 26,
|
||||
kIsOneshotIIFE = 1u << 27,
|
||||
kCollectSourcePositions = 1u << 28,
|
||||
kAllowHarmonyNullish = 1u << 29,
|
||||
kAllowHarmonyTopLevelAwait = 1u << 30,
|
||||
kREPLMode = 1u << 31,
|
||||
kAllowEvalCache = 1u << 13,
|
||||
kRequiresInstanceMembersInitializer = 1u << 14,
|
||||
kContainsAsmModule = 1u << 15,
|
||||
kMightAlwaysOpt = 1u << 16,
|
||||
kAllowLazyCompile = 1u << 17,
|
||||
kAllowNativeSyntax = 1u << 18,
|
||||
kAllowHarmonyPublicFields = 1u << 19,
|
||||
kAllowHarmonyStaticFields = 1u << 20,
|
||||
kAllowHarmonyDynamicImport = 1u << 21,
|
||||
kAllowHarmonyImportMeta = 1u << 22,
|
||||
kAllowHarmonyOptionalChaining = 1u << 23,
|
||||
kAllowHarmonyPrivateFields = 1u << 24,
|
||||
kAllowHarmonyPrivateMethods = 1u << 25,
|
||||
kIsOneshotIIFE = 1u << 26,
|
||||
kCollectSourcePositions = 1u << 27,
|
||||
kAllowHarmonyNullish = 1u << 28,
|
||||
kAllowHarmonyTopLevelAwait = 1u << 29,
|
||||
kREPLMode = 1u << 30,
|
||||
};
|
||||
|
||||
//------------- Inputs to parsing and scope analysis -----------------------
|
||||
|
@ -4200,14 +4200,12 @@ template <typename Impl>
|
||||
typename ParserBase<Impl>::ExpressionT
|
||||
ParserBase<Impl>::ParseArrowFunctionLiteral(
|
||||
const FormalParametersT& formal_parameters) {
|
||||
const RuntimeCallCounterId counters[2][2] = {
|
||||
{RuntimeCallCounterId::kParseBackgroundArrowFunctionLiteral,
|
||||
RuntimeCallCounterId::kParseArrowFunctionLiteral},
|
||||
{RuntimeCallCounterId::kPreParseBackgroundArrowFunctionLiteral,
|
||||
RuntimeCallCounterId::kPreParseArrowFunctionLiteral}};
|
||||
RuntimeCallTimerScope runtime_timer(
|
||||
runtime_call_stats_,
|
||||
counters[Impl::IsPreParser()][parsing_on_main_thread_]);
|
||||
const RuntimeCallCounterId counters[2] = {
|
||||
RuntimeCallCounterId::kParseArrowFunctionLiteral,
|
||||
RuntimeCallCounterId::kPreParseArrowFunctionLiteral};
|
||||
RuntimeCallTimerScope runtime_timer(runtime_call_stats_,
|
||||
counters[Impl::IsPreParser()],
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
base::ElapsedTimer timer;
|
||||
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "src/codegen/bailout-reason.h"
|
||||
#include "src/common/message-template.h"
|
||||
#include "src/compiler-dispatcher/compiler-dispatcher.h"
|
||||
#include "src/logging/counters.h"
|
||||
#include "src/logging/log.h"
|
||||
#include "src/numbers/conversions-inl.h"
|
||||
#include "src/objects/scope-info.h"
|
||||
@ -2333,10 +2334,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
|
||||
const bool is_lazy_inner_function = is_lazy && !is_top_level;
|
||||
|
||||
RuntimeCallTimerScope runtime_timer(
|
||||
runtime_call_stats_,
|
||||
parsing_on_main_thread_
|
||||
? RuntimeCallCounterId::kParseFunctionLiteral
|
||||
: RuntimeCallCounterId::kParseBackgroundFunctionLiteral);
|
||||
runtime_call_stats_, RuntimeCallCounterId::kParseFunctionLiteral,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
base::ElapsedTimer timer;
|
||||
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
|
||||
|
||||
@ -2429,12 +2428,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
|
||||
}
|
||||
if (V8_UNLIKELY(TracingFlags::is_runtime_stats_enabled()) &&
|
||||
did_preparse_successfully) {
|
||||
const RuntimeCallCounterId counters[2] = {
|
||||
RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution,
|
||||
RuntimeCallCounterId::kPreParseWithVariableResolution};
|
||||
if (runtime_call_stats_) {
|
||||
runtime_call_stats_->CorrectCurrentCounterId(
|
||||
counters[parsing_on_main_thread_]);
|
||||
RuntimeCallCounterId::kPreParseWithVariableResolution,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "src/base/logging.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/logging/counters.h"
|
||||
#include "src/numbers/conversions-inl.h"
|
||||
#include "src/numbers/conversions.h"
|
||||
#include "src/parsing/parser-base.h"
|
||||
@ -276,11 +277,10 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
|
||||
DCHECK_NE(FunctionSyntaxKind::kWrapped, function_syntax_kind);
|
||||
// Function ::
|
||||
// '(' FormalParameterList? ')' '{' FunctionBody '}'
|
||||
const RuntimeCallCounterId counters[2] = {
|
||||
RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution,
|
||||
RuntimeCallCounterId::kPreParseWithVariableResolution};
|
||||
RuntimeCallTimerScope runtime_timer(runtime_call_stats_,
|
||||
counters[parsing_on_main_thread_]);
|
||||
RuntimeCallTimerScope runtime_timer(
|
||||
runtime_call_stats_,
|
||||
RuntimeCallCounterId::kPreParseWithVariableResolution,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
|
||||
base::ElapsedTimer timer;
|
||||
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
|
||||
|
@ -366,9 +366,8 @@ bool Rewriter::Rewrite(ParseInfo* info) {
|
||||
|
||||
RuntimeCallTimerScope runtimeTimer(
|
||||
info->runtime_call_stats(),
|
||||
info->on_background_thread()
|
||||
? RuntimeCallCounterId::kCompileBackgroundRewriteReturnResult
|
||||
: RuntimeCallCounterId::kCompileRewriteReturnResult);
|
||||
RuntimeCallCounterId::kCompileRewriteReturnResult,
|
||||
RuntimeCallStats::kThreadSpecific);
|
||||
|
||||
FunctionLiteral* function = info->literal();
|
||||
DCHECK_NOT_NULL(function);
|
||||
|
Loading…
Reference in New Issue
Block a user