Commit 8c3ed0d8 authored by Jiewei Qian's avatar Jiewei Qian Committed by Commit Bot

system-web-app: add install duration metric

Bug: 1021813
Change-Id: Ie148398f2e670164c3acd82c666335c9d2a71781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1921600
Commit-Queue: Jiewei Qian  <qjw@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719087}
parent 598ddc40
...@@ -395,6 +395,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) { ...@@ -395,6 +395,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) {
SystemWebAppManager::kInstallResultHistogramName, 0); SystemWebAppManager::kInstallResultHistogramName, 0);
histograms.ExpectTotalCount(settings_app_install_result_histogram, 0); histograms.ExpectTotalCount(settings_app_install_result_histogram, 0);
histograms.ExpectTotalCount(profile_install_result_histogram, 0); histograms.ExpectTotalCount(profile_install_result_histogram, 0);
histograms.ExpectTotalCount(
SystemWebAppManager::kInstallDurationHistogramName, 0);
system_web_app_manager()->Start(); system_web_app_manager()->Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -410,6 +412,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) { ...@@ -410,6 +412,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) {
histograms.ExpectTotalCount(profile_install_result_histogram, 1); histograms.ExpectTotalCount(profile_install_result_histogram, 1);
histograms.ExpectBucketCount(profile_install_result_histogram, histograms.ExpectBucketCount(profile_install_result_histogram,
InstallResultCode::kSuccessNewInstall, 1); InstallResultCode::kSuccessNewInstall, 1);
histograms.ExpectTotalCount(
SystemWebAppManager::kInstallDurationHistogramName, 1);
} }
{ {
base::flat_map<SystemAppType, SystemAppInfo> system_apps; base::flat_map<SystemAppType, SystemAppInfo> system_apps;
...@@ -447,6 +451,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) { ...@@ -447,6 +451,8 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) {
pending_app_manager()->SetInstallResultCode( pending_app_manager()->SetInstallResultCode(
InstallResultCode::kProfileDestroyed); InstallResultCode::kProfileDestroyed);
histograms.ExpectTotalCount(
SystemWebAppManager::kInstallDurationHistogramName, 2);
histograms.ExpectBucketCount(settings_app_install_result_histogram, histograms.ExpectBucketCount(settings_app_install_result_histogram,
InstallResultCode::kFailedShuttingDown, 0); InstallResultCode::kFailedShuttingDown, 0);
histograms.ExpectBucketCount(profile_install_result_histogram, histograms.ExpectBucketCount(profile_install_result_histogram,
...@@ -467,6 +473,9 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) { ...@@ -467,6 +473,9 @@ TEST_F(SystemWebAppManagerTest, InstallResultHistogram) {
InstallResultCode::kFailedShuttingDown, 1); InstallResultCode::kFailedShuttingDown, 1);
histograms.ExpectBucketCount(profile_install_result_histogram, histograms.ExpectBucketCount(profile_install_result_histogram,
InstallResultCode::kFailedShuttingDown, 1); InstallResultCode::kFailedShuttingDown, 1);
// If install was interrupted by shutdown, do not report duration.
histograms.ExpectTotalCount(
SystemWebAppManager::kInstallDurationHistogramName, 2);
} }
} }
......
...@@ -129,6 +129,7 @@ SystemAppInfo::~SystemAppInfo() = default; ...@@ -129,6 +129,7 @@ SystemAppInfo::~SystemAppInfo() = default;
// static // static
const char SystemWebAppManager::kInstallResultHistogramName[]; const char SystemWebAppManager::kInstallResultHistogramName[];
const char SystemWebAppManager::kInstallDurationHistogramName[];
// static // static
bool SystemWebAppManager::IsAppEnabled(SystemAppType type) { bool SystemWebAppManager::IsAppEnabled(SystemAppType type) {
...@@ -191,6 +192,8 @@ void SystemWebAppManager::SetSubsystems(PendingAppManager* pending_app_manager, ...@@ -191,6 +192,8 @@ void SystemWebAppManager::SetSubsystems(PendingAppManager* pending_app_manager,
} }
void SystemWebAppManager::Start() { void SystemWebAppManager::Start() {
const base::TimeTicks install_start_time = base::TimeTicks::Now();
std::vector<ExternalInstallOptions> install_options_list; std::vector<ExternalInstallOptions> install_options_list;
if (IsEnabled()) { if (IsEnabled()) {
// Skipping this will uninstall all System Apps currently installed. // Skipping this will uninstall all System Apps currently installed.
...@@ -199,11 +202,10 @@ void SystemWebAppManager::Start() { ...@@ -199,11 +202,10 @@ void SystemWebAppManager::Start() {
CreateInstallOptionsForSystemApp(app.second, NeedsUpdate())); CreateInstallOptionsForSystemApp(app.second, NeedsUpdate()));
} }
} }
pending_app_manager_->SynchronizeInstalledApps( pending_app_manager_->SynchronizeInstalledApps(
std::move(install_options_list), ExternalInstallSource::kSystemInstalled, std::move(install_options_list), ExternalInstallSource::kSystemInstalled,
base::BindOnce(&SystemWebAppManager::OnAppsSynchronized, base::BindOnce(&SystemWebAppManager::OnAppsSynchronized,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr(), install_start_time));
} }
void SystemWebAppManager::InstallSystemAppsForTesting() { void SystemWebAppManager::InstallSystemAppsForTesting() {
...@@ -281,8 +283,15 @@ const std::string& SystemWebAppManager::CurrentLocale() const { ...@@ -281,8 +283,15 @@ const std::string& SystemWebAppManager::CurrentLocale() const {
return g_browser_process->GetApplicationLocale(); return g_browser_process->GetApplicationLocale();
} }
void SystemWebAppManager::RecordSystemWebAppInstallResultCode( void SystemWebAppManager::RecordSystemWebAppInstallMetrics(
const std::map<GURL, InstallResultCode>& install_results) const { const std::map<GURL, InstallResultCode>& install_results,
const base::TimeDelta& install_duration) const {
// Record the time spent to install system web apps.
if (!shutting_down_) {
base::UmaHistogramMediumTimes(kInstallDurationHistogramName,
install_duration);
}
// Record aggregate result. // Record aggregate result.
for (const auto& url_and_result : install_results) for (const auto& url_and_result : install_results)
base::UmaHistogramEnumeration(kInstallResultHistogramName, base::UmaHistogramEnumeration(kInstallResultHistogramName,
...@@ -315,8 +324,12 @@ void SystemWebAppManager::RecordSystemWebAppInstallResultCode( ...@@ -315,8 +324,12 @@ void SystemWebAppManager::RecordSystemWebAppInstallResultCode(
} }
void SystemWebAppManager::OnAppsSynchronized( void SystemWebAppManager::OnAppsSynchronized(
const base::TimeTicks& install_start_time,
std::map<GURL, InstallResultCode> install_results, std::map<GURL, InstallResultCode> install_results,
std::map<GURL, bool> uninstall_results) { std::map<GURL, bool> uninstall_results) {
const base::TimeDelta install_duration =
install_start_time - base::TimeTicks::Now();
if (IsEnabled()) { if (IsEnabled()) {
// TODO(qjw): Figure out where install_results come from, decide if // TODO(qjw): Figure out where install_results come from, decide if
// installation failures need to be handled // installation failures need to be handled
...@@ -326,7 +339,7 @@ void SystemWebAppManager::OnAppsSynchronized( ...@@ -326,7 +339,7 @@ void SystemWebAppManager::OnAppsSynchronized(
CurrentLocale()); CurrentLocale());
} }
RecordSystemWebAppInstallResultCode(install_results); RecordSystemWebAppInstallMetrics(install_results, install_duration);
// Build the map from installed app id to app type. // Build the map from installed app id to app type.
for (const auto& it : system_app_infos_) { for (const auto& it : system_app_infos_) {
......
...@@ -81,6 +81,8 @@ class SystemWebAppManager { ...@@ -81,6 +81,8 @@ class SystemWebAppManager {
static constexpr char kInstallResultHistogramName[] = static constexpr char kInstallResultHistogramName[] =
"Webapp.InstallResult.System"; "Webapp.InstallResult.System";
static constexpr char kInstallDurationHistogramName[] =
"Webapp.InstallDuration.System";
// Returns whether the given app type is enabled. // Returns whether the given app type is enabled.
static bool IsAppEnabled(SystemAppType type); static bool IsAppEnabled(SystemAppType type);
...@@ -138,12 +140,14 @@ class SystemWebAppManager { ...@@ -138,12 +140,14 @@ class SystemWebAppManager {
virtual const std::string& CurrentLocale() const; virtual const std::string& CurrentLocale() const;
private: private:
void OnAppsSynchronized(std::map<GURL, InstallResultCode> install_results, void OnAppsSynchronized(const base::TimeTicks& install_start_time,
std::map<GURL, InstallResultCode> install_results,
std::map<GURL, bool> uninstall_results); std::map<GURL, bool> uninstall_results);
bool NeedsUpdate() const; bool NeedsUpdate() const;
void RecordSystemWebAppInstallResultCode( void RecordSystemWebAppInstallMetrics(
const std::map<GURL, InstallResultCode>& install_results) const; const std::map<GURL, InstallResultCode>& install_results,
const base::TimeDelta& install_duration) const;
std::unique_ptr<base::OneShotEvent> on_apps_synchronized_; std::unique_ptr<base::OneShotEvent> on_apps_synchronized_;
......
...@@ -162465,6 +162465,16 @@ regressions. --> ...@@ -162465,6 +162465,16 @@ regressions. -->
</summary> </summary>
</histogram> </histogram>
<histogram name="Webapp.InstallDuration.System" units="seconds"
expires_after="2020-06-30">
<owner>calamity@chromium.org</owner>
<owner>ortuno@chromium.org</owner>
<summary>
Records the number of seconds taken to install system web apps, from when we
dispatch a call to install them, until we get all the installation results.
</summary>
</histogram>
<histogram name="Webapp.InstallResult" enum="WebAppInstallResultCode" <histogram name="Webapp.InstallResult" enum="WebAppInstallResultCode"
expires_after="2020-06-30"> expires_after="2020-06-30">
<!-- Name completed by histogram_suffixes name="WebAppType" --> <!-- Name completed by histogram_suffixes name="WebAppType" -->
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