From 5335681cd2ab05ad47e81be7722c9eee19d54065 Mon Sep 17 00:00:00 2001 From: adeshkp Date: Sat, 12 Jan 2019 06:20:31 -0500 Subject: Telemetry: Remove stubs and related code --- js/src/vm/Stopwatch.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'js/src/vm/Stopwatch.cpp') diff --git a/js/src/vm/Stopwatch.cpp b/js/src/vm/Stopwatch.cpp index 28632c2a1..7a6acb970 100644 --- a/js/src/vm/Stopwatch.cpp +++ b/js/src/vm/Stopwatch.cpp @@ -637,13 +637,6 @@ GetStopwatchIsMonitoringCPOW(JSContext* cx) return cx->performanceMonitoring.isMonitoringCPOW(); } -JS_PUBLIC_API(void) -GetPerfMonitoringTestCpuRescheduling(JSContext* cx, uint64_t* stayed, uint64_t* moved) -{ - *stayed = cx->performanceMonitoring.testCpuRescheduling.stayed; - *moved = cx->performanceMonitoring.testCpuRescheduling.moved; -} - JS_PUBLIC_API(void) AddCPOWPerformanceDelta(JSContext* cx, uint64_t delta) { -- cgit v1.2.3 From 3476c1d60ec29c5497123194acd7a9310b1023d2 Mon Sep 17 00:00:00 2001 From: David Teller Date: Mon, 28 Jan 2019 23:41:20 +0100 Subject: Reduce number of allocations in AutoStopwatch This patch fixes two related issues. 1. The AutoStopwatch uses a stack-allocated `mozilla::Vector` to communicate with its callback during each compartment switch. This vector was designed to allow its contents to be stack-allocated but they turned out to be accidentally heap-allocated. 2. During each tick, the stopwatch fills a vector `recentGroups_`. This vector always started with minimal capacity and had to grow repeatedly as groups were added, causing repeated reallocations. This patch preallocates `recentGroups_` to have the same capacity as the previous tick. We expect that this should eventually reach a stable size that closely matches the actual needs of the process. --- js/src/vm/Stopwatch.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'js/src/vm/Stopwatch.cpp') diff --git a/js/src/vm/Stopwatch.cpp b/js/src/vm/Stopwatch.cpp index 7a6acb970..49b70c478 100644 --- a/js/src/vm/Stopwatch.cpp +++ b/js/src/vm/Stopwatch.cpp @@ -136,6 +136,9 @@ PerformanceMonitoring::start() bool PerformanceMonitoring::commit() { + // Maximum initialization size, in elements for the vector of groups. + static const size_t MAX_GROUPS_INIT_CAPACITY = 1024; + #if !defined(MOZ_HAVE_RDTSC) // The AutoStopwatch is only executed if `MOZ_HAVE_RDTSC`. return false; @@ -152,12 +155,19 @@ PerformanceMonitoring::commit() return true; } - PerformanceGroupVector recentGroups; - recentGroups_.swap(recentGroups); + // The move operation is generally constant time, unless `recentGroups_.length()` is very small, in which case it's + // fast anyway because it's small. + PerformanceGroupVector recentGroups(Move(recentGroups_)); + recentGroups_ = PerformanceGroupVector(); // Reconstruct after `Move`. bool success = true; - if (stopwatchCommitCallback) - success = stopwatchCommitCallback(iteration_, recentGroups, stopwatchCommitClosure); + if (stopwatchCommitCallback) { + success = stopwatchCommitCallback(iteration_, recentGroups, stopwatchCommitClosure); + } + + // Heuristic use: we expect to have roughly the same number of groups as in the previous iteration. + const size_t capacity = std::min(recentGroups.capacity(), MAX_GROUPS_INIT_CAPACITY); + success = recentGroups_.reserve(capacity) && success; // Reset immediately, to make sure that we're not hit by the end // of a nested event loop (which would cause `commit` to be called @@ -227,7 +237,7 @@ AutoStopwatch::AutoStopwatch(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IM MOZ_GUARD_OBJECT_NOTIFIER_INIT; JSCompartment* compartment = cx_->compartment(); - if (compartment->scheduledForDestruction) + if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) return; JSRuntime* runtime = cx_->runtime(); @@ -266,11 +276,11 @@ AutoStopwatch::~AutoStopwatch() } JSCompartment* compartment = cx_->compartment(); - if (compartment->scheduledForDestruction) + if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) return; JSRuntime* runtime = cx_->runtime(); - if (iteration_ != runtime->performanceMonitoring.iteration()) { + if (MOZ_UNLIKELY(iteration_ != runtime->performanceMonitoring.iteration())) { // We have entered a nested event loop at some point. // Any information we may have is obsolete. return; -- cgit v1.2.3 From abcaa560fcaf2f814fc40eef46557033c910eb96 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 29 Jan 2019 00:40:24 +0100 Subject: Revert "Reduce number of allocations in AutoStopwatch" This reverts commit 3476c1d60ec29c5497123194acd7a9310b1023d2. --- js/src/vm/Stopwatch.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'js/src/vm/Stopwatch.cpp') diff --git a/js/src/vm/Stopwatch.cpp b/js/src/vm/Stopwatch.cpp index 49b70c478..7a6acb970 100644 --- a/js/src/vm/Stopwatch.cpp +++ b/js/src/vm/Stopwatch.cpp @@ -136,9 +136,6 @@ PerformanceMonitoring::start() bool PerformanceMonitoring::commit() { - // Maximum initialization size, in elements for the vector of groups. - static const size_t MAX_GROUPS_INIT_CAPACITY = 1024; - #if !defined(MOZ_HAVE_RDTSC) // The AutoStopwatch is only executed if `MOZ_HAVE_RDTSC`. return false; @@ -155,19 +152,12 @@ PerformanceMonitoring::commit() return true; } - // The move operation is generally constant time, unless `recentGroups_.length()` is very small, in which case it's - // fast anyway because it's small. - PerformanceGroupVector recentGroups(Move(recentGroups_)); - recentGroups_ = PerformanceGroupVector(); // Reconstruct after `Move`. + PerformanceGroupVector recentGroups; + recentGroups_.swap(recentGroups); bool success = true; - if (stopwatchCommitCallback) { - success = stopwatchCommitCallback(iteration_, recentGroups, stopwatchCommitClosure); - } - - // Heuristic use: we expect to have roughly the same number of groups as in the previous iteration. - const size_t capacity = std::min(recentGroups.capacity(), MAX_GROUPS_INIT_CAPACITY); - success = recentGroups_.reserve(capacity) && success; + if (stopwatchCommitCallback) + success = stopwatchCommitCallback(iteration_, recentGroups, stopwatchCommitClosure); // Reset immediately, to make sure that we're not hit by the end // of a nested event loop (which would cause `commit` to be called @@ -237,7 +227,7 @@ AutoStopwatch::AutoStopwatch(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IM MOZ_GUARD_OBJECT_NOTIFIER_INIT; JSCompartment* compartment = cx_->compartment(); - if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) + if (compartment->scheduledForDestruction) return; JSRuntime* runtime = cx_->runtime(); @@ -276,11 +266,11 @@ AutoStopwatch::~AutoStopwatch() } JSCompartment* compartment = cx_->compartment(); - if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) + if (compartment->scheduledForDestruction) return; JSRuntime* runtime = cx_->runtime(); - if (MOZ_UNLIKELY(iteration_ != runtime->performanceMonitoring.iteration())) { + if (iteration_ != runtime->performanceMonitoring.iteration()) { // We have entered a nested event loop at some point. // Any information we may have is obsolete. return; -- cgit v1.2.3 From b55d41c240df13812760a2a77f086a477f450fd0 Mon Sep 17 00:00:00 2001 From: David Teller Date: Tue, 29 Jan 2019 03:11:39 +0100 Subject: Reduce number of allocations in AutoStopwatch This patch fixes two related issues. 1. The AutoStopwatch uses a stack-allocated `mozilla::Vector` to communicate with its callback during each compartment switch. This vector was designed to allow its contents to be stack-allocated but they turned out to be accidentally heap-allocated. 2. During each tick, the stopwatch fills a vector `recentGroups_`. This vector always started with minimal capacity and had to grow repeatedly as groups were added, causing repeated reallocations. This patch preallocates `recentGroups_` to have the same capacity as the previous tick. We expect that this should eventually reach a stable size that closely matches the actual needs of the process. --- js/src/vm/Stopwatch.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'js/src/vm/Stopwatch.cpp') diff --git a/js/src/vm/Stopwatch.cpp b/js/src/vm/Stopwatch.cpp index 7a6acb970..5b5ec6196 100644 --- a/js/src/vm/Stopwatch.cpp +++ b/js/src/vm/Stopwatch.cpp @@ -20,6 +20,7 @@ #include "gc/Zone.h" #include "vm/Runtime.h" + namespace js { bool @@ -136,6 +137,9 @@ PerformanceMonitoring::start() bool PerformanceMonitoring::commit() { + // Maximal initialization size, in elements for the vector of groups. + static const size_t MAX_GROUPS_INIT_CAPACITY = 1024; + #if !defined(MOZ_HAVE_RDTSC) // The AutoStopwatch is only executed if `MOZ_HAVE_RDTSC`. return false; @@ -152,13 +156,24 @@ PerformanceMonitoring::commit() return true; } - PerformanceGroupVector recentGroups; - recentGroups_.swap(recentGroups); + // The move operation is generally constant time, unless + // `recentGroups_.length()` is very small, in which case + // it's fast just because it's small. + PerformanceGroupVector recentGroups(Move(recentGroups_)); + recentGroups_ = PerformanceGroupVector(); // Reconstruct after `Move`. bool success = true; if (stopwatchCommitCallback) success = stopwatchCommitCallback(iteration_, recentGroups, stopwatchCommitClosure); + // Heuristic: we expect to have roughly the same number of groups as in + // the previous iteration. + const size_t capacity = recentGroups.capacity() < MAX_GROUPS_INIT_CAPACITY ? + recentGroups.capacity() : + MAX_GROUPS_INIT_CAPACITY; + success = recentGroups_.reserve(capacity) + && success; + // Reset immediately, to make sure that we're not hit by the end // of a nested event loop (which would cause `commit` to be called // twice in succession). @@ -227,7 +242,7 @@ AutoStopwatch::AutoStopwatch(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IM MOZ_GUARD_OBJECT_NOTIFIER_INIT; JSCompartment* compartment = cx_->compartment(); - if (compartment->scheduledForDestruction) + if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) return; JSRuntime* runtime = cx_->runtime(); @@ -266,11 +281,11 @@ AutoStopwatch::~AutoStopwatch() } JSCompartment* compartment = cx_->compartment(); - if (compartment->scheduledForDestruction) + if (MOZ_UNLIKELY(compartment->scheduledForDestruction)) return; JSRuntime* runtime = cx_->runtime(); - if (iteration_ != runtime->performanceMonitoring.iteration()) { + if (MOZ_UNLIKELY(iteration_ != runtime->performanceMonitoring.iteration())) { // We have entered a nested event loop at some point. // Any information we may have is obsolete. return; -- cgit v1.2.3 From 493c956d8de0fdb763851d9c12cfd248776b80b8 Mon Sep 17 00:00:00 2001 From: adeshkp Date: Wed, 30 Jan 2019 13:56:07 -0500 Subject: Remove telemetry leftovers from JS engine. --- js/src/vm/Stopwatch.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'js/src/vm/Stopwatch.cpp') diff --git a/js/src/vm/Stopwatch.cpp b/js/src/vm/Stopwatch.cpp index 5b5ec6196..684846f00 100644 --- a/js/src/vm/Stopwatch.cpp +++ b/js/src/vm/Stopwatch.cpp @@ -334,11 +334,6 @@ AutoStopwatch::exit() const uint64_t cyclesEnd = getCycles(runtime); cyclesDelta = cyclesEnd - cyclesStart_; // Always >= 0 by definition of `getCycles`. } -#if WINVER >= 0x600 - updateTelemetry(cpuStart_, cpuEnd); -#elif defined(__linux__) - updateTelemetry(cpuStart_, cpuEnd); -#endif // WINVER >= 0x600 || _linux__ } uint64_t CPOWTimeDelta = 0; @@ -350,17 +345,6 @@ AutoStopwatch::exit() return addToGroups(cyclesDelta, CPOWTimeDelta); } -void -AutoStopwatch::updateTelemetry(const cpuid_t& cpuStart_, const cpuid_t& cpuEnd) -{ - JSRuntime* runtime = cx_->runtime(); - - if (isSameCPU(cpuStart_, cpuEnd)) - runtime->performanceMonitoring.testCpuRescheduling.stayed += 1; - else - runtime->performanceMonitoring.testCpuRescheduling.moved += 1; -} - PerformanceGroup* AutoStopwatch::acquireGroup(PerformanceGroup* group) { -- cgit v1.2.3