-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland: [GRC] Add heuristics UKM and refactor MetricsCollector.
This patch also disables MetricsCollectorTest on Windows because it failed on Win 7 dbg. This is a reland of f28e176 Original change's description: > Reland "Reland "[GRC] Add heuristics UKM and refactor MetricsCollector."" > > This is a reland of 6bc2eb1 > Original change's description: > > Reland "[GRC] Add heuristics UKM and refactor MetricsCollector." > > > > This is a reland of e31b0b4 > > Original change's description: > > > > TBR=chrisha@chromium.org,dcheng@chromium.org,holte@chromium.org > > > [GRC] Add heuristics UKM and refactor MetricsCollector. > > > > > > This patch: > > > 1. adds heuristics UKM; > > > 2. rafactors MetricsCollector to unify background tabs metrics report; > > > 3. moved metrics report 5-minutes timeout logic to MetricsCollector; > > > 4. adds more unit tests. > > > > > > BUG=731270, 753486 > > > > > > Change-Id: Ica08674bf6b95d88f8de571ef025a7eaf58515d7 > > > Reviewed-on: https://chromium-review.googlesource.com/627594 > > > Reviewed-by: Chris Hamilton <chrisha@chromium.org> > > > Reviewed-by: Daniel Cheng <dcheng@chromium.org> > > > Reviewed-by: Steven Holte <holte@chromium.org> > > > Commit-Queue: lpy <lpy@chromium.org> > > > Cr-Commit-Position: refs/heads/master@{#497900} > > > > Bug: 731270, 753486 > > Change-Id: I43c99c0cdc7c7d3431f08fae86cb10d6d87d99fa > > Reviewed-on: https://chromium-review.googlesource.com/640010 > > Reviewed-by: lpy <lpy@chromium.org> > > Commit-Queue: lpy <lpy@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#498395} > > TBR=chrisha@chromium.org,dcheng@chromium.org,holte@chromium.org > > Bug: 731270, 753486 > Change-Id: I65f2a5bc86e8ddd4af4b1739c306b6d1bc70b4b1 > Reviewed-on: https://chromium-review.googlesource.com/643568 > Commit-Queue: lpy <lpy@chromium.org> > Reviewed-by: lpy <lpy@chromium.org> > Cr-Commit-Position: refs/heads/master@{#498965} TBR=chrisha@chromium.org,dcheng@chromium.org,holte@chromium.org Bug: 731270, 753486 Change-Id: I10d8a16821848c8896e054dad0185b368905dc6e Reviewed-on: https://chromium-review.googlesource.com/646533 Reviewed-by: lpy <lpy@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Commit-Queue: lpy <lpy@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#499148}(cherry picked from commit 85b2a0f) Reviewed-on: https://chromium-review.googlesource.com/648186 Cr-Commit-Position: refs/branch-heads/3202@{#7} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
- Loading branch information
Showing
11 changed files
with
572 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
services/resource_coordinator/coordination_unit/background_metrics_reporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// 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. | ||
|
||
#ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_BACKGROUND_METRICS_REPORTER_H_ | ||
#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_BACKGROUND_METRICS_REPORTER_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/metrics/histogram_macros.h" | ||
#include "base/time/time.h" | ||
#include "services/metrics/public/cpp/ukm_builders.h" | ||
|
||
// Tabs can be kept in the background for a long time, metrics show 75th | ||
// percentile of time spent in background is 2.5 hours, and the 95th is 24 hour. | ||
// In order to guide the selection of an appropriate observation window we are | ||
// proposing using a CUSTOM_TIMES histogram from 1s to 48h, with 100 buckets. | ||
#define HEURISTICS_HISTOGRAM(name, sample) \ | ||
UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, base::TimeDelta::FromSeconds(1), \ | ||
base::TimeDelta::FromHours(48), 100) | ||
|
||
namespace ukm { | ||
class MojoUkmRecorder; | ||
} // namespace ukm | ||
|
||
namespace resource_coordinator { | ||
|
||
namespace internal { | ||
|
||
enum UKMFrameReportType : uint8_t { | ||
kMainFrameOnly = 0, | ||
kMainFrameAndChildFrame | ||
}; | ||
|
||
template <class UKMBuilderClass, | ||
internal::UKMFrameReportType kShouldReportChildFrameUkm> | ||
class UKMReportDelegate {}; | ||
|
||
template <class UKMBuilderClass> | ||
class UKMReportDelegate<UKMBuilderClass, internal::kMainFrameOnly> { | ||
public: | ||
void ReportUKM(int64_t ukm_source_id, | ||
bool is_main_frame, | ||
int64_t duration_in_ms, | ||
ukm::MojoUkmRecorder* ukm_recorder) { | ||
UKMBuilderClass ukm_builder(ukm_source_id); | ||
ukm_builder.SetTimeFromBackgrounded(duration_in_ms).Record(ukm_recorder); | ||
} | ||
}; | ||
|
||
template <class UKMBuilderClass> | ||
class UKMReportDelegate<UKMBuilderClass, internal::kMainFrameAndChildFrame> { | ||
public: | ||
void ReportUKM(int64_t ukm_source_id, | ||
bool is_main_frame, | ||
int64_t duration_in_ms, | ||
ukm::MojoUkmRecorder* ukm_recorder) { | ||
UKMBuilderClass ukm_builder(ukm_source_id); | ||
ukm_builder.SetIsMainFrame(is_main_frame) | ||
.SetTimeFromBackgrounded(duration_in_ms) | ||
.Record(ukm_recorder); | ||
} | ||
}; | ||
|
||
} // namespace internal | ||
|
||
template <class UKMBuilderClass, | ||
const char* kMetricName, | ||
internal::UKMFrameReportType kShouldReportChildFrameUkm> | ||
class BackgroundMetricsReporter { | ||
public: | ||
BackgroundMetricsReporter() | ||
: ukm_source_id_(-1), | ||
uma_reported_(false), | ||
ukm_reported_(false), | ||
child_frame_ukm_reported_(false) {} | ||
|
||
void Reset() { | ||
uma_reported_ = false; | ||
ukm_reported_ = false; | ||
child_frame_ukm_reported_ = false; | ||
} | ||
|
||
void SetUKMSourceID(int64_t ukm_source_id) { ukm_source_id_ = ukm_source_id; } | ||
|
||
void OnSignalReceived(bool is_main_frame, | ||
base::TimeDelta duration, | ||
ukm::MojoUkmRecorder* ukm_recorder) { | ||
if (!uma_reported_) { | ||
uma_reported_ = true; | ||
HEURISTICS_HISTOGRAM(kMetricName, duration); | ||
} | ||
|
||
ReportUKMIfNeeded(is_main_frame, duration, ukm_recorder); | ||
} | ||
|
||
private: | ||
void ReportUKMIfNeeded(bool is_main_frame, | ||
base::TimeDelta duration, | ||
ukm::MojoUkmRecorder* ukm_recorder) { | ||
if (ukm_source_id_ == -1 || | ||
(!kShouldReportChildFrameUkm && ukm_reported_) || | ||
(kShouldReportChildFrameUkm && | ||
!ShouldReportMainFrameUKM(is_main_frame) && | ||
!ShouldReportChildFrameUKM(is_main_frame))) { | ||
return; | ||
} | ||
|
||
ukm_reporter_.ReportUKM(ukm_source_id_, is_main_frame, | ||
duration.InMilliseconds(), ukm_recorder); | ||
|
||
if (is_main_frame) { | ||
ukm_reported_ = true; | ||
} else { | ||
child_frame_ukm_reported_ = true; | ||
} | ||
} | ||
|
||
bool ShouldReportMainFrameUKM(bool is_main_frame) const { | ||
return is_main_frame && !ukm_reported_; | ||
} | ||
|
||
bool ShouldReportChildFrameUKM(bool is_main_frame) const { | ||
return !is_main_frame && !child_frame_ukm_reported_; | ||
} | ||
|
||
int64_t ukm_source_id_; | ||
bool uma_reported_; | ||
bool ukm_reported_; | ||
bool child_frame_ukm_reported_; | ||
internal::UKMReportDelegate<UKMBuilderClass, kShouldReportChildFrameUkm> | ||
ukm_reporter_; | ||
}; | ||
|
||
} // namespace resource_coordinator | ||
|
||
#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_BACKGROUND_METRICS_REPORTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.