diff --git a/sky/engine/core/script/dart_init.cc b/sky/engine/core/script/dart_init.cc index bdf356e9c7f..8df302d70eb 100644 --- a/sky/engine/core/script/dart_init.cc +++ b/sky/engine/core/script/dart_init.cc @@ -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 dart_flags; if (base::CommandLine::ForCurrentProcess()->HasSwitch(kDartFlags)) { // Split up dart flags by spaces. diff --git a/sky/engine/public/platform/sky_settings.h b/sky/engine/public/platform/sky_settings.h index 068eb9db88a..81f6427ab92 100644 --- a/sky/engine/public/platform/sky_settings.h +++ b/sky/engine/public/platform/sky_settings.h @@ -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(); diff --git a/sky/shell/platform/mojo/BUILD.gn b/sky/shell/platform/mojo/BUILD.gn index 4d97eb48582..ac884a8872d 100644 --- a/sky/shell/platform/mojo/BUILD.gn +++ b/sky/shell/platform/mojo/BUILD.gn @@ -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", diff --git a/sky/shell/platform/mojo/dart_tracing.cc b/sky/shell/platform/mojo/dart_tracing.cc deleted file mode 100644 index 1917d2e1e16..00000000000 --- a/sky/shell/platform/mojo/dart_tracing.cc +++ /dev/null @@ -1,171 +0,0 @@ -// 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 - -#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 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 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* data = - reinterpret_cast*>(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 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 data; - bool got_trace = Dart_GlobalTimelineGetTrace(AppendStreamConsumer, &data); - if (got_trace) { - SplitAndRecord(reinterpret_cast(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 request) { - provider_impl_.Bind(request.Pass()); -} - -} // namespace dart diff --git a/sky/shell/platform/mojo/dart_tracing.h b/sky/shell/platform/mojo/dart_tracing.h deleted file mode 100644 index 5929d8e7043..00000000000 --- a/sky/shell/platform/mojo/dart_tracing.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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 request); - - private: - // tracing::TraceProvider implementation: - void StartTracing( - const mojo::String& categories, - mojo::InterfaceHandle recorder) override; - void StopTracing() override; - - void SplitAndRecord(char* data, size_t length); - - mojo::Binding binding_; - tracing::TraceRecorderPtr recorder_; - - DISALLOW_COPY_AND_ASSIGN(DartTraceProvider); -}; - -class DartTracingImpl : - public mojo::InterfaceFactory { - 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 implementation. - void Create(mojo::ApplicationConnection* connection, - mojo::InterfaceRequest request) override; - private: - DartTraceProvider provider_impl_; - - DISALLOW_COPY_AND_ASSIGN(DartTracingImpl); -}; - -} // namespace dart - -#endif // SKY_SHELL_PLATFORM_MOJO_DART_TRACING_H_ diff --git a/sky/shell/platform/mojo/main_mojo.cc b/sky/shell/platform/mojo/main_mojo.cc index 0110d6f0db9..77eb32b2013 100644 --- a/sky/shell/platform/mojo/main_mojo.cc +++ b/sky/shell/platform/mojo/main_mojo.cc @@ -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); };