From 3986012f4c1fa4f8d6ccceb672072cb436d660d3 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Fri, 3 Dec 2021 13:13:39 +0100 Subject: [PATCH] [d8] Make --dump-counters a d8-only flag --dump-counters and --dump-counters-nvp are only functional in d8, thus they should be d8-only flags. R=mlippautz@chromium.org Bug: v8:12464 Change-Id: Ie3295990a1b4691ab95f8403ff6d9932543b03cd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3312275 Reviewed-by: Michael Lippautz Commit-Queue: Clemens Backes Cr-Commit-Position: refs/heads/main@{#78247} --- src/d8/d8.cc | 18 +++++++++++------- src/d8/d8.h | 2 ++ src/flags/flag-definitions.h | 5 +---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/d8/d8.cc b/src/d8/d8.cc index f762ce8291..081a4a54d0 100644 --- a/src/d8/d8.cc +++ b/src/d8/d8.cc @@ -3360,22 +3360,18 @@ void Shell::OnExit(v8::Isolate* isolate, bool dispose) { i::Isolate::Delete(reinterpret_cast(shared_isolate)); } - // {V8::Dispose} resets flags, thus get the flag values before disposing. - bool dump_counters = i::FLAG_dump_counters; - bool dump_counters_nvp = i::FLAG_dump_counters_nvp; - if (dispose) { V8::Dispose(); V8::DisposePlatform(); } - if (dump_counters || dump_counters_nvp) { + if (options.dump_counters || options.dump_counters_nvp) { base::SharedMutexGuard mutex_guard(&counter_mutex_); std::vector> counters( counter_map_->begin(), counter_map_->end()); std::sort(counters.begin(), counters.end()); - if (dump_counters_nvp) { + if (options.dump_counters_nvp) { // Dump counters as name-value pairs. for (const auto& pair : counters) { std::string key = pair.first; @@ -4358,6 +4354,14 @@ bool Shell::SetOptions(int argc, char* argv[]) { } else if (strcmp(argv[i], "--no-fail") == 0) { options.no_fail = true; argv[i] = nullptr; + } else if (strcmp(argv[i], "--dump-counters") == 0) { + i::FLAG_slow_histograms = true; + options.dump_counters = true; + argv[i] = nullptr; + } else if (strcmp(argv[i], "--dump-counters-nvp") == 0) { + i::FLAG_slow_histograms = true; + options.dump_counters_nvp = true; + argv[i] = nullptr; } else if (strncmp(argv[i], "--icu-data-file=", 16) == 0) { options.icu_data_file = argv[i] + 16; argv[i] = nullptr; @@ -5208,7 +5212,7 @@ int Shell::Main(int argc, char* argv[]) { base::SysInfo::AmountOfVirtualMemory()); Shell::counter_map_ = new CounterMap(); - if (i::FLAG_dump_counters || i::FLAG_dump_counters_nvp || + if (options.dump_counters || options.dump_counters_nvp || i::TracingFlags::is_gc_stats_enabled()) { create_params.counter_lookup_callback = LookupCounter; create_params.create_histogram_callback = CreateHistogram; diff --git a/src/d8/d8.h b/src/d8/d8.h index 63f68e32dd..49a514a639 100644 --- a/src/d8/d8.h +++ b/src/d8/d8.h @@ -393,6 +393,8 @@ class ShellOptions { bool test_shell = false; DisallowReassignment expected_to_throw = {"throws", false}; DisallowReassignment no_fail = {"no-fail", false}; + DisallowReassignment dump_counters = {"dump-counters", false}; + DisallowReassignment dump_counters_nvp = {"dump-counters-nvp", false}; DisallowReassignment ignore_unhandled_promises = { "ignore-unhandled-promises", false}; DisallowReassignment mock_arraybuffer_allocator = { diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.h index 3462e69975..9e6b9bfa3e 100644 --- a/src/flags/flag-definitions.h +++ b/src/flags/flag-definitions.h @@ -1879,13 +1879,10 @@ DEFINE_BOOL_READONLY(minor_mc, false, DEFINE_BOOL(help, false, "Print usage message, including flags, on console") DEFINE_BOOL(print_flag_values, false, "Print all flag values of V8") -DEFINE_BOOL(dump_counters, false, "Dump counters on exit") +// Slow histograms are also enabled via --dump-counters in d8. DEFINE_BOOL(slow_histograms, false, "Enable slow histograms with more overhead.") -DEFINE_IMPLICATION(dump_counters, slow_histograms) -DEFINE_BOOL(dump_counters_nvp, false, - "Dump counters as name-value pairs on exit") DEFINE_BOOL(use_external_strings, false, "Use external strings for source code") DEFINE_STRING(map_counters, "", "Map counters to a file") DEFINE_BOOL(mock_arraybuffer_allocator, false,