mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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
This commit is contained in:
parent
ec0519a888
commit
84690ebeab
@ -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",
|
||||
]
|
||||
|
||||
@ -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 <iostream>
|
||||
|
||||
@ -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<Prompt> weak_ptr_factory_;
|
||||
|
||||
|
||||
@ -25,8 +25,7 @@
|
||||
namespace sky {
|
||||
|
||||
class Viewer : public mojo::ApplicationDelegate,
|
||||
public mojo::InterfaceFactory<mojo::ContentHandler>,
|
||||
public mojo::InterfaceFactory<mojo::Tracing> {
|
||||
public mojo::InterfaceFactory<mojo::ContentHandler> {
|
||||
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<mojo::ContentHandler>(this);
|
||||
connection->AddService<mojo::Tracing>(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -53,12 +53,6 @@ class Viewer : public mojo::ApplicationDelegate,
|
||||
mojo::BindToRequest(new ContentHandlerImpl(), &request);
|
||||
}
|
||||
|
||||
// Overridden from InterfaceFactory<Tracing>
|
||||
virtual void Create(mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<mojo::Tracing> request) override {
|
||||
new mojo::TracingImpl(request.Pass(), FILE_PATH_LITERAL("sky_viewer"));
|
||||
}
|
||||
|
||||
scoped_ptr<PlatformImpl> platform_impl_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Viewer);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user