Commit 6ed08ad9 authored by Alice Boxhall's avatar Alice Boxhall Committed by Commit Bot

Revert "chromeos: removes time_to_first_present.mojom"

This reverts commit f9d8f7f6.

Reason for revert: Apologies, this test seems to be timing out:
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8913896950441933072/+/steps/browser_tests/0/logs/Deterministic_failure:_TimeToFirstPresentRecorderTest.VerifyTimeCalculated__status_TIMEOUT_/0

Original change's description:
> chromeos: removes time_to_first_present.mojom
> 
> And instead has ash directly access the startup time.
> 
> BUG=958213
> TEST=covered by tests
> TBR=tsepez@chromium.org
> 
> Change-Id: I146c27edef79ff8fb69ca7cdd7f230ad77f040a8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602854
> Reviewed-by: Scott Violet <sky@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Reviewed-by: James Cook <jamescook@chromium.org>
> Commit-Queue: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#658315}

TBR=jamescook@chromium.org,sky@chromium.org,tsepez@chromium.org

Change-Id: I272066f1adc2866821a5195dca1907a6f077069a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 958213
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605255Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Commit-Queue: Alice Boxhall <aboxhall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658455}
parent 5b8dfb30
...@@ -1361,7 +1361,6 @@ component("ash") { ...@@ -1361,7 +1361,6 @@ component("ash") {
"//components/prefs", "//components/prefs",
"//components/quirks", "//components/quirks",
"//components/session_manager:base", "//components/session_manager:base",
"//components/startup_metric_utils/browser:lib",
"//components/strings", "//components/strings",
"//components/sync", "//components/sync",
"//components/user_manager", "//components/user_manager",
......
...@@ -13,7 +13,6 @@ include_rules = [ ...@@ -13,7 +13,6 @@ include_rules = [
"+components/prefs", "+components/prefs",
"+components/quirks", "+components/quirks",
"+components/session_manager", "+components/session_manager",
"+components/startup_metric_utils",
"+components/strings", "+components/strings",
"+components/sync", "+components/sync",
"+components/ui_devtools", "+components/ui_devtools",
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
...@@ -16,10 +15,6 @@ ...@@ -16,10 +15,6 @@
namespace ash { namespace ash {
// static
const char TimeToFirstPresentRecorder::kMetricName[] =
"Ash.ProcessCreationToFirstPresent";
TimeToFirstPresentRecorder::TimeToFirstPresentRecorder(aura::Window* window) { TimeToFirstPresentRecorder::TimeToFirstPresentRecorder(aura::Window* window) {
aura::WindowTreeHost* window_tree_host = window->GetHost(); aura::WindowTreeHost* window_tree_host = window->GetHost();
DCHECK(window_tree_host); DCHECK(window_tree_host);
...@@ -30,13 +25,42 @@ TimeToFirstPresentRecorder::TimeToFirstPresentRecorder(aura::Window* window) { ...@@ -30,13 +25,42 @@ TimeToFirstPresentRecorder::TimeToFirstPresentRecorder(aura::Window* window) {
TimeToFirstPresentRecorder::~TimeToFirstPresentRecorder() = default; TimeToFirstPresentRecorder::~TimeToFirstPresentRecorder() = default;
void TimeToFirstPresentRecorder::DidPresentCompositorFrame( void TimeToFirstPresentRecorder::Bind(
const gfx::PresentationFeedback& feedback) { mojom::ProcessCreationTimeRecorderRequest request) {
const base::TimeDelta time_to_first_present = // Process createion time should only be set once.
feedback.timestamp - startup_metric_utils::MainEntryPointTicks(); if (binding_.is_bound() || !process_creation_time_.is_null())
UMA_HISTOGRAM_TIMES(kMetricName, time_to_first_present); return;
binding_.Bind(std::move(request));
}
void TimeToFirstPresentRecorder::SetMainProcessCreationTime(
base::TimeTicks start_time) {
if (!process_creation_time_.is_null())
return;
process_creation_time_ = start_time;
LogTime();
// Process creation time should be set only once.
binding_.Close();
}
void TimeToFirstPresentRecorder::LogTime() {
if (present_time_.is_null() || process_creation_time_.is_null())
return;
UMA_HISTOGRAM_TIMES("Ash.ProcessCreationToFirstPresent",
time_to_first_present());
if (log_callback_) if (log_callback_)
std::move(log_callback_).Run(); std::move(log_callback_).Run();
} }
void TimeToFirstPresentRecorder::DidPresentCompositorFrame(
const gfx::PresentationFeedback& feedback) {
DCHECK(present_time_.is_null()); // This should only be called once.
present_time_ = feedback.timestamp;
LogTime();
}
} // namespace ash } // namespace ash
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#include <stdint.h> #include <stdint.h>
#include "ash/ash_export.h" #include "ash/public/interfaces/process_creation_time_recorder.mojom.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace aura { namespace aura {
class Window; class Window;
...@@ -24,26 +26,41 @@ namespace ash { ...@@ -24,26 +26,41 @@ namespace ash {
class TimeToFirstPresentRecorderTestApi; class TimeToFirstPresentRecorderTestApi;
// Used for tracking the time main started to the time the first bits make it // Used for tracking the time main started to the time the first bits make it
// the screen and logging a histogram of the time. // the screen and logging a histogram of the time. Chrome is responsible for
// providing the start time by way of ProcessCreationTimeRecorder.
// //
// This only logs the time to present the primary root window. // This only logs the time to present the primary root window.
class ASH_EXPORT TimeToFirstPresentRecorder { class TimeToFirstPresentRecorder : public mojom::ProcessCreationTimeRecorder {
public: public:
// The name of the histogram the time is logged against.
static const char kMetricName[];
explicit TimeToFirstPresentRecorder(aura::Window* window); explicit TimeToFirstPresentRecorder(aura::Window* window);
~TimeToFirstPresentRecorder(); ~TimeToFirstPresentRecorder() override;
void Bind(mojom::ProcessCreationTimeRecorderRequest request);
private: private:
friend class TimeToFirstPresentRecorderTestApi; friend class TimeToFirstPresentRecorderTestApi;
// If both times are available the time to present is logged.
void LogTime();
// Callback from the compositor when it presented a valid frame. // Callback from the compositor when it presented a valid frame.
void DidPresentCompositorFrame(const gfx::PresentationFeedback& feedback); void DidPresentCompositorFrame(const gfx::PresentationFeedback& feedback);
// Only used by tests. If valid it's Run() when the time is recorded. base::TimeDelta time_to_first_present() const {
return present_time_ - process_creation_time_;
}
// mojom::ProcessCreationTimeRecorder:
void SetMainProcessCreationTime(base::TimeTicks start_time) override;
base::TimeTicks process_creation_time_;
base::TimeTicks present_time_;
// Only used by tests. If valid it's Run() when both times are determined.
base::OnceClosure log_callback_; base::OnceClosure log_callback_;
mojo::Binding<mojom::ProcessCreationTimeRecorder> binding_{this};
DISALLOW_COPY_AND_ASSIGN(TimeToFirstPresentRecorder); DISALLOW_COPY_AND_ASSIGN(TimeToFirstPresentRecorder);
}; };
......
...@@ -7,14 +7,52 @@ ...@@ -7,14 +7,52 @@
#include "ash/metrics/time_to_first_present_recorder.h" #include "ash/metrics/time_to_first_present_recorder.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace ash { namespace ash {
TimeToFirstPresentRecorderTestApi::TimeToFirstPresentRecorderTestApi() =
default;
TimeToFirstPresentRecorderTestApi::~TimeToFirstPresentRecorderTestApi() =
default;
// static // static
void TimeToFirstPresentRecorderTestApi::SetTimeToFirstPresentCallback( void TimeToFirstPresentRecorderTestApi::BindRequest(
base::OnceClosure callback) { mojom::TimeToFirstPresentRecorderTestApiRequest request) {
Shell::Get()->time_to_first_present_recorder()->log_callback_ = mojo::MakeStrongBinding(std::make_unique<TimeToFirstPresentRecorderTestApi>(),
std::move(callback); std::move(request));
}
void TimeToFirstPresentRecorderTestApi::GetProcessCreationToFirstPresentTime(
GetProcessCreationToFirstPresentTimeCallback callback) {
TimeToFirstPresentRecorder* recorder =
Shell::Get()->time_to_first_present_recorder();
if (recorder->process_creation_time_.is_null() ||
recorder->present_time_.is_null()) {
// Still waiting for time. Schedule a callback with
// TimeToFirstPresentRecorder. This only supports one callback at a time,
// which should be fine for tests.
DCHECK(recorder->log_callback_.is_null());
recorder->log_callback_ = base::BindOnce(
&TimeToFirstPresentRecorderTestApi::OnLog, base::Unretained(this));
DCHECK(!get_creation_time_callback_);
get_creation_time_callback_ = std::move(callback);
return;
}
std::move(callback).Run(recorder->time_to_first_present());
}
void TimeToFirstPresentRecorderTestApi::OnLog() {
TimeToFirstPresentRecorder* recorder =
Shell::Get()->time_to_first_present_recorder();
DCHECK(!recorder->process_creation_time_.is_null() &&
!recorder->present_time_.is_null());
std::move(get_creation_time_callback_)
.Run(Shell::Get()
->time_to_first_present_recorder()
->time_to_first_present());
} }
} // namespace ash } // namespace ash
...@@ -5,17 +5,33 @@ ...@@ -5,17 +5,33 @@
#ifndef ASH_METRICS_TIME_TO_FIRST_PRESENT_RECORDER_TEST_API_H_ #ifndef ASH_METRICS_TIME_TO_FIRST_PRESENT_RECORDER_TEST_API_H_
#define ASH_METRICS_TIME_TO_FIRST_PRESENT_RECORDER_TEST_API_H_ #define ASH_METRICS_TIME_TO_FIRST_PRESENT_RECORDER_TEST_API_H_
#include "base/callback_forward.h" #include "ash/public/interfaces/time_to_first_present_recorder_test_api.test-mojom.h"
#include "base/macros.h" #include "base/macros.h"
namespace ash { namespace ash {
class TimeToFirstPresentRecorderTestApi { class TimeToFirstPresentRecorderTestApi
: public mojom::TimeToFirstPresentRecorderTestApi {
public: public:
static void SetTimeToFirstPresentCallback(base::OnceClosure callback); TimeToFirstPresentRecorderTestApi();
~TimeToFirstPresentRecorderTestApi() override;
// Creates and binds an instance from a remote request (e.g. from chrome).
static void BindRequest(
mojom::TimeToFirstPresentRecorderTestApiRequest request);
// mojom::TimeToFirstPresentRecorderTestApi:
void GetProcessCreationToFirstPresentTime(
GetProcessCreationToFirstPresentTimeCallback callback) override;
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TimeToFirstPresentRecorderTestApi); void OnLog();
// If valid GetProcessCreationToFirstPresentTimeCallback() was called and
// we're waiting for TimeToFirstPresentRecorder to see the first log.
GetProcessCreationToFirstPresentTimeCallback get_creation_time_callback_;
DISALLOW_COPY_AND_ASSIGN(TimeToFirstPresentRecorderTestApi);
}; };
} // namespace ash } // namespace ash
......
...@@ -210,6 +210,11 @@ void BindNoteTakingControllerRequestOnMainThread( ...@@ -210,6 +210,11 @@ void BindNoteTakingControllerRequestOnMainThread(
Shell::Get()->note_taking_controller()->BindRequest(std::move(request)); Shell::Get()->note_taking_controller()->BindRequest(std::move(request));
} }
void BindProcessCreationTimeRecorderOnMainThread(
mojom::ProcessCreationTimeRecorderRequest request) {
Shell::Get()->time_to_first_present_recorder()->Bind(std::move(request));
}
void BindShelfRequestOnMainThread(mojom::ShelfControllerRequest request) { void BindShelfRequestOnMainThread(mojom::ShelfControllerRequest request) {
Shell::Get()->shelf_controller()->BindRequest(std::move(request)); Shell::Get()->shelf_controller()->BindRequest(std::move(request));
} }
...@@ -347,6 +352,9 @@ void RegisterInterfaces( ...@@ -347,6 +352,9 @@ void RegisterInterfaces(
registry->AddInterface( registry->AddInterface(
base::BindRepeating(&BindNoteTakingControllerRequestOnMainThread), base::BindRepeating(&BindNoteTakingControllerRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
registry->AddInterface(
base::BindRepeating(&BindProcessCreationTimeRecorderOnMainThread),
main_thread_task_runner);
registry->AddInterface(base::BindRepeating(&BindShelfRequestOnMainThread), registry->AddInterface(base::BindRepeating(&BindShelfRequestOnMainThread),
main_thread_task_runner); main_thread_task_runner);
registry->AddInterface( registry->AddInterface(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/public/interfaces/shell_test_api.test-mojom.h" #include "ash/public/interfaces/shell_test_api.test-mojom.h"
#include "ash/public/interfaces/status_area_widget_test_api.test-mojom.h" #include "ash/public/interfaces/status_area_widget_test_api.test-mojom.h"
#include "ash/public/interfaces/system_tray_test_api.test-mojom.h" #include "ash/public/interfaces/system_tray_test_api.test-mojom.h"
#include "ash/public/interfaces/time_to_first_present_recorder_test_api.test-mojom.h"
#include "ash/shelf/shelf_test_api.h" #include "ash/shelf/shelf_test_api.h"
#include "ash/shell_test_api.h" #include "ash/shell_test_api.h"
#include "ash/system/status_area_widget_test_api.h" #include "ash/system/status_area_widget_test_api.h"
...@@ -50,6 +51,11 @@ void BindSystemTrayTestApiOnMainThread( ...@@ -50,6 +51,11 @@ void BindSystemTrayTestApiOnMainThread(
UnifiedSystemTrayTestApi::BindRequest(std::move(request)); UnifiedSystemTrayTestApi::BindRequest(std::move(request));
} }
void BindTimeToFirstPresentRecorderTestApiOnMainThread(
mojom::TimeToFirstPresentRecorderTestApiRequest request) {
TimeToFirstPresentRecorderTestApi::BindRequest(std::move(request));
}
} // namespace } // namespace
void RegisterInterfaces( void RegisterInterfaces(
...@@ -65,6 +71,9 @@ void RegisterInterfaces( ...@@ -65,6 +71,9 @@ void RegisterInterfaces(
main_thread_task_runner); main_thread_task_runner);
registry->AddInterface(base::Bind(&BindSystemTrayTestApiOnMainThread), registry->AddInterface(base::Bind(&BindSystemTrayTestApiOnMainThread),
main_thread_task_runner); main_thread_task_runner);
registry->AddInterface(
base::Bind(&BindTimeToFirstPresentRecorderTestApiOnMainThread),
main_thread_task_runner);
} }
} // namespace mojo_test_interface_factory } // namespace mojo_test_interface_factory
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ash/public/interfaces/night_light_controller.mojom.h" #include "ash/public/interfaces/night_light_controller.mojom.h"
#include "ash/public/interfaces/note_taking_controller.mojom.h" #include "ash/public/interfaces/note_taking_controller.mojom.h"
#include "ash/public/interfaces/pref_connector.mojom.h" #include "ash/public/interfaces/pref_connector.mojom.h"
#include "ash/public/interfaces/process_creation_time_recorder.mojom.h"
#include "ash/public/interfaces/shelf.mojom.h" #include "ash/public/interfaces/shelf.mojom.h"
#include "ash/public/interfaces/shelf_integration_test_api.mojom.h" #include "ash/public/interfaces/shelf_integration_test_api.mojom.h"
#include "ash/public/interfaces/shutdown.mojom.h" #include "ash/public/interfaces/shutdown.mojom.h"
...@@ -90,7 +91,8 @@ const service_manager::Manifest& GetManifest() { ...@@ -90,7 +91,8 @@ const service_manager::Manifest& GetManifest() {
mojom::KeyboardController, mojom::LocaleUpdateController, mojom::KeyboardController, mojom::LocaleUpdateController,
mojom::LoginScreen, mojom::MediaController, mojom::LoginScreen, mojom::MediaController,
mojom::NewWindowController, mojom::NightLightController, mojom::NewWindowController, mojom::NightLightController,
mojom::NoteTakingController, mojom::ShelfController, mojom::NoteTakingController,
mojom::ProcessCreationTimeRecorder, mojom::ShelfController,
mojom::ShutdownController, mojom::SystemTray, mojom::ShutdownController, mojom::SystemTray,
mojom::TabletModeController, mojom::TrayAction, mojom::TabletModeController, mojom::TrayAction,
mojom::VoiceInteractionController, mojom::VpnList, mojom::VoiceInteractionController, mojom::VpnList,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/public/interfaces/shell_test_api.test-mojom.h" #include "ash/public/interfaces/shell_test_api.test-mojom.h"
#include "ash/public/interfaces/status_area_widget_test_api.test-mojom.h" #include "ash/public/interfaces/status_area_widget_test_api.test-mojom.h"
#include "ash/public/interfaces/system_tray_test_api.test-mojom.h" #include "ash/public/interfaces/system_tray_test_api.test-mojom.h"
#include "ash/public/interfaces/time_to_first_present_recorder_test_api.test-mojom.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "services/service_manager/public/cpp/manifest_builder.h" #include "services/service_manager/public/cpp/manifest_builder.h"
...@@ -21,7 +22,8 @@ const service_manager::Manifest& GetManifestOverlayForTesting() { ...@@ -21,7 +22,8 @@ const service_manager::Manifest& GetManifestOverlayForTesting() {
"test", service_manager::Manifest::InterfaceList< "test", service_manager::Manifest::InterfaceList<
mojom::LoginScreenTestApi, mojom::ShelfTestApi, mojom::LoginScreenTestApi, mojom::ShelfTestApi,
mojom::ShellTestApi, mojom::StatusAreaWidgetTestApi, mojom::ShellTestApi, mojom::StatusAreaWidgetTestApi,
mojom::SystemTrayTestApi>()) mojom::SystemTrayTestApi,
mojom::TimeToFirstPresentRecorderTestApi>())
.Build()}; .Build()};
return *manifest; return *manifest;
} }
......
...@@ -50,6 +50,7 @@ mojom("interfaces_internal") { ...@@ -50,6 +50,7 @@ mojom("interfaces_internal") {
"night_light_controller.mojom", "night_light_controller.mojom",
"note_taking_controller.mojom", "note_taking_controller.mojom",
"pref_connector.mojom", "pref_connector.mojom",
"process_creation_time_recorder.mojom",
"shelf.mojom", "shelf.mojom",
"shelf_integration_test_api.mojom", "shelf_integration_test_api.mojom",
"shutdown.mojom", "shutdown.mojom",
...@@ -103,6 +104,7 @@ mojom("test_interfaces") { ...@@ -103,6 +104,7 @@ mojom("test_interfaces") {
"shell_test_api.test-mojom", "shell_test_api.test-mojom",
"status_area_widget_test_api.test-mojom", "status_area_widget_test_api.test-mojom",
"system_tray_test_api.test-mojom", "system_tray_test_api.test-mojom",
"time_to_first_present_recorder_test_api.test-mojom",
] ]
deps = [ deps = [
"//ash/public/interfaces:interfaces_internal", "//ash/public/interfaces:interfaces_internal",
......
// Copyright 2017 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.
module ash.mojom;
import "mojo/public/mojom/base/time.mojom";
interface ProcessCreationTimeRecorder {
// Sets the time the main process was created at, used for logging metrics.
SetMainProcessCreationTime(mojo_base.mojom.TimeTicks start_time);
};
// Copyright 2017 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.
module ash.mojom;
import "mojo/public/mojom/base/time.mojom";
// Used to test internal state of TimeToFirstPresentRecorder.
interface TimeToFirstPresentRecorderTestApi {
// Returns the time between process creation and the first pixels shown on
// screen.
GetProcessCreationToFirstPresentTime() => (mojo_base.mojom.TimeDelta delta);
};
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/public/interfaces/constants.mojom.h" #include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/process_creation_time_recorder.mojom.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -73,6 +74,20 @@ ...@@ -73,6 +74,20 @@
#include "chrome/browser/exo_parts.h" #include "chrome/browser/exo_parts.h"
#endif #endif
namespace {
void PushProcessCreationTimeToAsh() {
ash::mojom::ProcessCreationTimeRecorderPtr recorder;
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &recorder);
DCHECK(!startup_metric_utils::MainEntryPointTicks().is_null());
recorder->SetMainProcessCreationTime(
startup_metric_utils::MainEntryPointTicks());
}
} // namespace
namespace internal { namespace internal {
// Creates a ChromeLauncherController on the first active session notification. // Creates a ChromeLauncherController on the first active session notification.
...@@ -189,6 +204,8 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { ...@@ -189,6 +204,8 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
#if BUILDFLAG(ENABLE_WAYLAND_SERVER) #if BUILDFLAG(ENABLE_WAYLAND_SERVER)
exo_parts_ = ExoParts::CreateIfNecessary(); exo_parts_ = ExoParts::CreateIfNecessary();
#endif #endif
PushProcessCreationTimeToAsh();
} }
void ChromeBrowserMainExtraPartsAsh::PostProfileInit() { void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
......
...@@ -2,30 +2,24 @@ ...@@ -2,30 +2,24 @@
// 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 "ash/metrics/time_to_first_present_recorder.h" #include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/time_to_first_present_recorder_test_api.test-mojom-test-utils.h"
#include "ash/metrics/time_to_first_present_recorder_test_api.h" #include "ash/public/interfaces/time_to_first_present_recorder_test_api.test-mojom.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
using TimeToFirstPresentRecorderTest = InProcessBrowserTest; using TimeToFirstPresentRecorderTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(TimeToFirstPresentRecorderTest, VerifyTimeCalculated) { IN_PROC_BROWSER_TEST_F(TimeToFirstPresentRecorderTest, VerifyTimeCalculated) {
// It's possible that the metric was already recorded. ash::mojom::TimeToFirstPresentRecorderTestApiPtr recorder_test_api;
base::HistogramTester tester; content::ServiceManagerConnection::GetForProcess()
auto counts = tester.GetTotalCountsForPrefix( ->GetConnector()
ash::TimeToFirstPresentRecorder::kMetricName); ->BindInterface(ash::mojom::kServiceName, &recorder_test_api);
if (counts[ash::TimeToFirstPresentRecorder::kMetricName] == 1) ash::mojom::TimeToFirstPresentRecorderTestApiAsyncWaiter recorder(
return; recorder_test_api.get());
base::TimeDelta time_delta;
// The metric wasn't recorded. Wait for it to be recorded. recorder.GetProcessCreationToFirstPresentTime(&time_delta);
base::RunLoop run_loop; EXPECT_FALSE(time_delta.is_zero());
ash::TimeToFirstPresentRecorderTestApi::SetTimeToFirstPresentCallback(
run_loop.QuitClosure());
run_loop.Run();
counts = tester.GetTotalCountsForPrefix(
ash::TimeToFirstPresentRecorder::kMetricName);
EXPECT_EQ(1, counts[ash::TimeToFirstPresentRecorder::kMetricName]);
} }
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