From 84690ebeab40d056f2ca5ca282edb002abd65f08 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Mon, 1 Dec 2014 16:31:03 -0800 Subject: [PATCH] Add tracing service and make the shell+sky_viewer+services talk to it This adds a tracing service that can aggregate tracing data from multiple sources and write a json file out to disk that trace-viewer can understand. This also teaches the shell, sky_viewer, and various other services how to register themselves with the tracing service and provide tracing data on demand. Finally, this teaches the skydb prompt to tell the tracing service to start/stop tracing when the 'trace' command is issued. The tracing service exposes two APIs, a collector interface and a coordinator interface. The collector interface allows different entities to register themselves as being capable of producing tracing data. The coordinator interface allows asking the service to collect data from all registered sources and flushing the collected data to disk. The service keeps track of all open connections to registered sources and broadcasts a request for data whenever the coordinator's Start method is called, then aggregates all data send back into a single trace file. In this patch, the tracing service simply gives all sources 1 second to return data then flushes to disk. Ideally it would keep track of how many requests it sent out and give each source a certain amount of time to respond but this is simple and works for most cases. The tracing service can talk to any source that is capable of producing data that the trace-viewer can handle, which is a broad set, but in practice many programs will want to use //base/debug's tracing to produce trace data. This adds code at //mojo/common:tracing_impl that registers a collector hooked up to //base/debug's tracing system. This can be dropped in to the mojo::ApplicationDelegate::Initialize() implementation for most services and applications to easily enable base tracing. Programs that don't use //base, or that want to register additional data sources that can talk to trace viewer (perhaps providing data that's more easily available from another thread, say) may want to create additional connections to the tracing service. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/769963004 --- tools/debugger/prompt/BUILD.gn | 2 +- tools/debugger/prompt/prompt.cc | 10 +++++----- viewer/viewer.cc | 12 +++--------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tools/debugger/prompt/BUILD.gn b/tools/debugger/prompt/BUILD.gn index c6fbccfafaa..8429d6c72ff 100644 --- a/tools/debugger/prompt/BUILD.gn +++ b/tools/debugger/prompt/BUILD.gn @@ -14,10 +14,10 @@ mojo_native_application("prompt") { deps = [ "//base", "//mojo/application", - "//mojo/common:tracing_bindings", "//mojo/public/c/system:for_shared_library", "//mojo/public/cpp/bindings", "//mojo/public/cpp/utility", + "//services/tracing:bindings", "//sky/tools/debugger:bindings", "//sky/viewer:bindings", ] diff --git a/tools/debugger/prompt/prompt.cc b/tools/debugger/prompt/prompt.cc index f400055ac22..6ef357d1d22 100644 --- a/tools/debugger/prompt/prompt.cc +++ b/tools/debugger/prompt/prompt.cc @@ -5,10 +5,10 @@ #include "base/bind.h" #include "base/memory/weak_ptr.h" #include "mojo/application/application_runner_chromium.h" -#include "mojo/common/tracing.mojom.h" #include "mojo/public/c/system/main.h" #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_impl.h" +#include "services/tracing/tracing.mojom.h" #include "sky/tools/debugger/debugger.mojom.h" #include @@ -42,7 +42,7 @@ class Prompt : public mojo::ApplicationDelegate { private: // Overridden from mojo::ApplicationDelegate: virtual void Initialize(mojo::ApplicationImpl* app) override { - app->ConnectToService("mojo:sky_viewer", &tracing_); + app->ConnectToService("mojo:tracing", &tracing_); if (app->args().size() > 1) url_ = app->args()[1]; else { @@ -138,17 +138,17 @@ class Prompt : public mojo::ApplicationDelegate { void ToggleTracing() { if (is_tracing_) { std::cout << "Stopping trace (writing to sky_viewer.trace)" << std::endl; - tracing_->Stop(); + tracing_->StopAndFlush(); } else { std::cout << "Starting trace (type 'trace' to stop tracing)" << std::endl; - tracing_->Start(); + tracing_->Start(mojo::String("sky_viewer"), mojo::String("*")); } is_tracing_ = !is_tracing_; } bool is_tracing_; DebuggerPtr debugger_; - mojo::TracingPtr tracing_; + tracing::TraceCoordinatorPtr tracing_; std::string url_; base::WeakPtrFactory weak_ptr_factory_; diff --git a/viewer/viewer.cc b/viewer/viewer.cc index 9a325151b32..9db52a1e53e 100644 --- a/viewer/viewer.cc +++ b/viewer/viewer.cc @@ -25,8 +25,7 @@ namespace sky { class Viewer : public mojo::ApplicationDelegate, - public mojo::InterfaceFactory, - public mojo::InterfaceFactory { + public mojo::InterfaceFactory { public: Viewer() {} @@ -38,12 +37,13 @@ class Viewer : public mojo::ApplicationDelegate, platform_impl_.reset(new PlatformImpl(app)); blink::initialize(platform_impl_.get()); base::i18n::InitializeICU(); + + mojo::TracingImpl::Create(app); } virtual bool ConfigureIncomingConnection( mojo::ApplicationConnection* connection) override { connection->AddService(this); - connection->AddService(this); return true; } @@ -53,12 +53,6 @@ class Viewer : public mojo::ApplicationDelegate, mojo::BindToRequest(new ContentHandlerImpl(), &request); } - // Overridden from InterfaceFactory - virtual void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest request) override { - new mojo::TracingImpl(request.Pass(), FILE_PATH_LITERAL("sky_viewer")); - } - scoped_ptr platform_impl_; DISALLOW_COPY_AND_ASSIGN(Viewer);