Commit 47281893 authored by Jakub Chyłkowski's avatar Jakub Chyłkowski Committed by Chromium LUCI CQ

Add support for perfetto::TraceConfig in tracing

Currently, the TraceConfig JSON object passed to the DevTools method to
start tracing only supports configuration of the Chrome-internal trace
event data source.

This commit provides additional parameters in DevTools:

- base64-encoded serialized protobuf message which takes precedence
  over other parameters,

- backend selection.

In order to handle new parameters, convert
base::trace_event::TraceConfig to perfetto::TraceConfig before passing
it and add support for the new perfettoConfig protocol param.

Add test to handle Command to run new test:
out/Default/content_browsertests --gtest_filter=DevToolsProtocolTest.TracingWithPerfettoConfig

Bug: chromium:1141381, chromium:1141386
Change-Id: I35e436487b2526bb3bf17bac34b9741712fb5319
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2560581
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836082}
parent f997361d
......@@ -41,6 +41,7 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/security_style_explanations.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/tracing_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
......@@ -55,6 +56,7 @@
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "services/tracing/public/cpp/perfetto/perfetto_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
......@@ -2683,4 +2685,33 @@ IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DISABLED_MultiDownload) {
file2, GetTestFilePath("download", "download-test.lib")));
}
#endif // !defined(ANDROID)
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TracingWithPerfettoConfig) {
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
base::trace_event::TraceConfig chrome_config;
base::DictionaryValue* command_result;
perfetto::TraceConfig perfetto_config;
std::string perfetto_config_encoded;
chrome_config = base::trace_event::TraceConfig();
perfetto_config = tracing::GetDefaultPerfettoConfig(
chrome_config,
/*privacy_filtering_enabled=*/false,
/*convert_to_legacy_json=*/false,
perfetto::protos::gen::ChromeConfig::USER_INITIATED);
base::Base64Encode(perfetto_config.SerializeAsString(),
&perfetto_config_encoded);
params->SetKey("perfettoConfig", base::Value(perfetto_config_encoded));
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
command_result = SendCommand("Tracing.start", std::move(params), true);
ASSERT_NE(command_result, nullptr);
command_result = SendCommand("Tracing.end", nullptr, true);
ASSERT_NE(command_result, nullptr);
WaitForNotification("Tracing.tracingComplete", true);
}
} // namespace content
......@@ -22,6 +22,7 @@
#include "content/browser/devtools/protocol/tracing.h"
#include "content/common/content_export.h"
#include "content/public/browser/tracing_controller.h"
#include "services/tracing/public/cpp/perfetto/perfetto_config.h"
namespace base {
class RepeatingTimer;
......@@ -69,6 +70,7 @@ class TracingHandler : public DevToolsDomainHandler, public Tracing::Backend {
Maybe<std::string> transfer_format,
Maybe<std::string> transfer_compression,
Maybe<Tracing::TraceConfig> config,
Maybe<Binary> perfetto_config,
std::unique_ptr<StartCallback> callback) override;
Response End() override;
void GetCategories(std::unique_ptr<GetCategoriesCallback> callback) override;
......@@ -124,6 +126,8 @@ class TracingHandler : public DevToolsDomainHandler, public Tracing::Backend {
CONTENT_EXPORT static base::trace_event::TraceConfig
GetTraceConfigFromDevToolsConfig(
const base::DictionaryValue& devtools_config);
perfetto::TraceConfig CreatePerfettoConfiguration(
const base::trace_event::TraceConfig& browser_config);
void SetupProcessFilter(base::ProcessId gpu_pid, RenderFrameHost*);
void StartTracingWithGpuPid(std::unique_ptr<StartCallback>,
base::ProcessId gpu_pid);
......@@ -144,7 +148,7 @@ class TracingHandler : public DevToolsDomainHandler, public Tracing::Backend {
TraceDataBufferState trace_data_buffer_state_;
std::unique_ptr<DevToolsVideoConsumer> video_consumer_;
int number_of_screenshots_from_video_consumer_ = 0;
base::trace_event::TraceConfig trace_config_;
perfetto::TraceConfig trace_config_;
std::unique_ptr<TracingSession> session_;
base::WeakPtrFactory<TracingHandler> weak_factory_{this};
......
......@@ -8078,6 +8078,10 @@ experimental domain Tracing
# transfer mode (defaults to `none`)
optional StreamCompression streamCompression
optional TraceConfig traceConfig
# Base64-encoded serialized perfetto.protos.TraceConfig protobuf message
# When specified, the parameters `categories`, `options`, `traceConfig`
# are ignored.
optional binary perfettoConfig
event bufferUsage
parameters
......
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