Chromium Code Reviews| 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/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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 StartProfiling(connection_id); | 95 StartProfiling(connection_id); |
| 96 else if (info.path == "/stop_profiling") | 96 else if (info.path == "/stop_profiling") |
| 97 StopProfiling(connection_id); | 97 StopProfiling(connection_id); |
| 98 else { | 98 else { |
| 99 Help(info.path, connection_id); | 99 Help(info.path, connection_id); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void OnWebSocketRequest( | 103 void OnWebSocketRequest( |
| 104 int connection_id, const net::HttpServerRequestInfo& info) override { | 104 int connection_id, const net::HttpServerRequestInfo& info) override { |
| 105 web_server_->Send500(connection_id, "http only"); | 105 Error(connection_id, "OnWebSocketRequest not implemented"); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void OnWebSocketMessage( | 108 void OnWebSocketMessage( |
| 109 int connection_id, const std::string& data) override { | 109 int connection_id, const std::string& data) override { |
| 110 web_server_->Send500(connection_id, "http only"); | 110 Error(connection_id, "OnWebSocketMessage not implemented"); |
| 111 } | |
| 112 | |
| 113 void Error(int connection_id, std::string message) { | |
| 114 web_server_->Send500(connection_id, message); | |
| 111 } | 115 } |
| 112 | 116 |
| 113 void Respond(int connection_id, std::string response) { | 117 void Respond(int connection_id, std::string response) { |
| 114 // When sending tracing data back over the wire to the client, we can blow | 118 // When sending tracing data back over the wire to the client, we can blow |
| 115 // through the default send buffer size. | 119 // through the default send buffer size. |
| 116 web_server_->SetSendBufferSize( | 120 web_server_->SetSendBufferSize( |
| 117 connection_id, std::max(kMinSendBufferSize, response.length())); | 121 connection_id, std::max(kMinSendBufferSize, response.length())); |
| 118 web_server_->Send200(connection_id, response, "text/plain"); | 122 web_server_->Send200(connection_id, response, "text/plain"); |
| 119 } | 123 } |
| 120 | 124 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); | 174 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); |
| 171 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); | 175 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); |
| 172 } | 176 } |
| 173 | 177 |
| 174 void OnTraceAvailable(int connection_id, std::string trace) { | 178 void OnTraceAvailable(int connection_id, std::string trace) { |
| 175 trace_collector_.reset(); | 179 trace_collector_.reset(); |
| 176 Respond(connection_id, trace); | 180 Respond(connection_id, trace); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void StartProfiling(int connection_id) { | 183 void StartProfiling(int connection_id) { |
| 184 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING) | |
| 185 Error(connection_id, | |
| 186 "Profiling requires debug=false and enable_profiling=true"); | |
|
abarth-chromium
2015/01/21 22:18:49
debug=false -> is_debug=false
eseidel
2015/01/21 22:44:43
Done.
| |
| 187 return; | |
| 188 #else | |
| 180 base::debug::StartProfiling("sky_viewer.pprof"); | 189 base::debug::StartProfiling("sky_viewer.pprof"); |
| 181 Respond(connection_id, "Starting profiling (stop with 'stop_profiling')"); | 190 Respond(connection_id, "Starting profiling (stop with 'stop_profiling')"); |
| 191 #endif | |
| 182 } | 192 } |
| 183 | 193 |
| 184 void StopProfiling(int connection_id) { | 194 void StopProfiling(int connection_id) { |
| 195 if (!base::debug::BeingProfiled()) { | |
| 196 Error(connection_id, "Profiling not started"); | |
| 197 return; | |
| 198 } | |
| 185 base::debug::StopProfiling(); | 199 base::debug::StopProfiling(); |
| 186 Respond(connection_id, "Stopped profiling"); | 200 Respond(connection_id, "Stopped profiling"); |
| 187 } | 201 } |
| 188 | 202 |
| 189 bool is_tracing_; | 203 bool is_tracing_; |
| 190 DebuggerPtr debugger_; | 204 DebuggerPtr debugger_; |
| 191 tracing::TraceCoordinatorPtr tracing_; | 205 tracing::TraceCoordinatorPtr tracing_; |
| 192 std::string url_; | 206 std::string url_; |
| 193 base::WeakPtrFactory<Prompt> weak_ptr_factory_; | 207 base::WeakPtrFactory<Prompt> weak_ptr_factory_; |
| 194 scoped_ptr<net::HttpServer> web_server_; | 208 scoped_ptr<net::HttpServer> web_server_; |
| 195 uint32_t command_port_; | 209 uint32_t command_port_; |
| 196 | 210 |
| 197 scoped_ptr<TraceCollector> trace_collector_; | 211 scoped_ptr<TraceCollector> trace_collector_; |
| 198 | 212 |
| 199 DISALLOW_COPY_AND_ASSIGN(Prompt); | 213 DISALLOW_COPY_AND_ASSIGN(Prompt); |
| 200 }; | 214 }; |
| 201 | 215 |
| 202 } // namespace debugger | 216 } // namespace debugger |
| 203 } // namespace sky | 217 } // namespace sky |
| 204 | 218 |
| 205 MojoResult MojoMain(MojoHandle shell_handle) { | 219 MojoResult MojoMain(MojoHandle shell_handle) { |
| 206 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); | 220 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); |
| 207 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); | 221 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); |
| 208 return runner.Run(shell_handle); | 222 return runner.Run(shell_handle); |
| 209 } | 223 } |
| OLD | NEW |