Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: services/debugger/debugger.cc

Issue 1151573010: Pull Sky debugger up to services/debugger. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/debugger/BUILD.gn ('k') | services/debugger/trace_collector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "mojo/application/application_runner_chromium.h" 11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/common/data_pipe_utils.h" 12 #include "mojo/common/data_pipe_utils.h"
13 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/bindings/binding.h" 16 #include "mojo/public/cpp/bindings/binding.h"
17 #include "mojo/services/http_server/public/cpp/http_server_util.h" 17 #include "mojo/services/http_server/public/cpp/http_server_util.h"
18 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h" 18 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h"
19 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom. h" 19 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom. h"
20 #include "mojo/services/network/public/interfaces/net_address.mojom.h" 20 #include "mojo/services/network/public/interfaces/net_address.mojom.h"
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/debugger/trace_collector.h"
22 #include "services/tracing/tracing.mojom.h" 23 #include "services/tracing/tracing.mojom.h"
23 #include "sky/tools/debugger/trace_collector.h"
24 24
25 namespace sky { 25 // Debugger is a Mojo application that exposes an http server and talks to other
26 // mojo apps in response to url requests received by the server. Supported
27 // actions include tracing and profiling, allowing to interactively inspect how
28 // the shell is performing.
29
26 namespace debugger { 30 namespace debugger {
27 31
28 class SkyDebugger : public mojo::ApplicationDelegate, 32 class Debugger : public mojo::ApplicationDelegate,
29 public http_server::HttpHandler { 33 public http_server::HttpHandler {
30 public: 34 public:
31 SkyDebugger() : is_tracing_(false), app_(nullptr), handler_binding_(this) {} 35 Debugger() : is_tracing_(false), app_(nullptr), handler_binding_(this) {}
32 ~SkyDebugger() override {} 36 ~Debugger() override {}
33 37
34 private: 38 private:
35 // mojo::ApplicationDelegate: 39 // mojo::ApplicationDelegate:
36 void Initialize(mojo::ApplicationImpl* app) override { 40 void Initialize(mojo::ApplicationImpl* app) override {
37 app_ = app; 41 app_ = app;
38 app->ConnectToService("mojo:window_manager", &window_manager_); 42 app->ConnectToService("mojo:window_manager", &window_manager_);
39 43
40 // Format: --args-for="app_url command_port" 44 // Format: --args-for="app_url command_port"
41 if (app->args().size() < 2) { 45 if (app->args().size() < 2) {
42 LOG(ERROR) << "--args-for required to specify command_port"; 46 LOG(ERROR) << "--args-for required to specify command_port";
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 154 }
151 155
152 void StopTracing(const HandleRequestCallback& callback) { 156 void StopTracing(const HandleRequestCallback& callback) {
153 if (!is_tracing_) { 157 if (!is_tracing_) {
154 Error(callback, "Not tracing yet. Use start_tracing to start.\n"); 158 Error(callback, "Not tracing yet. Use start_tracing to start.\n");
155 return; 159 return;
156 } 160 }
157 161
158 is_tracing_ = false; 162 is_tracing_ = false;
159 tracing_->StopAndFlush(); 163 tracing_->StopAndFlush();
160 trace_collector_->GetTrace(base::Bind(&SkyDebugger::OnTraceAvailable, 164 trace_collector_->GetTrace(base::Bind(&Debugger::OnTraceAvailable,
161 base::Unretained(this), callback)); 165 base::Unretained(this), callback));
162 } 166 }
163 167
164 void OnTraceAvailable(HandleRequestCallback callback, std::string trace) { 168 void OnTraceAvailable(HandleRequestCallback callback, std::string trace) {
165 trace_collector_.reset(); 169 trace_collector_.reset();
166 Respond(callback, trace); 170 Respond(callback, trace);
167 } 171 }
168 172
169 void StartProfiling(const HandleRequestCallback& callback) { 173 void StartProfiling(const HandleRequestCallback& callback) {
170 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING) 174 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING)
(...skipping 20 matching lines...) Expand all
191 mojo::WindowManagerPtr window_manager_; 195 mojo::WindowManagerPtr window_manager_;
192 tracing::TraceCoordinatorPtr tracing_; 196 tracing::TraceCoordinatorPtr tracing_;
193 std::string url_; 197 std::string url_;
194 uint32_t command_port_; 198 uint32_t command_port_;
195 199
196 http_server::HttpServerPtr http_server_; 200 http_server::HttpServerPtr http_server_;
197 mojo::Binding<http_server::HttpHandler> handler_binding_; 201 mojo::Binding<http_server::HttpHandler> handler_binding_;
198 202
199 scoped_ptr<TraceCollector> trace_collector_; 203 scoped_ptr<TraceCollector> trace_collector_;
200 204
201 DISALLOW_COPY_AND_ASSIGN(SkyDebugger); 205 DISALLOW_COPY_AND_ASSIGN(Debugger);
202 }; 206 };
203 207
204 } // namespace debugger 208 } // namespace debugger
205 } // namespace sky
206 209
207 MojoResult MojoMain(MojoHandle application_request) { 210 MojoResult MojoMain(MojoHandle application_request) {
208 mojo::ApplicationRunnerChromium runner(new sky::debugger::SkyDebugger); 211 mojo::ApplicationRunnerChromium runner(new debugger::Debugger);
209 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); 212 runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
210 return runner.Run(application_request); 213 return runner.Run(application_request);
211 } 214 }
OLDNEW
« no previous file with comments | « services/debugger/BUILD.gn ('k') | services/debugger/trace_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698