提交 678409b8 编写于 作者: J Jason Simmons

Revert "Plumb dart timeline events to mojo:tracing. (#2595)" (#2670)

This needs to be updated for the latest Mojo APIs
上级 ef589f99
......@@ -114,10 +114,6 @@ static const char* kDartTraceStartupArgs[]{
"--timeline_recorder=endless",
};
static const char* kVmCompleteTimelineArgs[]{
"--complete_timeline",
};
const char kFileUriPrefix[] = "file://";
const char kDartFlags[] = "dart-flags";
......@@ -511,9 +507,6 @@ void InitDartVM() {
if (SkySettings::Get().trace_startup)
args.append(kDartTraceStartupArgs, arraysize(kDartTraceStartupArgs));
if (SkySettings::Get().vm_complete_timeline)
args.append(kVmCompleteTimelineArgs, arraysize(kVmCompleteTimelineArgs));
Vector<std::string> dart_flags;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kDartFlags)) {
// Split up dart flags by spaces.
......
......@@ -19,7 +19,6 @@ struct SkySettings {
bool start_paused = false;
bool enable_dart_checked_mode = false;
bool trace_startup = false;
bool vm_complete_timeline = false;
std::string aot_snapshot_path;
static const SkySettings& Get();
......
......@@ -13,8 +13,6 @@ mojo_native_application("mojo") {
"application_impl.h",
"content_handler_impl.cc",
"content_handler_impl.h",
"dart_tracing.cc",
"dart_tracing.h",
"main_mojo.cc",
"platform_view_mojo.cc",
"platform_view_mojo.h",
......@@ -38,7 +36,6 @@ mojo_native_application("mojo") {
"//mojo/services/content_handler/interfaces",
"//mojo/services/gfx/composition/interfaces",
"//mojo/services/input_events/interfaces",
"//mojo/services/tracing/interfaces",
"//mojo/services/ui/input/interfaces",
"//mojo/services/ui/views/interfaces",
"//services/asset_bundle:lib",
......
// Copyright 2015 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/shell/platform/mojo/dart_tracing.h"
#include <utility>
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "dart/runtime/include/dart_tools_api.h"
#include "mojo/public/cpp/application/application_impl.h"
namespace dart {
void DartTimelineController::Enable(const mojo::String& categories) {
if (categories == mojo::String("Dart")) {
Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART);
} else {
// TODO(johnmccutchan): Respect |categories|.
EnableAll();
}
}
void DartTimelineController::EnableAll() {
Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_ALL);
}
void DartTimelineController::Disable() {
Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DISABLE);
}
DartTraceProvider::DartTraceProvider()
: binding_(this) {
}
DartTraceProvider::~DartTraceProvider() {
}
void DartTraceProvider::Bind(
mojo::InterfaceRequest<tracing::TraceProvider> request) {
if (!binding_.is_bound()) {
binding_.Bind(request.Pass());
} else {
LOG(ERROR) << "Cannot accept two connections to TraceProvider.";
}
}
// tracing::TraceProvider implementation:
void DartTraceProvider::StartTracing(
const mojo::String& categories,
mojo::InterfaceHandle<tracing::TraceRecorder> recorder) {
DCHECK(!recorder_.get());
recorder_ = tracing::TraceRecorderPtr::Create(std::move(recorder));
DartTimelineController::Enable(categories);
}
static void AppendStreamConsumer(Dart_StreamConsumer_State state,
const char* stream_name,
const uint8_t* buffer,
intptr_t buffer_length,
void* user_data) {
if (state == Dart_StreamConsumer_kFinish) {
return;
}
std::vector<uint8_t>* data =
reinterpret_cast<std::vector<uint8_t>*>(user_data);
DCHECK(data);
if (state == Dart_StreamConsumer_kStart) {
data->clear();
return;
}
DCHECK_EQ(state, Dart_StreamConsumer_kData);
// Append data.
data->insert(data->end(), buffer, buffer + buffer_length);
}
// recorder_->Record():
// 1. Doesn't like big hunks of data.
// See: https://github.com/domokit/mojo/issues/564
// 2. Expects to receive one or more complete JSON maps per call.
// Therefore, we parse the recorded data, split it up and send it to trace
// recorder in chunks.
void DartTraceProvider::SplitAndRecord(char* data, size_t length) {
const size_t kMinChunkLength = 1024 * 1024; // 1MB.
// The data from the VM is null-terminated content of a JSON array without its
// enclosing square brackets. Remove the trailing "\0" and add the enclosing
// brackets to make JSON parser happy.
std::string json_data = "[" + std::string(data, length -1) + "]";
base::JSONReader reader;
scoped_ptr<base::Value> trace_data = reader.ReadToValue(json_data);
if (!trace_data) {
LOG(ERROR) << "Dart tracing failed to parse the JSON string: "
<< reader.GetErrorMessage();
return;
}
base::ListValue* event_list;
if (!trace_data->GetAsList(&event_list)) {
LOG(ERROR) << "Dart tracing failed to parse the JSON string: data is not "
<< "a list.";
return;
}
// Iterate over trace events and send over the traces to the recorder each
// time we accumulate more than |kMinChunkLength| worth of data.
std::string current_chunk;
for (base::Value* val : *event_list) {
base::DictionaryValue* event_dict;
if (!val->GetAsDictionary(&event_dict)) {
LOG(WARNING) << "Dart tracing ignoring incorrect trace event: "
<< "not a dictionary";
continue;
}
std::string event_json;
if (!base::JSONWriter::Write(*event_dict, &event_json)) {
LOG(WARNING) << "Dart tracing ignoring trace event: "
<< "failed to serialize";
continue;
}
if (!current_chunk.empty()) {
current_chunk += ",";
}
current_chunk += event_json;
if (current_chunk.size() >= kMinChunkLength) {
mojo::String json(current_chunk.data(), current_chunk.size());
recorder_->Record(json);
current_chunk.clear();
}
}
if (!current_chunk.empty()) {
mojo::String json(current_chunk.data(), current_chunk.size());
recorder_->Record(json);
}
}
// tracing::TraceProvider implementation:
void DartTraceProvider::StopTracing() {
DCHECK(recorder_);
DartTimelineController::Disable();
std::vector<uint8_t> data;
bool got_trace = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data);
if (got_trace) {
SplitAndRecord(reinterpret_cast<char*>(data.data()), data.size());
}
recorder_.reset();
}
DartTracingImpl::DartTracingImpl() {
}
DartTracingImpl::~DartTracingImpl() {
}
void DartTracingImpl::Initialize(mojo::ApplicationImpl* app) {
auto connection = app->ConnectToApplication("mojo:tracing");
connection->AddService(this);
}
void DartTracingImpl::Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<tracing::TraceProvider> request) {
provider_impl_.Bind(request.Pass());
}
} // namespace dart
// Copyright 2015 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 SKY_SHELL_PLATFORM_MOJO_DART_TRACING_H_
#define SKY_SHELL_PLATFORM_MOJO_DART_TRACING_H_
#include "base/trace_event/trace_event.h"
#include "mojo/common/tracing_impl.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/services/tracing/interfaces/tracing.mojom.h"
namespace dart {
class DartTimelineController {
public:
static void Enable(const mojo::String& categories);
static void EnableAll();
static void Disable();
};
class DartTraceProvider : public tracing::TraceProvider {
public:
DartTraceProvider();
~DartTraceProvider() override;
void Bind(mojo::InterfaceRequest<tracing::TraceProvider> request);
private:
// tracing::TraceProvider implementation:
void StartTracing(
const mojo::String& categories,
mojo::InterfaceHandle<tracing::TraceRecorder> recorder) override;
void StopTracing() override;
void SplitAndRecord(char* data, size_t length);
mojo::Binding<tracing::TraceProvider> binding_;
tracing::TraceRecorderPtr recorder_;
DISALLOW_COPY_AND_ASSIGN(DartTraceProvider);
};
class DartTracingImpl :
public mojo::InterfaceFactory<tracing::TraceProvider> {
public:
DartTracingImpl();
~DartTracingImpl() override;
// This connects to the tracing service and registers ourselves to provide
// tracing data on demand.
void Initialize(mojo::ApplicationImpl* app);
private:
// InterfaceFactory<tracing::TraceProvider> implementation.
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<tracing::TraceProvider> request) override;
private:
DartTraceProvider provider_impl_;
DISALLOW_COPY_AND_ASSIGN(DartTracingImpl);
};
} // namespace dart
#endif // SKY_SHELL_PLATFORM_MOJO_DART_TRACING_H_
......@@ -16,14 +16,12 @@
#include "sky/engine/public/platform/sky_settings.h"
#include "sky/shell/shell.h"
#include "sky/shell/platform/mojo/content_handler_impl.h"
#include "sky/shell/platform/mojo/dart_tracing.h"
namespace sky {
namespace shell {
namespace {
const char kEnableCheckedMode[] = "--enable-checked-mode";
const char kVmCompleteTimeline[] = "--vm-complete-timeline";
} // namespace
......@@ -37,15 +35,11 @@ class MojoApp : public mojo::ApplicationDelegate,
// Overridden from ApplicationDelegate:
void Initialize(mojo::ApplicationImpl* app) override {
mojo::icu::Initialize(app);
// Tracing of content handler.
tracing_.Initialize(app);
// Tracing of isolates and VM.
dart_tracing_.Initialize(app);
blink::SkySettings settings;
settings.enable_observatory = true;
settings.enable_dart_checked_mode = app->HasArg(kEnableCheckedMode);
settings.vm_complete_timeline = app->HasArg(kVmCompleteTimeline);
blink::SkySettings::Set(settings);
Shell::Init();
......@@ -64,7 +58,6 @@ class MojoApp : public mojo::ApplicationDelegate,
}
mojo::TracingImpl tracing_;
dart::DartTracingImpl dart_tracing_;
DISALLOW_COPY_AND_ASSIGN(MojoApp);
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册