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/files/file_path.h" | 8 #include "base/debug/profiler.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "mojo/application/application_runner_chromium.h" | 12 #include "mojo/application/application_runner_chromium.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 "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/server/http_server.h" | 17 #include "net/server/http_server.h" |
18 #include "net/server/http_server_request_info.h" | 18 #include "net/server/http_server_request_info.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 if (info.path == "/trace") | 84 if (info.path == "/trace") |
85 ToggleTracing(connection_id); | 85 ToggleTracing(connection_id); |
86 else if (info.path == "/reload") | 86 else if (info.path == "/reload") |
87 Load(connection_id, url_); | 87 Load(connection_id, url_); |
88 else if (info.path == "/inspect") | 88 else if (info.path == "/inspect") |
89 Inspect(connection_id); | 89 Inspect(connection_id); |
90 else if (info.path == "/quit") | 90 else if (info.path == "/quit") |
91 Quit(connection_id); | 91 Quit(connection_id); |
92 else if (info.path == "/load") | 92 else if (info.path == "/load") |
93 Load(connection_id, info.data); | 93 Load(connection_id, info.data); |
| 94 else if (info.path == "/start_profiling") |
| 95 StartProfiling(connection_id); |
| 96 else if (info.path == "/stop_profiling") |
| 97 StopProfiling(connection_id); |
94 else { | 98 else { |
95 Help(info.path, connection_id); | 99 Help(info.path, connection_id); |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 void OnWebSocketRequest( | 103 void OnWebSocketRequest( |
100 int connection_id, const net::HttpServerRequestInfo& info) override { | 104 int connection_id, const net::HttpServerRequestInfo& info) override { |
101 web_server_->Send500(connection_id, "http only"); | 105 web_server_->Send500(connection_id, "http only"); |
102 } | 106 } |
103 | 107 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); | 169 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); |
166 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); | 170 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); |
167 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); | 171 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); |
168 } | 172 } |
169 | 173 |
170 void OnTraceAvailable(int connection_id, std::string trace) { | 174 void OnTraceAvailable(int connection_id, std::string trace) { |
171 trace_collector_.reset(); | 175 trace_collector_.reset(); |
172 Respond(connection_id, trace); | 176 Respond(connection_id, trace); |
173 } | 177 } |
174 | 178 |
| 179 void StartProfiling(int connection_id) { |
| 180 base::debug::StartProfiling("sky_viewer.pprof"); |
| 181 Respond(connection_id, "Starting profiling (type 'stop_profiling' to stop"); |
| 182 } |
| 183 |
| 184 void StopProfiling(int connection_id) { |
| 185 base::debug::StopProfiling(); |
| 186 Respond(connection_id, "Stopped profiling"); |
| 187 } |
| 188 |
175 bool is_tracing_; | 189 bool is_tracing_; |
176 DebuggerPtr debugger_; | 190 DebuggerPtr debugger_; |
177 tracing::TraceCoordinatorPtr tracing_; | 191 tracing::TraceCoordinatorPtr tracing_; |
178 std::string url_; | 192 std::string url_; |
179 base::WeakPtrFactory<Prompt> weak_ptr_factory_; | 193 base::WeakPtrFactory<Prompt> weak_ptr_factory_; |
180 scoped_ptr<net::HttpServer> web_server_; | 194 scoped_ptr<net::HttpServer> web_server_; |
181 uint32_t command_port_; | 195 uint32_t command_port_; |
182 | 196 |
183 scoped_ptr<TraceCollector> trace_collector_; | 197 scoped_ptr<TraceCollector> trace_collector_; |
184 | 198 |
185 DISALLOW_COPY_AND_ASSIGN(Prompt); | 199 DISALLOW_COPY_AND_ASSIGN(Prompt); |
186 }; | 200 }; |
187 | 201 |
188 } // namespace debugger | 202 } // namespace debugger |
189 } // namespace sky | 203 } // namespace sky |
190 | 204 |
191 MojoResult MojoMain(MojoHandle shell_handle) { | 205 MojoResult MojoMain(MojoHandle shell_handle) { |
192 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); | 206 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); |
193 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); | 207 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); |
194 return runner.Run(shell_handle); | 208 return runner.Run(shell_handle); |
195 } | 209 } |
OLD | NEW |