Commit 1d11f9fd authored by Mario Bianucci's avatar Mario Bianucci Committed by Commit Bot

De-couple PredictionMetricsHandler from specific histograms

PredictionMetricsHandler appears to be designed to work for anything
that is predicting points. However, it currently only reports metrics
in the Event.InputEventPrediction.Scroll* histograms. De-couple the
class from these histograms so it can be used for things only than
scroll metrics.

Bug: 1133785
Change-Id: Ib34129fc46b20b45810cbd5ca195483e88c513e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441197Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Mario Bianucci <mabian@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#813813}
parent 21ef1b69
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
namespace blink { namespace blink {
ScrollPredictor::ScrollPredictor() { ScrollPredictor::ScrollPredictor()
: metrics_handler_("Event.InputEventPrediction.Scroll") {
// Get the predictor from feature flags // Get the predictor from feature flags
std::string predictor_name = GetFieldTrialParamValueByFeature( std::string predictor_name = GetFieldTrialParamValueByFeature(
blink::features::kResamplingScrollEvents, "predictor"); blink::features::kResamplingScrollEvents, "predictor");
......
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <utility>
#include "ui/base/prediction/prediction_metrics_handler.h" #include "ui/base/prediction/prediction_metrics_handler.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
namespace ui { namespace ui {
PredictionMetricsHandler::PredictionMetricsHandler() {} PredictionMetricsHandler::PredictionMetricsHandler(const char* histogram_name)
PredictionMetricsHandler::~PredictionMetricsHandler() {} : histogram_name_(std::move(histogram_name)) {}
PredictionMetricsHandler::~PredictionMetricsHandler() = default;
void PredictionMetricsHandler::AddRealEvent(const gfx::PointF& pos, void PredictionMetricsHandler::AddRealEvent(const gfx::PointF& pos,
const base::TimeTicks& time_stamp, const base::TimeTicks& time_stamp,
...@@ -130,25 +134,25 @@ void PredictionMetricsHandler::ComputeMetrics() { ...@@ -130,25 +134,25 @@ void PredictionMetricsHandler::ComputeMetrics() {
for (int i = 0; i < first_needed_event - 1; i++) for (int i = 0; i < first_needed_event - 1; i++)
events_queue_.pop_front(); events_queue_.pop_front();
std::string kPredictionMetrics = "Event.InputEventPrediction.Scroll.";
double score = ComputeOverUnderPredictionMetric(); double score = ComputeOverUnderPredictionMetric();
if (score >= 0) { if (score >= 0) {
base::UmaHistogramCounts1000(kPredictionMetrics + "OverPrediction", score); base::UmaHistogramCounts1000(
base::StrCat({histogram_name_, ".OverPrediction"}), score);
} else { } else {
base::UmaHistogramCounts1000(kPredictionMetrics + "UnderPrediction", base::UmaHistogramCounts1000(
-score); base::StrCat({histogram_name_, ".UnderPrediction"}), -score);
} }
// Need |last_predicted_| to compute WrongDirection and Jitter metrics. // Need |last_predicted_| to compute WrongDirection and Jitter metrics.
if (!last_predicted_.has_value()) if (!last_predicted_.has_value())
return; return;
base::UmaHistogramBoolean(kPredictionMetrics + "WrongDirection", base::UmaHistogramBoolean(base::StrCat({histogram_name_, ".WrongDirection"}),
ComputeWrongDirectionMetric()); ComputeWrongDirectionMetric());
base::UmaHistogramCounts1000(kPredictionMetrics + "PredictionJitter", base::UmaHistogramCounts1000(
ComputePredictionJitterMetric()); base::StrCat({histogram_name_, ".PredictionJitter"}),
base::UmaHistogramCounts1000(kPredictionMetrics + "VisualJitter", ComputePredictionJitterMetric());
base::UmaHistogramCounts1000(base::StrCat({histogram_name_, ".VisualJitter"}),
ComputeVisualJitterMetric()); ComputeVisualJitterMetric());
} }
......
...@@ -25,7 +25,7 @@ class PredictionMetricsHandlerTest; ...@@ -25,7 +25,7 @@ class PredictionMetricsHandlerTest;
// few metrics. // few metrics.
class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler { class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler {
public: public:
explicit PredictionMetricsHandler(); explicit PredictionMetricsHandler(const char* histogram_name);
~PredictionMetricsHandler(); ~PredictionMetricsHandler();
// Struct used to store predicted and real event information. // Struct used to store predicted and real event information.
...@@ -103,6 +103,12 @@ class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler { ...@@ -103,6 +103,12 @@ class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler {
base::Optional<gfx::PointF> last_predicted_ = base::nullopt; base::Optional<gfx::PointF> last_predicted_ = base::nullopt;
// The first real event position which time is later than the predicted time. // The first real event position which time is later than the predicted time.
gfx::PointF next_real_; gfx::PointF next_real_;
// Beginning of the full histogram name. It will have the various metrics'
// names (.OverPrediction, .UnderPrediction, .WrongDirection,
// .PredictionJitter, .VisualJitter) appended to it when counting the metric
// in a histogram.
const char* const histogram_name_;
}; };
} // namespace ui } // namespace ui
......
...@@ -29,7 +29,8 @@ class PredictionMetricsHandlerTest : public testing::Test { ...@@ -29,7 +29,8 @@ class PredictionMetricsHandlerTest : public testing::Test {
explicit PredictionMetricsHandlerTest() {} explicit PredictionMetricsHandlerTest() {}
void SetUp() override { void SetUp() override {
metrics_handler_ = std::make_unique<PredictionMetricsHandler>(); metrics_handler_ = std::make_unique<PredictionMetricsHandler>(
"Event.InputEventPrediction.Scroll");
histogram_tester_ = std::make_unique<base::HistogramTester>(); histogram_tester_ = std::make_unique<base::HistogramTester>();
} }
......
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