Commit 3121c748 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

Wire autotest start/stop smoothness with ui::ThroughputTracker

ui::ThroughputTracker provides a more accurate smoothness tracking
than ash::FpsCounter. Re-wire the start/stop smoothness tracking
api using that.

Bug: 1062124
Change-Id: I7472593810e2dc2151059e16656041cb1a7a72d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226278Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775177}
parent 2b24505b
...@@ -166,6 +166,8 @@ component("cpp") { ...@@ -166,6 +166,8 @@ component("cpp") {
"media_client.h", "media_client.h",
"media_controller.cc", "media_controller.cc",
"media_controller.h", "media_controller.h",
"metrics_util.cc",
"metrics_util.h",
"network_config_service.cc", "network_config_service.cc",
"network_config_service.h", "network_config_service.h",
"network_icon_image_source.cc", "network_icon_image_source.cc",
......
include_rules = [ include_rules = [
"+chromeos/services", "+chromeos/services",
"+cc/metrics",
"+components/arc/mojom", "+components/arc/mojom",
"+components/prefs", "+components/prefs",
"+services/data_decoder/public", "+services/data_decoder/public",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/metrics_util.h"
#include "base/bind.h"
namespace ash {
namespace metrics_util {
namespace {
// Calculates smoothness from |throughput| and sends to |callback|.
void ForwardSmoothness(SmoothnessCallback callback,
cc::FrameSequenceMetrics::ThroughputData throughput) {
const int smoothness = std::floor(100.0f * throughput.frames_produced /
throughput.frames_expected);
callback.Run(smoothness);
}
} // namespace
ReportCallback ForSmoothness(SmoothnessCallback callback) {
return base::BindRepeating(&ForwardSmoothness, std::move(callback));
}
} // namespace metrics_util
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_METRICS_UTIL_H_
#define ASH_PUBLIC_CPP_METRICS_UTIL_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/callback.h"
#include "cc/metrics/frame_sequence_metrics.h"
namespace ash {
namespace metrics_util {
using ReportCallback =
base::RepeatingCallback<void(cc::FrameSequenceMetrics::ThroughputData)>;
using SmoothnessCallback = base::RepeatingCallback<void(int smoothness)>;
// Returns a ReportCallback that could be passed to ui::ThroughputTracker
// or ui::AnimationThroughputReporter. The returned callback picks up the
// cc::FrameSequenceMetrics::ThroughputData, calculates the smoothness
// out of it and forward it to the smoothness report callback.
ASH_PUBLIC_EXPORT ReportCallback ForSmoothness(SmoothnessCallback callback);
} // namespace metrics_util
} // namespace ash
#endif // ASH_PUBLIC_CPP_METRICS_UTIL_H_
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#include "ash/public/cpp/autotest_private_api_utils.h" #include "ash/public/cpp/autotest_private_api_utils.h"
#include "ash/public/cpp/default_frame_header.h" #include "ash/public/cpp/default_frame_header.h"
#include "ash/public/cpp/desks_helper.h" #include "ash/public/cpp/desks_helper.h"
#include "ash/public/cpp/fps_counter.h"
#include "ash/public/cpp/frame_header.h" #include "ash/public/cpp/frame_header.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller.h" #include "ash/public/cpp/immersive/immersive_fullscreen_controller.h"
#include "ash/public/cpp/login_screen.h" #include "ash/public/cpp/login_screen.h"
#include "ash/public/cpp/metrics_util.h"
#include "ash/public/cpp/overview_test_api.h" #include "ash/public/cpp/overview_test_api.h"
#include "ash/public/cpp/shelf_item.h" #include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -152,6 +153,7 @@ ...@@ -152,6 +153,7 @@
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/ime/chromeos/ime_bridge.h" #include "ui/base/ime/chromeos/ime_bridge.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
...@@ -713,13 +715,26 @@ bool GetDisplayIdFromOptionalArg(const std::unique_ptr<std::string>& arg, ...@@ -713,13 +715,26 @@ bool GetDisplayIdFromOptionalArg(const std::unique_ptr<std::string>& arg,
return true; return true;
} }
using DisplaySmoothnessTrackers = struct SmoothnessTrackerInfo {
std::map<int64_t, std::unique_ptr<ash::FpsCounter>>; base::Optional<ui::ThroughputTracker> tracker;
DisplaySmoothnessTrackers* GetDisplaySmoothnessTrackers() { base::OnceCallback<void(int smoothness)> callback;
static base::NoDestructor<DisplaySmoothnessTrackers> trackers; };
using DisplaySmoothnessTrackerInfos = std::map<int64_t, SmoothnessTrackerInfo>;
DisplaySmoothnessTrackerInfos* GetDisplaySmoothnessTrackerInfos() {
static base::NoDestructor<DisplaySmoothnessTrackerInfos> trackers;
return trackers.get(); return trackers.get();
} }
// Forwards |smoothness| to the callback for |display_id| and resets.
void ForwardSmoothessAndReset(int64_t display_id, int smoothness) {
auto* infos = GetDisplaySmoothnessTrackerInfos();
auto it = infos->find(display_id);
DCHECK(it != infos->end());
DCHECK(it->second.callback);
std::move(it->second.callback).Run(smoothness);
infos->erase(it);
}
std::string ResolutionToString( std::string ResolutionToString(
chromeos::assistant::mojom::AssistantInteractionResolution resolution) { chromeos::assistant::mojom::AssistantInteractionResolution resolution) {
std::stringstream result; std::stringstream result;
...@@ -4416,8 +4431,8 @@ AutotestPrivateStartSmoothnessTrackingFunction::Run() { ...@@ -4416,8 +4431,8 @@ AutotestPrivateStartSmoothnessTrackingFunction::Run() {
Error(base::StrCat({"Invalid display id: ", *params->display_id}))); Error(base::StrCat({"Invalid display id: ", *params->display_id})));
} }
auto* trackers = GetDisplaySmoothnessTrackers(); auto* infos = GetDisplaySmoothnessTrackerInfos();
if (trackers->find(display_id) != trackers->end()) { if (infos->find(display_id) != infos->end()) {
return RespondNow( return RespondNow(
Error(base::StrCat({"Smoothness already tracked for display: ", Error(base::StrCat({"Smoothness already tracked for display: ",
base::NumberToString(display_id)}))); base::NumberToString(display_id)})));
...@@ -4430,8 +4445,11 @@ AutotestPrivateStartSmoothnessTrackingFunction::Run() { ...@@ -4430,8 +4445,11 @@ AutotestPrivateStartSmoothnessTrackingFunction::Run() {
base::NumberToString(display_id)}))); base::NumberToString(display_id)})));
} }
(*trackers)[display_id] = auto tracker =
std::make_unique<ash::FpsCounter>(root_window->layer()->GetCompositor()); root_window->layer()->GetCompositor()->RequestNewThroughputTracker();
tracker.Start(ash::metrics_util::ForSmoothness(
base::BindRepeating(&ForwardSmoothessAndReset, display_id)));
(*infos)[display_id].tracker = std::move(tracker);
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
...@@ -4454,22 +4472,24 @@ AutotestPrivateStopSmoothnessTrackingFunction::Run() { ...@@ -4454,22 +4472,24 @@ AutotestPrivateStopSmoothnessTrackingFunction::Run() {
Error(base::StrCat({"Invalid display id: ", *params->display_id}))); Error(base::StrCat({"Invalid display id: ", *params->display_id})));
} }
auto* trackers = GetDisplaySmoothnessTrackers(); auto* infos = GetDisplaySmoothnessTrackerInfos();
auto it = trackers->find(display_id); auto it = infos->find(display_id);
if (it == trackers->end()) { if (it == infos->end()) {
return RespondNow( return RespondNow(
Error(base::StrCat({"Smoothness is not tracked for display: ", Error(base::StrCat({"Smoothness is not tracked for display: ",
base::NumberToString(display_id)}))); base::NumberToString(display_id)})));
} }
auto fps_tracker = std::move(it->second); it->second.callback = base::BindOnce(
trackers->erase(it); &AutotestPrivateStopSmoothnessTrackingFunction::OnReportSmoothness, this);
it->second.tracker->Stop();
const int smoothness = fps_tracker->ComputeSmoothness(); return did_respond() ? AlreadyResponded() : RespondLater();
if (smoothness == -1) }
return RespondNow(Error("Could not compute smoothness."));
return RespondNow(OneArgument(std::make_unique<base::Value>(smoothness))); void AutotestPrivateStopSmoothnessTrackingFunction::OnReportSmoothness(
int smoothness) {
Respond(OneArgument(std::make_unique<base::Value>(smoothness)));
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -1243,6 +1243,8 @@ class AutotestPrivateStopSmoothnessTrackingFunction : public ExtensionFunction { ...@@ -1243,6 +1243,8 @@ class AutotestPrivateStopSmoothnessTrackingFunction : public ExtensionFunction {
private: private:
~AutotestPrivateStopSmoothnessTrackingFunction() override; ~AutotestPrivateStopSmoothnessTrackingFunction() override;
ResponseAction Run() override; ResponseAction Run() override;
void OnReportSmoothness(int smoothness);
}; };
class AutotestPrivateWaitForAmbientPhotoAnimationFunction class AutotestPrivateWaitForAmbientPhotoAnimationFunction
......
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