Commit 6f9bbc62 authored by Oystein Eftevaag's avatar Oystein Eftevaag Committed by Commit Bot

Devtools/tracing: Propagate errors from the tracing service dying

Right now if the utility process hosting the tracing service crashes
while tracing is in progress, the error isn't propagated and the
Tracing.end request will just eventually time out. Instead we now
throw an error right away to make these crashes more actionable.

R=caseq@chromium.org

Bug: 956191
Change-Id: Ie0f176676e9dc5e4ce29b3c228df56180975d483
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1603830
Commit-Queue: oysteine <oysteine@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658407}
parent f5181777
...@@ -242,6 +242,7 @@ class TracingHandler::TracingSession { ...@@ -242,6 +242,7 @@ class TracingHandler::TracingSession {
base::OnceCallback<void(float percent_full, base::OnceCallback<void(float percent_full,
size_t approximate_event_count)> size_t approximate_event_count)>
on_buffer_usage_callback) = 0; on_buffer_usage_callback) = 0;
virtual bool HasTracingFailed() = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(TracingSession); DISALLOW_COPY_AND_ASSIGN(TracingSession);
...@@ -282,6 +283,8 @@ class TracingHandler::LegacyTracingSession ...@@ -282,6 +283,8 @@ class TracingHandler::LegacyTracingSession
TracingController::GetInstance()->GetTraceBufferUsage( TracingController::GetInstance()->GetTraceBufferUsage(
std::move(on_buffer_usage_callback)); std::move(on_buffer_usage_callback));
} }
bool HasTracingFailed() override { return false; }
}; };
class TracingHandler::PerfettoTracingSession class TracingHandler::PerfettoTracingSession
...@@ -290,19 +293,16 @@ class TracingHandler::PerfettoTracingSession ...@@ -290,19 +293,16 @@ class TracingHandler::PerfettoTracingSession
public mojo::DataPipeDrainer::Client { public mojo::DataPipeDrainer::Client {
public: public:
~PerfettoTracingSession() override { ~PerfettoTracingSession() override {
#if DCHECK_IS_ON()
DCHECK(!tracing_active_); DCHECK(!tracing_active_);
#endif
} }
// TracingHandler::TracingSession implementation: // TracingHandler::TracingSession implementation:
void EnableTracing(const base::trace_event::TraceConfig& chrome_config, void EnableTracing(const base::trace_event::TraceConfig& chrome_config,
base::OnceClosure on_recording_enabled_callback) override { base::OnceClosure on_recording_enabled_callback) override {
DCHECK(!tracing_session_host_); DCHECK(!tracing_session_host_);
#if DCHECK_IS_ON()
DCHECK(!tracing_active_); DCHECK(!tracing_active_);
tracing_active_ = true; tracing_active_ = true;
#endif
ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface(
tracing::mojom::kServiceName, &consumer_host_); tracing::mojom::kServiceName, &consumer_host_);
...@@ -355,12 +355,12 @@ class TracingHandler::PerfettoTracingSession ...@@ -355,12 +355,12 @@ class TracingHandler::PerfettoTracingSession
use_proto_format_ = use_proto_format; use_proto_format_ = use_proto_format;
agent_label_ = agent_label; agent_label_ = agent_label;
endpoint_ = endpoint; endpoint_ = endpoint;
#if DCHECK_IS_ON()
tracing_active_ = false; tracing_active_ = false;
#endif
if (!tracing_session_host_) { if (!tracing_session_host_) {
OnTracingSessionFailed(); if (endpoint_)
endpoint_->ReceiveTraceFinalContents(nullptr);
return; return;
} }
...@@ -409,6 +409,10 @@ class TracingHandler::PerfettoTracingSession ...@@ -409,6 +409,10 @@ class TracingHandler::PerfettoTracingSession
std::move(on_buffer_usage_callback).Run(percent_full, 0); std::move(on_buffer_usage_callback).Run(percent_full, 0);
} }
bool HasTracingFailed() override {
return tracing_active_ && !tracing_session_host_;
}
// tracing::mojom::TracingSessionClient implementation: // tracing::mojom::TracingSessionClient implementation:
void OnTracingEnabled() override { void OnTracingEnabled() override {
if (on_recording_enabled_callback_) { if (on_recording_enabled_callback_) {
...@@ -471,6 +475,13 @@ class TracingHandler::PerfettoTracingSession ...@@ -471,6 +475,13 @@ class TracingHandler::PerfettoTracingSession
tracing_session_host_.reset(); tracing_session_host_.reset();
binding_.Close(); binding_.Close();
drainer_.reset(); drainer_.reset();
if (on_recording_enabled_callback_)
std::move(on_recording_enabled_callback_).Run();
if (pending_disable_tracing_task_)
std::move(pending_disable_tracing_task_).Run();
if (endpoint_) { if (endpoint_) {
// TODO(oysteine): Signal to the client that tracing failed. // TODO(oysteine): Signal to the client that tracing failed.
endpoint_->ReceiveTraceFinalContents(nullptr); endpoint_->ReceiveTraceFinalContents(nullptr);
...@@ -514,9 +525,9 @@ class TracingHandler::PerfettoTracingSession ...@@ -514,9 +525,9 @@ class TracingHandler::PerfettoTracingSession
std::unique_ptr<mojo::DataPipeDrainer> drainer_; std::unique_ptr<mojo::DataPipeDrainer> drainer_;
bool data_complete_ = false; bool data_complete_ = false;
bool read_buffers_complete_ = false; bool read_buffers_complete_ = false;
bool tracing_active_ = false;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
bool tracing_active_ = false;
base::trace_event::TraceConfig last_config_for_perfetto_; base::trace_event::TraceConfig last_config_for_perfetto_;
#endif #endif
}; };
...@@ -859,6 +870,9 @@ Response TracingHandler::End() { ...@@ -859,6 +870,9 @@ Response TracingHandler::End() {
if (!session_) if (!session_)
return Response::Error("Tracing is not started"); return Response::Error("Tracing is not started");
if (session_->HasTracingFailed())
return Response::Error("Tracing failed");
scoped_refptr<TracingController::TraceDataEndpoint> endpoint; scoped_refptr<TracingController::TraceDataEndpoint> endpoint;
if (return_as_stream_) { if (return_as_stream_) {
endpoint = new DevToolsStreamEndpoint( endpoint = new DevToolsStreamEndpoint(
......
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