Commit a2ac3a70 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

[blink] Use //base/metrics for recording enum metrics in core.

This converts PaintTiming and ScriptLoader metrics to use the macro
helper, and WorkerThread termination metrics to use the function helper.
The distinction between function vs macro was made based on a guess on
how performance sensitive the code recording the metric appears to be.
In addition, the recorded enumerations have been updated to use the
kMaxValue convention, allowing:

- clang to enforce kMaxValue correctness
- autodeduction of the max value by the enum histogram macro/function
  helpers.

Bug: 742517, 1047547
Change-Id: I24f51cde75880c6ac42675724bc0fad321bcaf33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524933Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826737}
parent 0bda5f06
...@@ -21,7 +21,7 @@ enum class WebSwapResult { ...@@ -21,7 +21,7 @@ enum class WebSwapResult {
kDidNotSwapCommitFails = 2, kDidNotSwapCommitFails = 2,
kDidNotSwapCommitNoUpdate = 3, kDidNotSwapCommitNoUpdate = 3,
kDidNotSwapActivationFails = 4, kDidNotSwapActivationFails = 4,
kSwapResultLast = kDidNotSwapActivationFails, kMaxValue = kDidNotSwapActivationFails,
}; };
using WebReportTimeCallback = using WebReportTimeCallback =
base::OnceCallback<void(WebSwapResult, base::TimeTicks)>; base::OnceCallback<void(WebSwapResult, base::TimeTicks)>;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/metrics/histogram_macros.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
...@@ -20,7 +21,6 @@ ...@@ -20,7 +21,6 @@
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h" #include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/core/timing/window_performance.h" #include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/document_resource_coordinator.h" #include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/document_resource_coordinator.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
...@@ -335,11 +335,8 @@ void PaintTiming::SetFirstPaintAfterBackForwardCacheRestoreSwap( ...@@ -335,11 +335,8 @@ void PaintTiming::SetFirstPaintAfterBackForwardCacheRestoreSwap(
} }
void PaintTiming::ReportSwapResultHistogram(WebSwapResult result) { void PaintTiming::ReportSwapResultHistogram(WebSwapResult result) {
DEFINE_STATIC_LOCAL( UMA_HISTOGRAM_ENUMERATION("PageLoad.Internal.Renderer.PaintTiming.SwapResult",
EnumerationHistogram, did_swap_histogram, result);
("PageLoad.Internal.Renderer.PaintTiming.SwapResult",
static_cast<uint32_t>(WebSwapResult::kSwapResultLast) + 1));
did_swap_histogram.Count(static_cast<uint32_t>(result));
} }
void PaintTiming::OnRestoredFromBackForwardCache() { void PaintTiming::OnRestoredFromBackForwardCache() {
......
...@@ -957,10 +957,7 @@ PendingScript* ScriptLoader::TakePendingScript( ...@@ -957,10 +957,7 @@ PendingScript* ScriptLoader::TakePendingScript(
ScriptSchedulingType scheduling_type) { ScriptSchedulingType scheduling_type) {
CHECK(prepared_pending_script_); CHECK(prepared_pending_script_);
DEFINE_STATIC_LOCAL( UMA_HISTOGRAM_ENUMERATION("Blink.Script.SchedulingType", scheduling_type);
EnumerationHistogram, scheduling_type_histogram,
("Blink.Script.SchedulingType", kLastScriptSchedulingType + 1));
scheduling_type_histogram.Count(static_cast<int>(scheduling_type));
PendingScript* pending_script = prepared_pending_script_; PendingScript* pending_script = prepared_pending_script_;
prepared_pending_script_ = nullptr; prepared_pending_script_ = nullptr;
pending_script->SetSchedulingType(scheduling_type); pending_script->SetSchedulingType(scheduling_type);
......
...@@ -69,14 +69,11 @@ enum class ScriptSchedulingType { ...@@ -69,14 +69,11 @@ enum class ScriptSchedulingType {
// execute after parsing completes (due to ForceDeferScriptIntervention). // execute after parsing completes (due to ForceDeferScriptIntervention).
// //
// Spec: not yet spec'ed. https://crbug.com/976061 // Spec: not yet spec'ed. https://crbug.com/976061
kForceDefer kForceDefer,
// When adding a new value, update kLastScriptSchedulingType. kMaxValue = kForceDefer,
}; };
static const int kLastScriptSchedulingType =
static_cast<int>(ScriptSchedulingType::kForceDefer);
} // namespace blink } // namespace blink
#endif #endif
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/metrics/histogram_functions.h"
#include "third_party/blink/public/common/loader/worker_main_script_load_parameters.h" #include "third_party/blink/public/common/loader/worker_main_script_load_parameters.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
...@@ -51,7 +52,6 @@ ...@@ -51,7 +52,6 @@
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/platform/bindings/microtask.h" #include "third_party/blink/renderer/platform/bindings/microtask.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h" #include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/worker_resource_timing_notifier.h" #include "third_party/blink/renderer/platform/loader/fetch/worker_resource_timing_notifier.h"
...@@ -160,10 +160,7 @@ WorkerThread::~WorkerThread() { ...@@ -160,10 +160,7 @@ WorkerThread::~WorkerThread() {
DCHECK(child_threads_.IsEmpty()); DCHECK(child_threads_.IsEmpty());
DCHECK_NE(ExitCode::kNotTerminated, exit_code_); DCHECK_NE(ExitCode::kNotTerminated, exit_code_);
DEFINE_THREAD_SAFE_STATIC_LOCAL( base::UmaHistogramEnumeration("WorkerThread.ExitCode", exit_code_);
EnumerationHistogram, exit_code_histogram,
("WorkerThread.ExitCode", static_cast<int>(ExitCode::kLastEnum)));
exit_code_histogram.Count(static_cast<int>(exit_code_));
} }
void WorkerThread::Start( void WorkerThread::Start(
...@@ -416,9 +413,6 @@ bool WorkerThread::IsForciblyTerminated() { ...@@ -416,9 +413,6 @@ bool WorkerThread::IsForciblyTerminated() {
case ExitCode::kSyncForciblyTerminated: case ExitCode::kSyncForciblyTerminated:
case ExitCode::kAsyncForciblyTerminated: case ExitCode::kAsyncForciblyTerminated:
return true; return true;
case ExitCode::kLastEnum:
NOTREACHED() << static_cast<int>(exit_code_);
return false;
} }
NOTREACHED() << static_cast<int>(exit_code_); NOTREACHED() << static_cast<int>(exit_code_);
return false; return false;
......
...@@ -91,7 +91,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver { ...@@ -91,7 +91,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver {
kGracefullyTerminated, kGracefullyTerminated,
kSyncForciblyTerminated, kSyncForciblyTerminated,
kAsyncForciblyTerminated, kAsyncForciblyTerminated,
kLastEnum, kMaxValue = kAsyncForciblyTerminated,
}; };
~WorkerThread() override; ~WorkerThread() override;
......
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