Commit d80f55ce authored by Thomas Anderson's avatar Thomas Anderson Committed by Commit Bot

Revert "DevTools: Do not start tracing in renderer process explicitly."

This reverts commit c5126022.

Reason for revert: Suspected cause of linux-rel breakage:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-rel/2129

Original change's description:
> DevTools: Do not start tracing in renderer process explicitly.
> 
> The tracing is now initiated by the browser process. There's no need
> to start it in renderer anymore. TracingStartedInPage event is not
> going to be produced anymore. It has been replaced with TracingStartedInBrowser.
> 
> Change-Id: I9e7759f7f792421d3f32fd21e82066e13a4901dc
> Reviewed-on: https://chromium-review.googlesource.com/1182287
> Commit-Queue: Alexei Filippov <alph@chromium.org>
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#584797}

TBR=dgozman@chromium.org,alph@chromium.org

Change-Id: I16a9138a8ab10ac74e032d02f4d4cbea1b173a30
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/1183802Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584819}
parent 7adc27a1
......@@ -404,6 +404,11 @@ void TracingHandler::Start(Maybe<std::string> categories,
options.fromMaybe(""));
}
// If inspected target is a render process Tracing.start will be handled by
// tracing agent in the renderer.
if (frame_tree_node_)
callback->fallThrough();
SetupProcessFilter(nullptr);
TracingController::GetInstance()->StartTracing(
......@@ -457,12 +462,14 @@ void TracingHandler::OnProcessReady(RenderProcessHost* process_host) {
trace_config_, base::RepeatingCallback<void()>());
}
Response TracingHandler::End() {
void TracingHandler::End(std::unique_ptr<EndCallback> callback) {
// Startup tracing triggered by --trace-config-file is a special case, where
// tracing is started automatically upon browser startup and can be stopped
// via DevTools.
if (!did_initiate_recording_ && !IsStartupTracingActive())
return Response::Error("Tracing is not started");
if (!did_initiate_recording_ && !IsStartupTracingActive()) {
callback->sendFailure(Response::Error("Tracing is not started"));
return;
}
scoped_refptr<TracingController::TraceDataEndpoint> endpoint;
if (return_as_stream_) {
......@@ -481,8 +488,12 @@ Response TracingHandler::End() {
endpoint = new DevToolsTraceEndpointProxy(weak_factory_.GetWeakPtr());
StopTracing(endpoint, tracing::mojom::kChromeTraceEventLabel);
}
return Response::OK();
// If inspected target is a render process Tracing.end will be handled by
// tracing agent in the renderer.
if (frame_tree_node_)
callback->fallThrough();
else
callback->sendSuccess();
}
void TracingHandler::GetCategories(
......@@ -497,7 +508,8 @@ void TracingHandler::OnRecordingEnabled(
std::unique_ptr<StartCallback> callback) {
EmitFrameTree();
callback->sendSuccess();
if (!frame_tree_node_)
callback->sendSuccess();
bool screenshot_enabled;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(
......
......@@ -69,7 +69,7 @@ class TracingHandler : public DevToolsDomainHandler, public Tracing::Backend {
Maybe<std::string> transfer_compression,
Maybe<Tracing::TraceConfig> config,
std::unique_ptr<StartCallback> callback) override;
Response End() override;
void End(std::unique_ptr<EndCallback> callback) override;
void GetCategories(std::unique_ptr<GetCategoriesCallback> callback) override;
void RequestMemoryDump(
std::unique_ptr<RequestMemoryDumpCallback> callback) override;
......
......@@ -85,7 +85,7 @@
},
{
"domain": "Tracing",
"async": ["start", "getCategories", "requestMemoryDump"]
"async": ["start", "end", "getCategories", "requestMemoryDump"]
}
]
},
......
Tests that Tracing agent returns a session id upon a start that is matching one issued in trace events.
Got DevTools metadata event: TracingStartedInBrowser
Got DevTools metadata event: TracingStartedInPage
Got DevTools metadata event: SetLayerTreeId
......@@ -19,16 +19,20 @@
await PerformanceTestRunner.invokeAsyncWithTimeline('waitForRaf');
let frameId = '';
PerformanceTestRunner.tracingModel().sortedProcesses().forEach(process =>
process.sortedThreads().forEach(thread => thread.events().forEach(processEvent))
);
PerformanceTestRunner.tracingModel().sortedProcesses().forEach(function(process) {
process.sortedThreads().forEach(function(thread) {
thread.events().forEach(processEvent);
});
});
TestRunner.completeTest();
var frameId = '';
function processEvent(event) {
if (!event.hasCategory(SDK.TracingModel.DevToolsMetadataEventCategory))
return;
if (event.name === TimelineModel.TimelineModel.DevToolsMetadataEvent.TracingStartedInBrowser) {
if (event.name === TimelineModel.TimelineModel.RecordType.TracingStartedInPage) {
TestRunner.addResult('Got DevTools metadata event: ' + event.name);
frameId = event.args['data']['frames'][0]['frame'];
} else if (event.name === TimelineModel.TimelineModel.RecordType.SetLayerTreeId) {
......
......@@ -76,6 +76,7 @@
#include "third_party/blink/renderer/core/inspector/inspector_resource_content_loader.h"
#include "third_party/blink/renderer/core/inspector/inspector_session.h"
#include "third_party/blink/renderer/core/inspector/inspector_task_runner.h"
#include "third_party/blink/renderer/core/inspector/inspector_tracing_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_worker_agent.h"
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
......@@ -215,6 +216,7 @@ class WebDevToolsAgentImpl::Session : public GarbageCollectedFinalized<Session>,
InspectorSession* inspector_session() { return inspector_session_.Get(); }
InspectorNetworkAgent* network_agent() { return network_agent_.Get(); }
InspectorPageAgent* page_agent() { return page_agent_.Get(); }
InspectorTracingAgent* tracing_agent() { return tracing_agent_.Get(); }
InspectorOverlayAgent* overlay_agent() { return overlay_agent_.Get(); }
private:
......@@ -250,6 +252,7 @@ class WebDevToolsAgentImpl::Session : public GarbageCollectedFinalized<Session>,
Member<InspectorSession> inspector_session_;
Member<InspectorNetworkAgent> network_agent_;
Member<InspectorPageAgent> page_agent_;
Member<InspectorTracingAgent> tracing_agent_;
Member<InspectorOverlayAgent> overlay_agent_;
bool detached_ = false;
......@@ -336,6 +339,7 @@ void WebDevToolsAgentImpl::Session::Trace(blink::Visitor* visitor) {
visitor->Trace(inspector_session_);
visitor->Trace(network_agent_);
visitor->Trace(page_agent_);
visitor->Trace(tracing_agent_);
visitor->Trace(overlay_agent_);
}
......@@ -445,6 +449,9 @@ void WebDevToolsAgentImpl::Session::InitializeInspectorSession(
inspector_session_->Append(
new InspectorWorkerAgent(inspected_frames, nullptr));
tracing_agent_ = new InspectorTracingAgent(inspected_frames);
inspector_session_->Append(tracing_agent_);
page_agent_ = InspectorPageAgent::Create(
inspected_frames, agent_, agent_->resource_content_loader_.Get(),
inspector_session_->V8Session());
......
......@@ -85,6 +85,8 @@ blink_core_sources("inspector") {
"inspector_task_runner.h",
"inspector_trace_events.cc",
"inspector_trace_events.h",
"inspector_tracing_agent.cc",
"inspector_tracing_agent.h",
"inspector_worker_agent.cc",
"inspector_worker_agent.h",
"main_thread_debugger.cc",
......
......@@ -71,6 +71,11 @@
"domain": "Memory",
"include": ["getDOMCounters", "startSampling", "stopSampling", "getSamplingProfile", "getAllTimeSamplingProfile"]
},
{
"domain": "Tracing",
"include": ["start", "end"],
"async": ["start", "end"]
},
{
"domain": "Page",
"exclude": ["getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled",
......
// Copyright 2014 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 "third_party/blink/renderer/core/inspector/inspector_tracing_agent.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
namespace blink {
using protocol::Maybe;
using protocol::Response;
namespace {
const char kDevtoolsMetadataEventCategory[] =
TRACE_DISABLED_BY_DEFAULT("devtools.timeline");
}
InspectorTracingAgent::InspectorTracingAgent(InspectedFrames* inspected_frames)
: session_id_(&agent_state_, /*default_value=*/ WTF::String()),
inspected_frames_(inspected_frames) {}
InspectorTracingAgent::~InspectorTracingAgent() {}
void InspectorTracingAgent::Trace(blink::Visitor* visitor) {
visitor->Trace(inspected_frames_);
InspectorBaseAgent::Trace(visitor);
}
void InspectorTracingAgent::Restore() {
if (IsStarted())
EmitMetadataEvents();
}
void InspectorTracingAgent::start(Maybe<String> categories,
Maybe<String> options,
Maybe<double> buffer_usage_reporting_interval,
Maybe<String> transfer_mode,
Maybe<String> transfer_compression,
Maybe<protocol::Tracing::TraceConfig> config,
std::unique_ptr<StartCallback> callback) {
DCHECK(!IsStarted());
if (config.isJust()) {
callback->sendFailure(Response::Error(
"Using trace config on renderer targets is not supported yet."));
return;
}
session_id_.Set(IdentifiersFactory::CreateIdentifier());
// Tracing is already started by DevTools TracingHandler::Start for the
// renderer target in the browser process. It will eventually start tracing
// in the renderer process via IPC. But we still need a redundant enable here
// for EmitMetadataEvents, at which point we are not sure if tracing
// is already started in the renderer process.
TraceEvent::EnableTracing(categories.fromMaybe(String()));
EmitMetadataEvents();
callback->sendSuccess();
}
void InspectorTracingAgent::end(std::unique_ptr<EndCallback> callback) {
TraceEvent::DisableTracing();
InnerDisable();
callback->sendSuccess();
}
bool InspectorTracingAgent::IsStarted() const {
return !session_id_.Get().IsEmpty();
}
void InspectorTracingAgent::EmitMetadataEvents() {
TRACE_EVENT_INSTANT1(kDevtoolsMetadataEventCategory, "TracingStartedInPage",
TRACE_EVENT_SCOPE_THREAD, "data",
InspectorTracingStartedInFrame::Data(
session_id_.Get(), inspected_frames_->Root()));
}
Response InspectorTracingAgent::disable() {
InnerDisable();
return Response::OK();
}
void InspectorTracingAgent::InnerDisable() {
session_id_.Clear();
}
} // namespace blink
/*
* Copyright 2014 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 THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_TRACING_AGENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_TRACING_AGENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/inspector/inspector_base_agent.h"
#include "third_party/blink/renderer/core/inspector/protocol/Tracing.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class InspectedFrames;
class CORE_EXPORT InspectorTracingAgent final
: public InspectorBaseAgent<protocol::Tracing::Metainfo> {
public:
explicit InspectorTracingAgent(InspectedFrames*);
~InspectorTracingAgent() override;
void Trace(blink::Visitor*) override;
// Base agent methods.
void Restore() override;
protocol::Response disable() override;
// Protocol method implementations.
void start(protocol::Maybe<String> categories,
protocol::Maybe<String> options,
protocol::Maybe<double> buffer_usage_reporting_interval,
protocol::Maybe<String> transfer_mode,
protocol::Maybe<String> transfer_compression,
protocol::Maybe<protocol::Tracing::TraceConfig>,
std::unique_ptr<StartCallback>) override;
void end(std::unique_ptr<EndCallback>) override;
private:
void EmitMetadataEvents();
void InnerDisable();
bool IsStarted() const;
InspectorAgentState::String session_id_;
Member<InspectedFrames> inspected_frames_;
DISALLOW_COPY_AND_ASSIGN(InspectorTracingAgent);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECTOR_TRACING_AGENT_H_
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