Commit 3d99da2a authored by Gabriel Marin's avatar Gabriel Marin Committed by Commit Bot

PerfProvider: Factor out CollectionParams as a top level class

CollectionParams will need to be visible to multiple classes in
metrics/perf, but not outside the CWP code, so it is stored as a top
level class in an internal namespace.

This CL is part of a larger restructuring of the PerfProvider class to
enable additional collectors.

BUG=b:116527691
TEST=Unit tests pass

Change-Id: I625d71685fba2042599c57f27fea0462eabc1f8c
Reviewed-on: https://chromium-review.googlesource.com/c/1343353
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613400}
parent 0e678a5f
...@@ -3159,6 +3159,8 @@ jumbo_split_static_library("browser") { ...@@ -3159,6 +3159,8 @@ jumbo_split_static_library("browser") {
"metrics/assistant_service_metrics_provider.h", "metrics/assistant_service_metrics_provider.h",
"metrics/chromeos_metrics_provider.cc", "metrics/chromeos_metrics_provider.cc",
"metrics/chromeos_metrics_provider.h", "metrics/chromeos_metrics_provider.h",
"metrics/perf/collection_params.cc",
"metrics/perf/collection_params.h",
"metrics/perf/cpu_identity.cc", "metrics/perf/cpu_identity.cc",
"metrics/perf/cpu_identity.h", "metrics/perf/cpu_identity.h",
"metrics/perf/perf_output.cc", "metrics/perf/perf_output.cc",
......
// Copyright 2018 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 "chrome/browser/metrics/perf/collection_params.h"
#include "chrome/common/channel_info.h"
#include "components/version_info/channel.h"
namespace metrics {
namespace {
// Returns a TimeDelta profile duration based on the current chrome channel.
base::TimeDelta ProfileDuration() {
switch (chrome::GetChannel()) {
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
case version_info::Channel::BETA:
return base::TimeDelta::FromSeconds(4);
case version_info::Channel::STABLE:
case version_info::Channel::UNKNOWN:
default:
return base::TimeDelta::FromSeconds(2);
}
}
// Returns a TimeDelta interval duration for periodic collection based on the
// current chrome channel.
base::TimeDelta PeriodicCollectionInterval() {
switch (chrome::GetChannel()) {
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
case version_info::Channel::BETA:
return base::TimeDelta::FromMinutes(90);
case version_info::Channel::STABLE:
case version_info::Channel::UNKNOWN:
default:
return base::TimeDelta::FromMinutes(180);
}
}
} // namespace
// Defines default collection parameters.
CollectionParams::CollectionParams()
: CollectionParams(
ProfileDuration() /* collection_duration */,
PeriodicCollectionInterval() /* periodic_interval */,
CollectionParams::TriggerParams(/* resume_from_suspend */
10 /* sampling_factor */,
base::TimeDelta::FromSeconds(
5)) /* max_collection_delay */,
CollectionParams::TriggerParams(/* restore_session */
10 /* sampling_factor */,
base::TimeDelta::FromSeconds(
10)) /* max_collection_delay */) {
}
CollectionParams::CollectionParams(base::TimeDelta collection_duration,
base::TimeDelta periodic_interval,
TriggerParams resume_from_suspend,
TriggerParams restore_session)
: collection_duration_(collection_duration),
periodic_interval_(periodic_interval),
resume_from_suspend_(resume_from_suspend),
restore_session_(restore_session) {}
CollectionParams::TriggerParams::TriggerParams(
int64_t sampling_factor,
base::TimeDelta max_collection_delay)
: sampling_factor_(sampling_factor),
max_collection_delay_(max_collection_delay) {}
} // namespace metrics
// Copyright 2018 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 CHROME_BROWSER_METRICS_PERF_COLLECTION_PARAMS_H_
#define CHROME_BROWSER_METRICS_PERF_COLLECTION_PARAMS_H_
#include "base/macros.h"
#include "base/time/time.h"
namespace metrics {
// Defines collection parameters for metric collectors. Each collection trigger
// has its own set of parameters.
class CollectionParams {
public:
class TriggerParams {
public:
TriggerParams(int64_t sampling_factor,
base::TimeDelta max_collection_delay);
int64_t sampling_factor() const { return sampling_factor_; }
void set_sampling_factor(int64_t factor) { sampling_factor_ = factor; }
base::TimeDelta max_collection_delay() const {
return max_collection_delay_;
}
void set_max_collection_delay(base::TimeDelta delay) {
max_collection_delay_ = delay;
}
private:
TriggerParams() = delete;
// Limit the number of profiles collected.
int64_t sampling_factor_;
// Add a random delay before collecting after the trigger.
// The delay should be randomly selected between 0 and this value.
base::TimeDelta max_collection_delay_;
};
CollectionParams();
CollectionParams(base::TimeDelta collection_duration,
base::TimeDelta periodic_interval,
TriggerParams resume_from_suspend,
TriggerParams restore_session);
base::TimeDelta collection_duration() const { return collection_duration_; }
void set_collection_duration(base::TimeDelta duration) {
collection_duration_ = duration;
}
base::TimeDelta periodic_interval() const { return periodic_interval_; }
void set_periodic_interval(base::TimeDelta interval) {
periodic_interval_ = interval;
}
const TriggerParams& resume_from_suspend() const {
return resume_from_suspend_;
}
TriggerParams* mutable_resume_from_suspend() { return &resume_from_suspend_; }
const TriggerParams& restore_session() const { return restore_session_; }
TriggerParams* mutable_restore_session() { return &restore_session_; }
private:
// Time perf is run for.
base::TimeDelta collection_duration_;
// For PERIODIC_COLLECTION, partition time since login into successive
// intervals of this duration. In each interval, a random time is picked to
// collect a profile.
base::TimeDelta periodic_interval_;
// Parameters for RESUME_FROM_SUSPEND and RESTORE_SESSION collections:
TriggerParams resume_from_suspend_;
TriggerParams restore_session_;
DISALLOW_COPY_AND_ASSIGN(CollectionParams);
};
} // namespace metrics
#endif // CHROME_BROWSER_METRICS_PERF_COLLECTION_PARAMS_H_
...@@ -80,35 +80,6 @@ base::TimeDelta RandomTimeDelta(base::TimeDelta max) { ...@@ -80,35 +80,6 @@ base::TimeDelta RandomTimeDelta(base::TimeDelta max) {
base::RandGenerator(max.InMicroseconds())); base::RandGenerator(max.InMicroseconds()));
} }
// Returns a TimeDelta profile duration based on the current chrome channel.
base::TimeDelta ProfileDuration() {
switch (chrome::GetChannel()) {
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
case version_info::Channel::BETA:
return base::TimeDelta::FromSeconds(4);
case version_info::Channel::STABLE:
case version_info::Channel::UNKNOWN:
default:
return base::TimeDelta::FromSeconds(2);
}
}
// Returns a TimeDelta interval duration for periodic collection based on the
// current chrome channel.
base::TimeDelta PeriodicCollectionInterval() {
switch (chrome::GetChannel()) {
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
case version_info::Channel::BETA:
return base::TimeDelta::FromMinutes(90);
case version_info::Channel::STABLE:
case version_info::Channel::UNKNOWN:
default:
return base::TimeDelta::FromMinutes(180);
}
}
// Gets parameter named by |key| from the map. If it is present and is an // Gets parameter named by |key| from the map. If it is present and is an
// integer, stores the result in |out| and return true. Otherwise return false. // integer, stores the result in |out| and return true. Otherwise return false.
bool GetInt64Param(const std::map<std::string, std::string>& params, bool GetInt64Param(const std::map<std::string, std::string>& params,
...@@ -313,36 +284,6 @@ std::vector<RandomSelector::WeightAndValue> GetDefaultCommandsForCpu( ...@@ -313,36 +284,6 @@ std::vector<RandomSelector::WeightAndValue> GetDefaultCommandsForCpu(
} // namespace internal } // namespace internal
PerfProvider::CollectionParams::CollectionParams()
: CollectionParams(ProfileDuration() /* collection_duration */,
PeriodicCollectionInterval() /* periodic_interval */,
PerfProvider::CollectionParams::
TriggerParams(/* resume_from_suspend */
10 /* sampling_factor */,
base::TimeDelta::FromSeconds(
5)) /* max_collection_delay */,
PerfProvider::CollectionParams::
TriggerParams(/* restore_session */
10 /* sampling_factor */,
base::TimeDelta::FromSeconds(
10)) /* max_collection_delay */) {}
PerfProvider::CollectionParams::CollectionParams(
base::TimeDelta collection_duration,
base::TimeDelta periodic_interval,
TriggerParams resume_from_suspend,
TriggerParams restore_session)
: collection_duration_(collection_duration),
periodic_interval_(periodic_interval),
resume_from_suspend_(resume_from_suspend),
restore_session_(restore_session) {}
PerfProvider::CollectionParams::TriggerParams::TriggerParams(
int64_t sampling_factor,
base::TimeDelta max_collection_delay)
: sampling_factor_(sampling_factor),
max_collection_delay_(max_collection_delay) {}
PerfProvider::PerfProvider() PerfProvider::PerfProvider()
: login_observer_(this), : login_observer_(this),
weak_factory_(this) { weak_factory_(this) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/metrics/perf/collection_params.h"
#include "chrome/browser/metrics/perf/cpu_identity.h" #include "chrome/browser/metrics/perf/cpu_identity.h"
#include "chrome/browser/metrics/perf/perf_output.h" #include "chrome/browser/metrics/perf/perf_output.h"
#include "chrome/browser/metrics/perf/random_selector.h" #include "chrome/browser/metrics/perf/random_selector.h"
...@@ -48,80 +49,6 @@ class PerfProvider : public chromeos::PowerManagerClient::Observer { ...@@ -48,80 +49,6 @@ class PerfProvider : public chromeos::PowerManagerClient::Observer {
PERF_COMMAND_UNSUPPORTED, PERF_COMMAND_UNSUPPORTED,
}; };
class CollectionParams {
public:
class TriggerParams {
public:
TriggerParams(int64_t sampling_factor,
base::TimeDelta max_collection_delay);
int64_t sampling_factor() const { return sampling_factor_; }
void set_sampling_factor(int64_t factor) { sampling_factor_ = factor; }
base::TimeDelta max_collection_delay() const {
return max_collection_delay_;
}
void set_max_collection_delay(base::TimeDelta delay) {
max_collection_delay_ = delay;
}
private:
TriggerParams() = delete;
// Limit the number of profiles collected.
int64_t sampling_factor_;
// Add a random delay before collecting after the trigger.
// The delay should be randomly selected between 0 and this value.
base::TimeDelta max_collection_delay_;
};
CollectionParams();
CollectionParams(base::TimeDelta collection_duration,
base::TimeDelta periodic_interval,
TriggerParams resume_from_suspend,
TriggerParams restore_session);
base::TimeDelta collection_duration() const { return collection_duration_; }
void set_collection_duration(base::TimeDelta duration) {
collection_duration_ = duration;
}
base::TimeDelta periodic_interval() const { return periodic_interval_; }
void set_periodic_interval(base::TimeDelta interval) {
periodic_interval_ = interval;
}
const TriggerParams& resume_from_suspend() const {
return resume_from_suspend_;
}
TriggerParams* mutable_resume_from_suspend() {
return &resume_from_suspend_;
}
const TriggerParams& restore_session() const {
return restore_session_;
}
TriggerParams* mutable_restore_session() {
return &restore_session_;
}
private:
// Time perf is run for.
base::TimeDelta collection_duration_;
// For PERIODIC_COLLECTION, partition time since login into successive
// intervals of this duration. In each interval, a random time is picked to
// collect a profile.
base::TimeDelta periodic_interval_;
// Parameters for RESUME_FROM_SUSPEND and RESTORE_SESSION collections:
TriggerParams resume_from_suspend_;
TriggerParams restore_session_;
DISALLOW_COPY_AND_ASSIGN(CollectionParams);
};
// Returns one of the above enums given an vector of perf arguments, starting // Returns one of the above enums given an vector of perf arguments, starting
// with "perf" itself in |args[0]|. // with "perf" itself in |args[0]|.
static PerfSubcommand GetPerfSubcommandType( static PerfSubcommand GetPerfSubcommandType(
......
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