[diagnostics] Make basic block profiling more configurable

This change adds more granular control to the behavior that was
previously controlled by the single flag --turbo-profiling. With this
change, it becomes possible to:
- output information only about builtins, ignoring functions compiled at
  runtime
- skip the very slow process of writing the schedule and disassembly for
  all builtins, if you only want the block counts and don't need verbose
  output

This change also moves the output step from Shell::OnExit to
Isolate::DumpAndResetStats so that it's more consistent with other
features and works in hosts other than d8.

Bug: v8:10470, v8:9119
Change-Id: I19b1caca3ff27a2e4a6fdc7ad2f8174f8d678b3a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2216717
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#68104}
This commit is contained in:
Seth Brenith 2020-05-29 10:45:32 -07:00 committed by Commit Bot
parent a70348d0e0
commit 7ce4b196ce
8 changed files with 31 additions and 12 deletions

View File

@ -131,10 +131,16 @@ declare_args() {
v8_enable_array_buffer_extension = true
# Runs mksnapshot with --turbo-profiling. After building in this
# configuration, any subsequent run of d8 with --turbo-profiling will output
# information about both runtime-generated code and builtins.
# configuration, any subsequent run of d8 will output information about usage
# of basic blocks in builtins.
v8_enable_builtins_profiling = false
# Runs mksnapshot with --turbo-profiling-verbose. After building in this
# configuration, any subsequent run of d8 will output information about usage
# of basic blocks in builtins, including the schedule and disassembly of all
# used builtins.
v8_enable_builtins_profiling_verbose = false
# Enables various testing features.
v8_enable_test_features = ""
@ -1431,6 +1437,9 @@ template("run_mksnapshot") {
if (v8_enable_builtins_profiling) {
args += [ "--turbo-profiling" ]
}
if (v8_enable_builtins_profiling_verbose) {
args += [ "--turbo-profiling-verbose" ]
}
# This is needed to distinguish between generating code for the simulator
# and cross-compiling. The latter may need to run code on the host with the

View File

@ -59,7 +59,7 @@ BasicBlockProfilerData* BasicBlockInstrumentor::Instrument(
// Set the function name.
data->SetFunctionName(info->GetDebugName());
// Capture the schedule string before instrumentation.
{
if (FLAG_turbo_profiling_verbose) {
std::ostringstream os;
os << *schedule;
data->SetSchedule(os);

View File

@ -35,7 +35,6 @@
#include "src/d8/d8.h"
#include "src/debug/debug-interface.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/diagnostics/basic-block-profiler.h"
#include "src/execution/vm-state-inl.h"
#include "src/handles/maybe-handles.h"
#include "src/init/v8.h"
@ -2236,12 +2235,6 @@ void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
}
void Shell::OnExit(v8::Isolate* isolate) {
// Dump basic block profiling data.
if (i::FLAG_turbo_profiling) {
i::StdoutStream out;
i::BasicBlockProfiler::Get()->Print(out,
reinterpret_cast<i::Isolate*>(isolate));
}
isolate->Dispose();
if (i::FLAG_dump_counters || i::FLAG_dump_counters_nvp) {

View File

@ -106,6 +106,7 @@ void BasicBlockProfiler::ResetCounts(Isolate* isolate) {
for (const auto& data : data_list_) {
data->ResetCounts();
}
HandleScope scope(isolate);
Handle<ArrayList> list(isolate->heap()->basic_block_profiling_data(),
isolate);
for (int i = 0; i < list->Length(); ++i) {
@ -117,6 +118,11 @@ void BasicBlockProfiler::ResetCounts(Isolate* isolate) {
}
}
bool BasicBlockProfiler::HasData(Isolate* isolate) {
return data_list_.size() > 0 ||
isolate->heap()->basic_block_profiling_data().Length() > 0;
}
void BasicBlockProfiler::Print(std::ostream& os, Isolate* isolate) {
os << "---- Start Profiling Data ----" << std::endl;
for (const auto& data : data_list_) {

View File

@ -66,6 +66,7 @@ class BasicBlockProfiler {
V8_EXPORT_PRIVATE static BasicBlockProfiler* Get();
BasicBlockProfilerData* NewData(size_t n_blocks);
V8_EXPORT_PRIVATE void ResetCounts(Isolate* isolate);
V8_EXPORT_PRIVATE bool HasData(Isolate* isolate);
V8_EXPORT_PRIVATE void Print(std::ostream& os, Isolate* isolate);
const DataList* data_list() { return &data_list_; }

View File

@ -32,6 +32,7 @@
#include "src/debug/debug-frames.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/diagnostics/basic-block-profiler.h"
#include "src/diagnostics/compilation-statistics.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
@ -3640,6 +3641,11 @@ void Isolate::DumpAndResetStats() {
counters()->runtime_call_stats()->Print();
counters()->runtime_call_stats()->Reset();
}
if (BasicBlockProfiler::Get()->HasData(this)) {
StdoutStream out;
BasicBlockProfiler::Get()->Print(out, this);
BasicBlockProfiler::Get()->ResetCounts(this);
}
}
void Isolate::AbortConcurrentOptimization(BlockingBehavior behavior) {

View File

@ -622,7 +622,11 @@ DEFINE_BOOL(trace_environment_liveness, false,
DEFINE_BOOL(turbo_load_elimination, true, "enable load elimination in TurboFan")
DEFINE_BOOL(trace_turbo_load_elimination, false,
"trace TurboFan load elimination")
DEFINE_BOOL(turbo_profiling, false, "enable profiling in TurboFan")
DEFINE_BOOL(turbo_profiling, false, "enable basic block profiling in TurboFan")
DEFINE_BOOL(turbo_profiling_verbose, false,
"enable basic block profiling in TurboFan, and include each "
"function's schedule and disassembly in the output")
DEFINE_IMPLICATION(turbo_profiling_verbose, turbo_profiling)
DEFINE_BOOL(turbo_verify_allocation, DEBUG_BOOL,
"verify register allocation in TurboFan")
DEFINE_BOOL(turbo_move_optimization, true, "optimize gap moves in TurboFan")

View File

@ -236,7 +236,7 @@ MaybeHandle<Code> Factory::CodeBuilder::BuildInternal(
code->FlushICache();
}
if (profiler_data_) {
if (profiler_data_ && FLAG_turbo_profiling_verbose) {
#ifdef ENABLE_DISASSEMBLER
std::ostringstream os;
code->Disassemble(nullptr, os, isolate_);