Commit 832b2fcc authored by Oystein Eftevaag's avatar Oystein Eftevaag Committed by Commit Bot

Background tracing: Support defining custom tracing categories and not just hardcoded presets

R=ssid@chromium.org
CC=etienneb@chromium.org

Change-Id: If3d32313d8202889a6765a4eef80a799b99d1508
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1630232
Commit-Queue: oysteine <oysteine@chromium.org>
Reviewed-by: default avatarssid <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666529}
parent 907f9c91
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
using base::trace_event::TraceConfig; using base::trace_event::TraceConfig;
using Metrics = content::BackgroundTracingManagerImpl::Metrics; using Metrics = content::BackgroundTracingManagerImpl::Metrics;
namespace {
const size_t kDefaultTraceBufferSizeInKb = 10 * 1024;
} // namespace
namespace content { namespace content {
class BackgroundTracingActiveScenario::TracingTimer { class BackgroundTracingActiveScenario::TracingTimer {
...@@ -75,10 +71,8 @@ class PerfettoTracingSession ...@@ -75,10 +71,8 @@ class PerfettoTracingSession
public mojo::DataPipeDrainer::Client { public mojo::DataPipeDrainer::Client {
public: public:
PerfettoTracingSession(BackgroundTracingActiveScenario* parent_scenario, PerfettoTracingSession(BackgroundTracingActiveScenario* parent_scenario,
const TraceConfig& chrome_config, const TraceConfig& chrome_config)
BackgroundTracingConfigImpl::CategoryPreset preset)
: parent_scenario_(parent_scenario), : parent_scenario_(parent_scenario),
category_preset_(preset),
raw_data_(std::make_unique<std::string>()) { raw_data_(std::make_unique<std::string>()) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// TODO(crbug.com/941318): Re-enable startup tracing for Android once all // TODO(crbug.com/941318): Re-enable startup tracing for Android once all
...@@ -143,7 +137,7 @@ class PerfettoTracingSession ...@@ -143,7 +137,7 @@ class PerfettoTracingSession
// tracing::mojom::TracingSession implementation: // tracing::mojom::TracingSession implementation:
void OnTracingEnabled() override { void OnTracingEnabled() override {
BackgroundTracingManagerImpl::GetInstance()->OnStartTracingDone( BackgroundTracingManagerImpl::GetInstance()->OnStartTracingDone(
category_preset_); parent_scenario_->GetConfig()->category_preset());
} }
void OnTracingDisabled() override { void OnTracingDisabled() override {
...@@ -182,7 +176,6 @@ class PerfettoTracingSession ...@@ -182,7 +176,6 @@ class PerfettoTracingSession
tracing::mojom::TracingSessionHostPtr tracing_session_host_; tracing::mojom::TracingSessionHostPtr tracing_session_host_;
std::unique_ptr<mojo::DataPipeDrainer> drainer_; std::unique_ptr<mojo::DataPipeDrainer> drainer_;
tracing::mojom::ConsumerHostPtr consumer_host_; tracing::mojom::ConsumerHostPtr consumer_host_;
BackgroundTracingConfigImpl::CategoryPreset category_preset_;
std::unique_ptr<std::string> raw_data_; std::unique_ptr<std::string> raw_data_;
bool has_finished_read_buffers_ = false; bool has_finished_read_buffers_ = false;
bool has_finished_receiving_data_ = false; bool has_finished_receiving_data_ = false;
...@@ -192,8 +185,7 @@ class LegacyTracingSession ...@@ -192,8 +185,7 @@ class LegacyTracingSession
: public BackgroundTracingActiveScenario::TracingSession { : public BackgroundTracingActiveScenario::TracingSession {
public: public:
LegacyTracingSession(BackgroundTracingActiveScenario* parent_scenario, LegacyTracingSession(BackgroundTracingActiveScenario* parent_scenario,
const TraceConfig& chrome_config, const TraceConfig& chrome_config)
BackgroundTracingConfigImpl::CategoryPreset preset)
: parent_scenario_(parent_scenario) { : parent_scenario_(parent_scenario) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// TODO(crbug.com/941318): Re-enable startup tracing for Android once all // TODO(crbug.com/941318): Re-enable startup tracing for Android once all
...@@ -210,7 +202,7 @@ class LegacyTracingSession ...@@ -210,7 +202,7 @@ class LegacyTracingSession
base::BindOnce( base::BindOnce(
&BackgroundTracingManagerImpl::OnStartTracingDone, &BackgroundTracingManagerImpl::OnStartTracingDone,
base::Unretained(BackgroundTracingManagerImpl::GetInstance()), base::Unretained(BackgroundTracingManagerImpl::GetInstance()),
preset)); parent_scenario->GetConfig()->category_preset()));
// We check IsEnabled() before creating the LegacyTracingSession, // We check IsEnabled() before creating the LegacyTracingSession,
// so any failures to start tracing at this point would be due to invalid // so any failures to start tracing at this point would be due to invalid
// configs which we treat as a failure scenario. // configs which we treat as a failure scenario.
...@@ -309,18 +301,8 @@ void BackgroundTracingActiveScenario::SetState(State new_state) { ...@@ -309,18 +301,8 @@ void BackgroundTracingActiveScenario::SetState(State new_state) {
// which means that we're left in a state where the Mojo interface doesn't // which means that we're left in a state where the Mojo interface doesn't
// think we're tracing but TraceLog is still enabled. If that's the case, // think we're tracing but TraceLog is still enabled. If that's the case,
// we abort tracing here. // we abort tracing here.
auto record_mode = base::trace_event::TraceLog::GetInstance()->SetDisabled(
(config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) base::trace_event::TraceLog::GetInstance()->enabled_modes());
? base::trace_event::RECORD_CONTINUOUSLY
: base::trace_event::RECORD_UNTIL_FULL;
TraceConfig config =
BackgroundTracingConfigImpl::GetConfigForCategoryPreset(
config_->category_preset(), record_mode);
uint8_t modes = base::trace_event::TraceLog::RECORDING_MODE;
if (!config.event_filters().empty())
modes |= base::trace_event::TraceLog::FILTERING_MODE;
base::trace_event::TraceLog::GetInstance()->SetDisabled(modes);
} }
if (scenario_state_ == State::kAborted) { if (scenario_state_ == State::kAborted) {
...@@ -347,32 +329,15 @@ BackgroundTracingActiveScenario::GetWeakPtr() { ...@@ -347,32 +329,15 @@ BackgroundTracingActiveScenario::GetWeakPtr() {
void BackgroundTracingActiveScenario::StartTracingIfConfigNeedsIt() { void BackgroundTracingActiveScenario::StartTracingIfConfigNeedsIt() {
DCHECK(config_); DCHECK(config_);
if (config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) { if (config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) {
StartTracing(config_->category_preset(), StartTracing();
base::trace_event::RECORD_CONTINUOUSLY);
} }
// There is nothing to do in case of reactive tracing. // There is nothing to do in case of reactive tracing.
} }
bool BackgroundTracingActiveScenario::StartTracing( bool BackgroundTracingActiveScenario::StartTracing() {
BackgroundTracingConfigImpl::CategoryPreset preset,
base::trace_event::TraceRecordMode record_mode) {
TraceConfig chrome_config = TraceConfig chrome_config =
BackgroundTracingConfigImpl::GetConfigForCategoryPreset(preset, config_->GetTraceConfig(requires_anonymized_data_);
record_mode);
if (requires_anonymized_data_) {
chrome_config.EnableArgumentFilter();
}
chrome_config.SetTraceBufferSizeInKb(kDefaultTraceBufferSizeInKb);
#if defined(OS_ANDROID)
// Set low trace buffer size on Android in order to upload small trace files.
if (config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) {
chrome_config.SetTraceBufferSizeInEvents(20000);
chrome_config.SetTraceBufferSizeInKb(500);
}
#endif
// If the tracing controller is tracing, i.e. DevTools or about://tracing, // If the tracing controller is tracing, i.e. DevTools or about://tracing,
// we don't start background tracing to not interfere with the user activity. // we don't start background tracing to not interfere with the user activity.
...@@ -393,10 +358,10 @@ bool BackgroundTracingActiveScenario::StartTracing( ...@@ -393,10 +358,10 @@ bool BackgroundTracingActiveScenario::StartTracing(
DCHECK(!tracing_session_); DCHECK(!tracing_session_);
if (base::FeatureList::IsEnabled(features::kBackgroundTracingProtoOutput)) { if (base::FeatureList::IsEnabled(features::kBackgroundTracingProtoOutput)) {
tracing_session_ = tracing_session_ =
std::make_unique<PerfettoTracingSession>(this, chrome_config, preset); std::make_unique<PerfettoTracingSession>(this, chrome_config);
} else { } else {
tracing_session_ = tracing_session_ =
std::make_unique<LegacyTracingSession>(this, chrome_config, preset); std::make_unique<LegacyTracingSession>(this, chrome_config);
} }
SetState(State::kTracing); SetState(State::kTracing);
...@@ -574,8 +539,7 @@ void BackgroundTracingActiveScenario::OnRuleTriggered( ...@@ -574,8 +539,7 @@ void BackgroundTracingActiveScenario::OnRuleTriggered(
if (state() != State::kTracing) { if (state() != State::kTracing) {
// It was not already tracing, start a new trace. // It was not already tracing, start a new trace.
if (!StartTracing(triggered_rule->category_preset(), if (!StartTracing()) {
base::trace_event::RECORD_UNTIL_FULL)) {
return; return;
} }
} else { } else {
......
...@@ -68,8 +68,7 @@ class BackgroundTracingActiveScenario { ...@@ -68,8 +68,7 @@ class BackgroundTracingActiveScenario {
const base::RepeatingClosure& callback); const base::RepeatingClosure& callback);
private: private:
bool StartTracing(BackgroundTracingConfigImpl::CategoryPreset, bool StartTracing();
base::trace_event::TraceRecordMode);
void BeginFinalizing( void BeginFinalizing(
BackgroundTracingManager::StartedFinalizingCallback callback); BackgroundTracingManager::StartedFinalizingCallback callback);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "components/tracing/common/trace_startup_config.h" #include "components/tracing/common/trace_startup_config.h"
#include "content/browser/tracing/background_tracing_rule.h" #include "content/browser/tracing/background_tracing_rule.h"
...@@ -27,6 +28,7 @@ const char kConfigModeReactive[] = "REACTIVE_TRACING_MODE"; ...@@ -27,6 +28,7 @@ const char kConfigModeReactive[] = "REACTIVE_TRACING_MODE";
const char kConfigScenarioName[] = "scenario_name"; const char kConfigScenarioName[] = "scenario_name";
const char kConfigCategoryKey[] = "category"; const char kConfigCategoryKey[] = "category";
const char kConfigCustomCategoriesKey[] = "custom_categories";
const char kConfigCategoryBenchmark[] = "BENCHMARK"; const char kConfigCategoryBenchmark[] = "BENCHMARK";
const char kConfigCategoryBenchmarkDeep[] = "BENCHMARK_DEEP"; const char kConfigCategoryBenchmarkDeep[] = "BENCHMARK_DEEP";
const char kConfigCategoryBenchmarkGPU[] = "BENCHMARK_GPU"; const char kConfigCategoryBenchmarkGPU[] = "BENCHMARK_GPU";
...@@ -42,6 +44,9 @@ const char kConfigCategoryBenchmarkRenderers[] = "BENCHMARK_RENDERERS"; ...@@ -42,6 +44,9 @@ const char kConfigCategoryBenchmarkRenderers[] = "BENCHMARK_RENDERERS";
const char kConfigCategoryBenchmarkServiceworker[] = "BENCHMARK_SERVICEWORKER"; const char kConfigCategoryBenchmarkServiceworker[] = "BENCHMARK_SERVICEWORKER";
const char kConfigCategoryBenchmarkPower[] = "BENCHMARK_POWER"; const char kConfigCategoryBenchmarkPower[] = "BENCHMARK_POWER";
const char kConfigCategoryBlinkStyle[] = "BLINK_STYLE"; const char kConfigCategoryBlinkStyle[] = "BLINK_STYLE";
const char kConfigCategoryCustom[] = "CUSTOM";
const size_t kDefaultTraceBufferSizeInKb = 10 * 1024;
} // namespace } // namespace
...@@ -84,6 +89,8 @@ std::string BackgroundTracingConfigImpl::CategoryPresetToString( ...@@ -84,6 +89,8 @@ std::string BackgroundTracingConfigImpl::CategoryPresetToString(
return kConfigCategoryBenchmarkPower; return kConfigCategoryBenchmarkPower;
case BackgroundTracingConfigImpl::BLINK_STYLE: case BackgroundTracingConfigImpl::BLINK_STYLE:
return kConfigCategoryBlinkStyle; return kConfigCategoryBlinkStyle;
case BackgroundTracingConfigImpl::CUSTOM_CATEGORY_PRESET:
return kConfigCategoryCustom;
case BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET: case BackgroundTracingConfigImpl::CATEGORY_PRESET_UNSET:
NOTREACHED(); NOTREACHED();
} }
...@@ -169,6 +176,10 @@ bool BackgroundTracingConfigImpl::StringToCategoryPreset( ...@@ -169,6 +176,10 @@ bool BackgroundTracingConfigImpl::StringToCategoryPreset(
} }
void BackgroundTracingConfigImpl::IntoDict(base::DictionaryValue* dict) { void BackgroundTracingConfigImpl::IntoDict(base::DictionaryValue* dict) {
if (category_preset_ == CUSTOM_CATEGORY_PRESET) {
dict->SetString(kConfigCustomCategoriesKey, custom_categories_);
}
switch (tracing_mode()) { switch (tracing_mode()) {
case BackgroundTracingConfigImpl::PREEMPTIVE: case BackgroundTracingConfigImpl::PREEMPTIVE:
dict->SetString(kConfigModeKey, kConfigModePreemptive); dict->SetString(kConfigModeKey, kConfigModePreemptive);
...@@ -214,6 +225,35 @@ void BackgroundTracingConfigImpl::AddReactiveRule( ...@@ -214,6 +225,35 @@ void BackgroundTracingConfigImpl::AddReactiveRule(
} }
} }
base::trace_event::TraceConfig BackgroundTracingConfigImpl::GetTraceConfig(
bool requires_anonymized_data) {
base::trace_event::TraceRecordMode record_mode =
(tracing_mode() == BackgroundTracingConfigImpl::REACTIVE)
? base::trace_event::RECORD_UNTIL_FULL
: base::trace_event::RECORD_CONTINUOUSLY;
base::trace_event::TraceConfig chrome_config =
(category_preset() == CUSTOM_CATEGORY_PRESET
? base::trace_event::TraceConfig(custom_categories_, record_mode)
: GetConfigForCategoryPreset(category_preset(), record_mode));
if (requires_anonymized_data) {
chrome_config.EnableArgumentFilter();
}
chrome_config.SetTraceBufferSizeInKb(kDefaultTraceBufferSizeInKb);
#if defined(OS_ANDROID)
// Set low trace buffer size on Android in order to upload small trace files.
if (tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) {
chrome_config.SetTraceBufferSizeInEvents(20000);
chrome_config.SetTraceBufferSizeInKb(500);
}
#endif
return chrome_config;
}
// static // static
std::unique_ptr<BackgroundTracingConfigImpl> std::unique_ptr<BackgroundTracingConfigImpl>
BackgroundTracingConfigImpl::FromDict(const base::DictionaryValue* dict) { BackgroundTracingConfigImpl::FromDict(const base::DictionaryValue* dict) {
...@@ -249,13 +289,19 @@ BackgroundTracingConfigImpl::PreemptiveFromDict( ...@@ -249,13 +289,19 @@ BackgroundTracingConfigImpl::PreemptiveFromDict(
std::unique_ptr<BackgroundTracingConfigImpl> config( std::unique_ptr<BackgroundTracingConfigImpl> config(
new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::PREEMPTIVE)); new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::PREEMPTIVE));
std::string category_preset_string; if (dict->GetString(kConfigCustomCategoriesKey,
if (!dict->GetString(kConfigCategoryKey, &category_preset_string)) &config->custom_categories_)) {
return nullptr; config->category_preset_ = CUSTOM_CATEGORY_PRESET;
} else {
std::string category_preset_string;
if (!dict->GetString(kConfigCategoryKey, &category_preset_string))
return nullptr;
if (!StringToCategoryPreset(category_preset_string, if (!StringToCategoryPreset(category_preset_string,
&config->category_preset_)) &config->category_preset_)) {
return nullptr; return nullptr;
}
}
const base::ListValue* configs_list = nullptr; const base::ListValue* configs_list = nullptr;
if (!dict->GetList(kConfigsKey, &configs_list)) if (!dict->GetList(kConfigsKey, &configs_list))
...@@ -284,6 +330,20 @@ BackgroundTracingConfigImpl::ReactiveFromDict( ...@@ -284,6 +330,20 @@ BackgroundTracingConfigImpl::ReactiveFromDict(
std::unique_ptr<BackgroundTracingConfigImpl> config( std::unique_ptr<BackgroundTracingConfigImpl> config(
new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::REACTIVE)); new BackgroundTracingConfigImpl(BackgroundTracingConfigImpl::REACTIVE));
std::string category_preset_string;
bool has_global_categories = false;
if (dict->GetString(kConfigCustomCategoriesKey,
&config->custom_categories_)) {
config->category_preset_ = CUSTOM_CATEGORY_PRESET;
has_global_categories = true;
} else if (dict->GetString(kConfigCategoryKey, &category_preset_string)) {
if (!StringToCategoryPreset(category_preset_string,
&config->category_preset_)) {
return nullptr;
}
has_global_categories = true;
}
const base::ListValue* configs_list = nullptr; const base::ListValue* configs_list = nullptr;
if (!dict->GetList(kConfigsKey, &configs_list)) if (!dict->GetList(kConfigsKey, &configs_list))
return nullptr; return nullptr;
...@@ -293,15 +353,17 @@ BackgroundTracingConfigImpl::ReactiveFromDict( ...@@ -293,15 +353,17 @@ BackgroundTracingConfigImpl::ReactiveFromDict(
if (!it.GetAsDictionary(&config_dict)) if (!it.GetAsDictionary(&config_dict))
return nullptr; return nullptr;
std::string category_preset_string; // TODO(oysteine): Remove the per-rule category preset when configs have
if (!config_dict->GetString(kConfigCategoryKey, &category_preset_string)) // been updated to just specify the per-config category preset.
return nullptr; if (!has_global_categories &&
config_dict->GetString(kConfigCategoryKey, &category_preset_string)) {
BackgroundTracingConfigImpl::CategoryPreset new_category_preset; if (!StringToCategoryPreset(category_preset_string,
if (!StringToCategoryPreset(category_preset_string, &new_category_preset)) &config->category_preset_)) {
return nullptr; return nullptr;
}
}
config->AddReactiveRule(config_dict, new_category_preset); config->AddReactiveRule(config_dict, config->category_preset_);
} }
if (config->rules().empty()) if (config->rules().empty())
...@@ -391,6 +453,7 @@ TraceConfig BackgroundTracingConfigImpl::GetConfigForCategoryPreset( ...@@ -391,6 +453,7 @@ TraceConfig BackgroundTracingConfigImpl::GetConfigForCategoryPreset(
return config; return config;
} }
case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET:
case BackgroundTracingConfigImpl::CategoryPreset::CUSTOM_CATEGORY_PRESET:
NOTREACHED(); NOTREACHED();
} }
NOTREACHED(); NOTREACHED();
......
...@@ -30,6 +30,7 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl ...@@ -30,6 +30,7 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl
enum CategoryPreset { enum CategoryPreset {
CATEGORY_PRESET_UNSET, CATEGORY_PRESET_UNSET,
CUSTOM_CATEGORY_PRESET,
BENCHMARK, BENCHMARK,
BENCHMARK_DEEP, BENCHMARK_DEEP,
BENCHMARK_GPU, BENCHMARK_GPU,
...@@ -61,6 +62,8 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl ...@@ -61,6 +62,8 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl
const base::DictionaryValue* dict, const base::DictionaryValue* dict,
BackgroundTracingConfigImpl::CategoryPreset category_preset); BackgroundTracingConfigImpl::CategoryPreset category_preset);
base::trace_event::TraceConfig GetTraceConfig(bool requires_anonymized_data);
static std::unique_ptr<BackgroundTracingConfigImpl> PreemptiveFromDict( static std::unique_ptr<BackgroundTracingConfigImpl> PreemptiveFromDict(
const base::DictionaryValue* dict); const base::DictionaryValue* dict);
static std::unique_ptr<BackgroundTracingConfigImpl> ReactiveFromDict( static std::unique_ptr<BackgroundTracingConfigImpl> ReactiveFromDict(
...@@ -75,17 +78,18 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl ...@@ -75,17 +78,18 @@ class CONTENT_EXPORT BackgroundTracingConfigImpl
const std::string& category_preset_string, const std::string& category_preset_string,
BackgroundTracingConfigImpl::CategoryPreset* category_preset); BackgroundTracingConfigImpl::CategoryPreset* category_preset);
static base::trace_event::TraceConfig GetConfigForCategoryPreset(
BackgroundTracingConfigImpl::CategoryPreset,
base::trace_event::TraceRecordMode);
private: private:
FRIEND_TEST_ALL_PREFIXES(BackgroundTracingConfigTest, FRIEND_TEST_ALL_PREFIXES(BackgroundTracingConfigTest,
ValidPreemptiveConfigToString); ValidPreemptiveConfigToString);
static base::trace_event::TraceConfig GetConfigForCategoryPreset(
BackgroundTracingConfigImpl::CategoryPreset,
base::trace_event::TraceRecordMode);
CategoryPreset category_preset_; CategoryPreset category_preset_;
std::vector<std::unique_ptr<BackgroundTracingRule>> rules_; std::vector<std::unique_ptr<BackgroundTracingRule>> rules_;
std::string scenario_name_; std::string scenario_name_;
std::string custom_categories_;
DISALLOW_COPY_AND_ASSIGN(BackgroundTracingConfigImpl); DISALLOW_COPY_AND_ASSIGN(BackgroundTracingConfigImpl);
}; };
......
...@@ -256,6 +256,21 @@ TEST_F(BackgroundTracingConfigTest, PreemptiveConfigFromValidString) { ...@@ -256,6 +256,21 @@ TEST_F(BackgroundTracingConfigTest, PreemptiveConfigFromValidString) {
EXPECT_EQ(RuleToString(config->rules()[1]), EXPECT_EQ(RuleToString(config->rules()[1]),
"{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\"," "{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\","
"\"trigger_name\":\"foo2\"}"); "\"trigger_name\":\"foo2\"}");
config = ReadFromJSONString(
"{\"mode\":\"PREEMPTIVE_TRACING_MODE\", \"custom_categories\": "
"\"toplevel,benchmark\",\"configs\": [{\"rule\": "
"\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\", \"trigger_name\":\"foo1\"}]}");
EXPECT_TRUE(config);
EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::PREEMPTIVE);
EXPECT_EQ(config->category_preset(),
BackgroundTracingConfigImpl::CUSTOM_CATEGORY_PRESET);
EXPECT_EQ(config->rules().size(), 1u);
EXPECT_EQ(
ConfigToString(config.get()),
"{\"category\":\"CUSTOM\",\"configs\":[{\"rule\":\"MONITOR_AND_DUMP_WHEN_"
"TRIGGER_NAMED\",\"trigger_name\":\"foo1\"}],\"custom_categories\":"
"\"toplevel,benchmark\",\"mode\":\"PREEMPTIVE_TRACING_MODE\"}");
} }
TEST_F(BackgroundTracingConfigTest, ValidPreemptiveCategoryToString) { TEST_F(BackgroundTracingConfigTest, ValidPreemptiveCategoryToString) {
...@@ -375,6 +390,7 @@ TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) { ...@@ -375,6 +390,7 @@ TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) {
"{\"category\":\"BENCHMARK_DEEP\"," "{\"category\":\"BENCHMARK_DEEP\","
"\"rule\":\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\"," "\"rule\":\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\","
"\"trigger_delay\":30,\"trigger_name\":\"foo2\"}"); "\"trigger_delay\":30,\"trigger_name\":\"foo2\"}");
config = ReadFromJSONString( config = ReadFromJSONString(
"{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": " "{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": "
"\"TRACE_AT_RANDOM_INTERVALS\"," "\"TRACE_AT_RANDOM_INTERVALS\","
...@@ -388,6 +404,22 @@ TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) { ...@@ -388,6 +404,22 @@ TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) {
"{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_AT_RANDOM_" "{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_AT_RANDOM_"
"INTERVALS\",\"stop_tracing_on_repeated_reactive\":true," "INTERVALS\",\"stop_tracing_on_repeated_reactive\":true,"
"\"timeout_max\":20,\"timeout_min\":10}"); "\"timeout_max\":20,\"timeout_min\":10}");
config = ReadFromJSONString(
"{\"mode\":\"REACTIVE_TRACING_MODE\","
"\"custom_categories\": \"benchmark,toplevel\","
"\"configs\": [{\"rule\": "
"\"TRACE_AT_RANDOM_INTERVALS\","
"\"stop_tracing_on_repeated_reactive\": true, "
"\"timeout_max\":20,\"timeout_min\":10}]}");
EXPECT_TRUE(config);
EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::REACTIVE);
EXPECT_EQ(config->rules().size(), 1u);
EXPECT_EQ(ConfigToString(config.get()),
"{\"configs\":[{\"category\":\"CUSTOM\",\"rule\":\"TRACE_AT_RANDOM_"
"INTERVALS\",\"stop_tracing_on_repeated_reactive\":true,\"timeout_"
"max\":20,\"timeout_min\":10}],\"custom_categories\":\"benchmark,"
"toplevel\",\"mode\":\"REACTIVE_TRACING_MODE\"}");
} }
TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) { TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) {
...@@ -502,6 +534,28 @@ TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) { ...@@ -502,6 +534,28 @@ TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) {
"SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":" "SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":"
"\"PREEMPTIVE_TRACING_MODE\"}"); "\"PREEMPTIVE_TRACING_MODE\"}");
} }
{
config.reset(
new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE));
std::unique_ptr<base::DictionaryValue> second_dict(
new base::DictionaryValue());
second_dict->SetString(
"rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE");
second_dict->SetString("histogram_name", "foo");
second_dict->SetInteger("histogram_lower_value", 1);
second_dict->SetInteger("histogram_upper_value", 2);
second_dict->SetInteger("trigger_delay", 10);
config->AddPreemptiveRule(second_dict.get());
EXPECT_EQ(ConfigToString(config.get()),
"{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_"
"value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true,"
"\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_"
"SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":"
"\"PREEMPTIVE_TRACING_MODE\"}");
}
} }
TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) { TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) {
......
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