| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/profiler.h" | 8 #include "base/debug/profiler.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" | 21 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" |
| 22 #include "services/tracing/tracing.mojom.h" | 22 #include "services/tracing/tracing.mojom.h" |
| 23 #include "sky/tools/debugger/trace_collector.h" | 23 #include "sky/tools/debugger/trace_collector.h" |
| 24 | 24 |
| 25 namespace sky { | 25 namespace sky { |
| 26 namespace debugger { | 26 namespace debugger { |
| 27 | 27 |
| 28 class SkyDebugger : public mojo::ApplicationDelegate, | 28 class SkyDebugger : public mojo::ApplicationDelegate, |
| 29 public http_server::HttpHandler { | 29 public http_server::HttpHandler { |
| 30 public: | 30 public: |
| 31 SkyDebugger() : is_tracing_(false), handler_binding_(this) {} | 31 SkyDebugger() : is_tracing_(false), app_(nullptr), handler_binding_(this) {} |
| 32 ~SkyDebugger() override {} | 32 ~SkyDebugger() override {} |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 // mojo::ApplicationDelegate: | 35 // mojo::ApplicationDelegate: |
| 36 void Initialize(mojo::ApplicationImpl* app) override { | 36 void Initialize(mojo::ApplicationImpl* app) override { |
| 37 app->ConnectToService("mojo:tracing", &tracing_); | 37 app_ = app; |
| 38 app->ConnectToService("mojo:window_manager", &window_manager_); | 38 app->ConnectToService("mojo:window_manager", &window_manager_); |
| 39 | 39 |
| 40 // Format: --args-for="app_url command_port" | 40 // Format: --args-for="app_url command_port" |
| 41 if (app->args().size() < 2) { | 41 if (app->args().size() < 2) { |
| 42 LOG(ERROR) << "--args-for required to specify command_port"; | 42 LOG(ERROR) << "--args-for required to specify command_port"; |
| 43 mojo::ApplicationImpl::Terminate(); | 43 mojo::ApplicationImpl::Terminate(); |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 base::StringToUint(app->args()[1], &command_port_); | 46 base::StringToUint(app->args()[1], &command_port_); |
| 47 http_server::HttpServerFactoryPtr http_server_factory; | 47 http_server::HttpServerFactoryPtr http_server_factory; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // TODO(eseidel): We should orderly shutdown once mojo can. | 133 // TODO(eseidel): We should orderly shutdown once mojo can. |
| 134 exit(0); | 134 exit(0); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void StartTracing(const HandleRequestCallback& callback) { | 137 void StartTracing(const HandleRequestCallback& callback) { |
| 138 if (is_tracing_) { | 138 if (is_tracing_) { |
| 139 Error(callback, "Already tracing. Use stop_tracing to stop.\n"); | 139 Error(callback, "Already tracing. Use stop_tracing to stop.\n"); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 if (!tracing_) |
| 144 app_->ConnectToService("mojo:tracing", &tracing_); |
| 143 is_tracing_ = true; | 145 is_tracing_ = true; |
| 144 mojo::DataPipe pipe; | 146 mojo::DataPipe pipe; |
| 145 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); | 147 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); |
| 146 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); | 148 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); |
| 147 Respond(callback, "Starting trace (type 'stop_tracing' to stop)\n"); | 149 Respond(callback, "Starting trace (type 'stop_tracing' to stop)\n"); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void StopTracing(const HandleRequestCallback& callback) { | 152 void StopTracing(const HandleRequestCallback& callback) { |
| 151 if (!is_tracing_) { | 153 if (!is_tracing_) { |
| 152 Error(callback, "Not tracing yet. Use start_tracing to start.\n"); | 154 Error(callback, "Not tracing yet. Use start_tracing to start.\n"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 178 void StopProfiling(const HandleRequestCallback& callback) { | 180 void StopProfiling(const HandleRequestCallback& callback) { |
| 179 if (!base::debug::BeingProfiled()) { | 181 if (!base::debug::BeingProfiled()) { |
| 180 Error(callback, "Profiling not started"); | 182 Error(callback, "Profiling not started"); |
| 181 return; | 183 return; |
| 182 } | 184 } |
| 183 base::debug::StopProfiling(); | 185 base::debug::StopProfiling(); |
| 184 Respond(callback, "Stopped profiling"); | 186 Respond(callback, "Stopped profiling"); |
| 185 } | 187 } |
| 186 | 188 |
| 187 bool is_tracing_; | 189 bool is_tracing_; |
| 190 mojo::ApplicationImpl* app_; |
| 188 mojo::WindowManagerPtr window_manager_; | 191 mojo::WindowManagerPtr window_manager_; |
| 189 tracing::TraceCoordinatorPtr tracing_; | 192 tracing::TraceCoordinatorPtr tracing_; |
| 190 std::string url_; | 193 std::string url_; |
| 191 uint32_t command_port_; | 194 uint32_t command_port_; |
| 192 | 195 |
| 193 http_server::HttpServerPtr http_server_; | 196 http_server::HttpServerPtr http_server_; |
| 194 mojo::Binding<http_server::HttpHandler> handler_binding_; | 197 mojo::Binding<http_server::HttpHandler> handler_binding_; |
| 195 | 198 |
| 196 scoped_ptr<TraceCollector> trace_collector_; | 199 scoped_ptr<TraceCollector> trace_collector_; |
| 197 | 200 |
| 198 DISALLOW_COPY_AND_ASSIGN(SkyDebugger); | 201 DISALLOW_COPY_AND_ASSIGN(SkyDebugger); |
| 199 }; | 202 }; |
| 200 | 203 |
| 201 } // namespace debugger | 204 } // namespace debugger |
| 202 } // namespace sky | 205 } // namespace sky |
| 203 | 206 |
| 204 MojoResult MojoMain(MojoHandle application_request) { | 207 MojoResult MojoMain(MojoHandle application_request) { |
| 205 mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger); | 208 mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger); |
| 206 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); | 209 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); |
| 207 return runner.Run(application_request); | 210 return runner.Run(application_request); |
| 208 } | 211 } |
| OLD | NEW |