mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
The tracing service logically provides one service, TraceCoordinator, which can start and stop tracing sessions. It also can connect to any number of TraceControllers each of which can supply tracing information on demand. Whenever an app connects to the tracing service, the tracing service attempts to connect to that app's TraceController interface. If the app provides this interface then tracing data will be requested whenever tracing starts. If the app doesn't, then the pipe just closes. Thus apps that want to be traced can do so by creating however many connections to the tracing service they want and registering a TraceController implementation on each outgoing connection. The shell connects in a similar fashion by connecting to the tracing service and providing a TraceController implementation. The code looks a bit different since the shell is special. BUG=451319 R=viettrungluu@chromium.org Review URL: https://codereview.chromium.org/791493006
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
// 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 "sky/tools/debugger/trace_collector.h"
|
|
|
|
namespace sky {
|
|
namespace debugger {
|
|
|
|
TraceCollector::TraceCollector(mojo::ScopedDataPipeConsumerHandle source)
|
|
: drainer_(this, source.Pass()), is_complete_(false) {
|
|
}
|
|
|
|
TraceCollector::~TraceCollector() {
|
|
}
|
|
|
|
void TraceCollector::GetTrace(TraceCallback callback) {
|
|
DCHECK(callback_.is_null());
|
|
DCHECK(!callback.is_null());
|
|
if (is_complete_) {
|
|
callback.Run(GetTraceAsString());
|
|
return;
|
|
}
|
|
callback_ = callback;
|
|
}
|
|
|
|
void TraceCollector::OnDataAvailable(const void* data, size_t num_bytes) {
|
|
DCHECK(!is_complete_);
|
|
const char* chars = static_cast<const char*>(data);
|
|
trace_.insert(trace_.end(), chars, chars + num_bytes);
|
|
}
|
|
|
|
void TraceCollector::OnDataComplete() {
|
|
DCHECK(!is_complete_);
|
|
is_complete_ = true;
|
|
if (!callback_.is_null())
|
|
callback_.Run(GetTraceAsString());
|
|
}
|
|
|
|
std::string TraceCollector::GetTraceAsString() {
|
|
return std::string(&trace_.front(), trace_.size());
|
|
}
|
|
|
|
} // namespace debugger
|
|
} // namespace sky
|