Commit b55cb9ca authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

services/tracing: Make client priority configurable

Make it possible to configure the priority of a tracing session client.
Currently multiple concurrent sessions aren't supported, so higher
priority clients may preempt sessions from lower priority ones.

Depends on https://android-review.googlesource.com/1426068

Bug: 1058632
Change-Id: I6dc3c92aa440e984c68bc83a88e36898033493a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404936Reviewed-by: default avataroysteine <oysteine@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806981}
parent 48522640
......@@ -25,7 +25,8 @@ perfetto::TraceConfig::DataSource* AddDataSourceConfig(
const char* name,
const std::string& chrome_config_string,
bool privacy_filtering_enabled,
bool convert_to_legacy_json) {
bool convert_to_legacy_json,
perfetto::protos::gen::ChromeConfig::ClientPriority client_priority) {
auto* data_source = perfetto_config->add_data_sources();
auto* source_config = data_source->mutable_config();
source_config->set_name(name);
......@@ -34,6 +35,7 @@ perfetto::TraceConfig::DataSource* AddDataSourceConfig(
chrome_config->set_trace_config(chrome_config_string);
chrome_config->set_privacy_filtering_enabled(privacy_filtering_enabled);
chrome_config->set_convert_to_legacy_json(convert_to_legacy_json);
chrome_config->set_client_priority(client_priority);
return data_source;
}
......@@ -43,7 +45,8 @@ void AddDataSourceConfigs(
const base::trace_event::TraceConfig& stripped_config,
const std::set<std::string>& source_names,
bool privacy_filtering_enabled,
bool convert_to_legacy_json) {
bool convert_to_legacy_json,
perfetto::protos::gen::ChromeConfig::ClientPriority client_priority) {
const std::string chrome_config_string = stripped_config.ToString();
// Capture actual trace events.
......@@ -51,8 +54,8 @@ void AddDataSourceConfigs(
source_names.count(tracing::mojom::kTraceEventDataSourceName) == 1) {
auto* trace_event_data_source = AddDataSourceConfig(
perfetto_config, tracing::mojom::kTraceEventDataSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
chrome_config_string, privacy_filtering_enabled, convert_to_legacy_json,
client_priority);
for (auto& enabled_pid : process_filters.included_process_ids()) {
*trace_event_data_source->add_producer_name_filter() = base::StrCat(
{mojom::kPerfettoProducerNamePrefix,
......@@ -69,7 +72,7 @@ void AddDataSourceConfigs(
AddDataSourceConfig(perfetto_config,
tracing::mojom::kSystemTraceDataSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
#endif
......@@ -79,7 +82,7 @@ void AddDataSourceConfigs(
AddDataSourceConfig(perfetto_config,
tracing::mojom::kArcTraceDataSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
#endif
}
......@@ -89,7 +92,7 @@ void AddDataSourceConfigs(
source_names.count(tracing::mojom::kMetaDataSourceName) == 1) {
AddDataSourceConfig(perfetto_config, tracing::mojom::kMetaDataSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
if (stripped_config.IsCategoryGroupEnabled(
......@@ -100,7 +103,7 @@ void AddDataSourceConfigs(
AddDataSourceConfig(perfetto_config,
tracing::mojom::kSamplerProfilerSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
if (stripped_config.IsCategoryGroupEnabled(
......@@ -111,7 +114,7 @@ void AddDataSourceConfigs(
AddDataSourceConfig(perfetto_config,
tracing::mojom::kJavaHeapProfilerSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
if (source_names.empty() ||
......@@ -119,7 +122,7 @@ void AddDataSourceConfigs(
AddDataSourceConfig(perfetto_config,
tracing::mojom::kReachedCodeProfilerSourceName,
chrome_config_string, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
}
}
......@@ -128,9 +131,11 @@ void AddDataSourceConfigs(
perfetto::TraceConfig GetDefaultPerfettoConfig(
const base::trace_event::TraceConfig& chrome_config,
bool privacy_filtering_enabled,
bool convert_to_legacy_json) {
bool convert_to_legacy_json,
perfetto::protos::gen::ChromeConfig::ClientPriority client_priority) {
return GetPerfettoConfigWithDataSources(
chrome_config, {}, privacy_filtering_enabled, convert_to_legacy_json);
chrome_config, {}, privacy_filtering_enabled, convert_to_legacy_json,
client_priority);
}
perfetto::TraceConfig COMPONENT_EXPORT(TRACING_CPP)
......@@ -138,7 +143,8 @@ perfetto::TraceConfig COMPONENT_EXPORT(TRACING_CPP)
const base::trace_event::TraceConfig& chrome_config,
const std::set<std::string>& source_names,
bool privacy_filtering_enabled,
bool convert_to_legacy_json) {
bool convert_to_legacy_json,
perfetto::protos::gen::ChromeConfig::ClientPriority client_priority) {
perfetto::TraceConfig perfetto_config;
size_t size_limit = chrome_config.GetTraceBufferSizeInKb();
......@@ -200,7 +206,7 @@ perfetto::TraceConfig COMPONENT_EXPORT(TRACING_CPP)
AddDataSourceConfigs(&perfetto_config, chrome_config.process_filter_config(),
stripped_config, source_names, privacy_filtering_enabled,
convert_to_legacy_json);
convert_to_legacy_json, client_priority);
return perfetto_config;
}
......
......@@ -9,6 +9,7 @@
#include <string>
#include "base/component_export.h"
#include "third_party/perfetto/include/perfetto/tracing/core/chrome_config.h"
#include "third_party/perfetto/include/perfetto/tracing/core/trace_config.h"
namespace base {
......@@ -22,7 +23,9 @@ namespace tracing {
perfetto::TraceConfig COMPONENT_EXPORT(TRACING_CPP) GetDefaultPerfettoConfig(
const base::trace_event::TraceConfig& chrome_config,
bool privacy_filtering_enabled = false,
bool convert_to_legacy_json = false);
bool convert_to_legacy_json = false,
perfetto::protos::gen::ChromeConfig::ClientPriority =
perfetto::protos::gen::ChromeConfig::USER_INITIATED);
// Creates a perfetto trace config with only the data sources included in
// |source_names| and enabled by |trace_config|. Passing empty set will add all
......@@ -33,7 +36,9 @@ perfetto::TraceConfig COMPONENT_EXPORT(TRACING_CPP)
const base::trace_event::TraceConfig& chrome_config,
const std::set<std::string>& source_names,
bool privacy_filtering_enabled = false,
bool convert_to_legacy_json = false);
bool convert_to_legacy_json = false,
perfetto::protos::gen::ChromeConfig::ClientPriority =
perfetto::protos::gen::ChromeConfig::USER_INITIATED);
} // namespace tracing
......
......@@ -378,11 +378,30 @@ class ConsumerEndpoint : public perfetto::ConsumerEndpoint,
void StartTracing() override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(skyostil): Don't hardcode the session's priority.
auto priority = mojom::TracingClientPriority::kUnknown;
for (const auto& data_source : trace_config_.data_sources()) {
if (!data_source.has_config() ||
!data_source.config().has_chrome_config()) {
continue;
}
switch (data_source.config().chrome_config().client_priority()) {
case perfetto::protos::gen::ChromeConfig::BACKGROUND:
priority =
std::max(priority, mojom::TracingClientPriority::kBackground);
break;
case perfetto::protos::gen::ChromeConfig::USER_INITIATED:
priority =
std::max(priority, mojom::TracingClientPriority::kUserInitiated);
break;
default:
case perfetto::protos::gen::ChromeConfig::UNKNOWN:
break;
}
}
consumer_host_->EnableTracing(
tracing_session_host_.BindNewPipeAndPassReceiver(),
tracing_session_client_.BindNewPipeAndPassRemote(), trace_config_,
tracing::mojom::TracingClientPriority::kUserInitiated);
priority);
tracing_session_host_.set_disconnect_handler(base::BindOnce(
&ConsumerEndpoint::OnTracingFailed, base::Unretained(this)));
tracing_session_client_.set_disconnect_handler(base::BindOnce(
......
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