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 {
kDidNotSwapCommitFails = 2,
kDidNotSwapCommitNoUpdate = 3,
kDidNotSwapActivationFails = 4,
kSwapResultLast = kDidNotSwapActivationFails,
kMaxValue = kDidNotSwapActivationFails,
};
using WebReportTimeCallback =
base::OnceCallback<void(WebSwapResult, base::TimeTicks)>;
......
......@@ -7,6 +7,7 @@
#include <memory>
#include <utility>
#include "base/metrics/histogram_macros.h"
#include "base/time/default_tick_clock.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
......@@ -20,7 +21,6 @@
#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/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/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
......@@ -335,11 +335,8 @@ void PaintTiming::SetFirstPaintAfterBackForwardCacheRestoreSwap(
}
void PaintTiming::ReportSwapResultHistogram(WebSwapResult result) {
DEFINE_STATIC_LOCAL(
EnumerationHistogram, did_swap_histogram,
("PageLoad.Internal.Renderer.PaintTiming.SwapResult",
static_cast<uint32_t>(WebSwapResult::kSwapResultLast) + 1));
did_swap_histogram.Count(static_cast<uint32_t>(result));
UMA_HISTOGRAM_ENUMERATION("PageLoad.Internal.Renderer.PaintTiming.SwapResult",
result);
}
void PaintTiming::OnRestoredFromBackForwardCache() {
......
......@@ -957,10 +957,7 @@ PendingScript* ScriptLoader::TakePendingScript(
ScriptSchedulingType scheduling_type) {
CHECK(prepared_pending_script_);
DEFINE_STATIC_LOCAL(
EnumerationHistogram, scheduling_type_histogram,
("Blink.Script.SchedulingType", kLastScriptSchedulingType + 1));
scheduling_type_histogram.Count(static_cast<int>(scheduling_type));
UMA_HISTOGRAM_ENUMERATION("Blink.Script.SchedulingType", scheduling_type);
PendingScript* pending_script = prepared_pending_script_;
prepared_pending_script_ = nullptr;
pending_script->SetSchedulingType(scheduling_type);
......
......@@ -69,14 +69,11 @@ enum class ScriptSchedulingType {
// execute after parsing completes (due to ForceDeferScriptIntervention).
//
// 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
#endif
......@@ -30,6 +30,7 @@
#include <memory>
#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/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
......@@ -51,7 +52,6 @@
#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/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/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/worker_resource_timing_notifier.h"
......@@ -160,10 +160,7 @@ WorkerThread::~WorkerThread() {
DCHECK(child_threads_.IsEmpty());
DCHECK_NE(ExitCode::kNotTerminated, exit_code_);
DEFINE_THREAD_SAFE_STATIC_LOCAL(
EnumerationHistogram, exit_code_histogram,
("WorkerThread.ExitCode", static_cast<int>(ExitCode::kLastEnum)));
exit_code_histogram.Count(static_cast<int>(exit_code_));
base::UmaHistogramEnumeration("WorkerThread.ExitCode", exit_code_);
}
void WorkerThread::Start(
......@@ -416,9 +413,6 @@ bool WorkerThread::IsForciblyTerminated() {
case ExitCode::kSyncForciblyTerminated:
case ExitCode::kAsyncForciblyTerminated:
return true;
case ExitCode::kLastEnum:
NOTREACHED() << static_cast<int>(exit_code_);
return false;
}
NOTREACHED() << static_cast<int>(exit_code_);
return false;
......
......@@ -91,7 +91,7 @@ class CORE_EXPORT WorkerThread : public Thread::TaskObserver {
kGracefullyTerminated,
kSyncForciblyTerminated,
kAsyncForciblyTerminated,
kLastEnum,
kMaxValue = kAsyncForciblyTerminated,
};
~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