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

Side by Side Diff: sky/tools/debugger/prompt/prompt.cc

Issue 878283002: Split skydb trace into start_tracing and stop_tracing (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | sky/tools/skydb » ('j') | sky/tools/skydb » ('J')
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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 void OnClose(int connection_id) override { 76 void OnClose(int connection_id) override {
77 } 77 }
78 78
79 void OnHttpRequest( 79 void OnHttpRequest(
80 int connection_id, const net::HttpServerRequestInfo& info) override { 80 int connection_id, const net::HttpServerRequestInfo& info) override {
81 81
82 // FIXME: We should use use a fancier lookup system more like what 82 // FIXME: We should use use a fancier lookup system more like what
83 // services/http_server/http_server.cc does with AddHandler. 83 // services/http_server/http_server.cc does with AddHandler.
84 if (info.path == "/trace") 84 if (info.path == "/reload")
85 ToggleTracing(connection_id);
86 else if (info.path == "/reload")
87 Load(connection_id, url_); 85 Load(connection_id, url_);
88 else if (info.path == "/inspect") 86 else if (info.path == "/inspect")
89 Inspect(connection_id); 87 Inspect(connection_id);
90 else if (info.path == "/quit") 88 else if (info.path == "/quit")
91 Quit(connection_id); 89 Quit(connection_id);
92 else if (info.path == "/load") 90 else if (info.path == "/load")
93 Load(connection_id, info.data); 91 Load(connection_id, info.data);
94 else if (info.path == "/start_profiling") 92 else if (info.path == "/start_profiling")
95 StartProfiling(connection_id); 93 StartProfiling(connection_id);
96 else if (info.path == "/stop_profiling") 94 else if (info.path == "/stop_profiling")
97 StopProfiling(connection_id); 95 StopProfiling(connection_id);
98 else { 96 else if (info.path == "/start_tracing")
97 StartTracing(connection_id);
98 else if (info.path == "/stop_tracing")
99 StopTracing(connection_id);
100 else
99 Help(info.path, connection_id); 101 Help(info.path, connection_id);
100 }
101 } 102 }
102 103
103 void OnWebSocketRequest( 104 void OnWebSocketRequest(
104 int connection_id, const net::HttpServerRequestInfo& info) override { 105 int connection_id, const net::HttpServerRequestInfo& info) override {
105 Error(connection_id, "OnWebSocketRequest not implemented"); 106 Error(connection_id, "OnWebSocketRequest not implemented");
106 } 107 }
107 108
108 void OnWebSocketMessage( 109 void OnWebSocketMessage(
109 int connection_id, const std::string& data) override { 110 int connection_id, const std::string& data) override {
110 Error(connection_id, "OnWebSocketMessage not implemented"); 111 Error(connection_id, "OnWebSocketMessage not implemented");
111 } 112 }
112 113
113 void Error(int connection_id, std::string message) { 114 void Error(int connection_id, std::string message) {
114 web_server_->Send500(connection_id, message); 115 web_server_->Send500(connection_id, message);
115 } 116 }
116 117
117 void Respond(int connection_id, std::string response) { 118 void Respond(int connection_id, std::string response) {
118 // When sending tracing data back over the wire to the client, we can blow 119 // When sending tracing data back over the wire to the client, we can blow
119 // through the default send buffer size. 120 // through the default send buffer size.
120 web_server_->SetSendBufferSize( 121 web_server_->SetSendBufferSize(
121 connection_id, std::max(kMinSendBufferSize, response.length())); 122 connection_id, std::max(kMinSendBufferSize, response.length()));
122 web_server_->Send200(connection_id, response, "text/plain"); 123 web_server_->Send200(connection_id, response, "text/plain");
123 } 124 }
124 125
125 void Help(std::string path, int connection_id) { 126 void Help(std::string path, int connection_id) {
126 std::string help = base::StringPrintf("Sky Debugger running on port %d\n" 127 std::string help = base::StringPrintf("Sky Debugger running on port %d\n"
127 "Supported URLs:\n" 128 "Supported URLs:\n"
128 "/toggle_tracing -- Start/stop tracing\n"
129 "/reload -- Reload the current page\n" 129 "/reload -- Reload the current page\n"
130 "/inspect -- Start inspector server for current page\n"
131 "/quit -- Quit\n" 130 "/quit -- Quit\n"
132 "/load -- Load a new URL, url in POST body.\n", 131 "/load -- Load a new URL, url in POST body.\n",
133 command_port_); 132 command_port_);
134 if (path != "/") 133 if (path != "/")
135 help = "Unknown path: " + path + "\n\n" + help; 134 help = "Unknown path: " + path + "\n\n" + help;
136 Respond(connection_id, help); 135 Respond(connection_id, help);
137 } 136 }
138 137
139 void Load(int connection_id, std::string url) { 138 void Load(int connection_id, std::string url) {
140 url_ = url; 139 url_ = url;
(...skipping 10 matching lines...) Expand all
151 debugger_->InjectInspector(); 150 debugger_->InjectInspector();
152 Respond(connection_id, 151 Respond(connection_id,
153 "Open the following URL in Chrome:\n" 152 "Open the following URL in Chrome:\n"
154 "chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898\n"); 153 "chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898\n");
155 } 154 }
156 155
157 void Quit(int connection_id) { 156 void Quit(int connection_id) {
158 debugger_->Shutdown(); 157 debugger_->Shutdown();
159 } 158 }
160 159
161 void ToggleTracing(int connection_id) { 160 void StartTracing(int connection_id) {
162 bool was_tracing = is_tracing_; 161 if (is_tracing_) {
163 is_tracing_ = !is_tracing_; 162 Error(connection_id, "Already tracing. Use stop_tracing to stop.\n");
164
165 if (was_tracing) {
166 tracing_->StopAndFlush();
167 trace_collector_->GetTrace(base::Bind(
168 &Prompt::OnTraceAvailable, base::Unretained(this), connection_id));
169 return; 163 return;
170 } 164 }
171 165
166 is_tracing_ = true;
eseidel 2015/01/27 21:07:21 You don't need to check this, there are apis to te
abarth-chromium 2015/01/27 21:27:59 We're using mojo's multiapp tracing system to trac
172 mojo::DataPipe pipe; 167 mojo::DataPipe pipe;
173 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); 168 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*"));
174 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); 169 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass()));
175 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); 170 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n");
esprehn 2015/01/27 20:59:24 is this right? Or do you need to type stop_tracing
abarth-chromium 2015/01/27 21:27:59 Ah, will fix.
176 } 171 }
177 172
173 void StopTracing(int connection_id) {
174 if (!is_tracing_) {
175 Error(connection_id, "Not tracing yet. Use start_tracing to start.\n");
176 return;
177 }
178
179 is_tracing_ = false;
180 tracing_->StopAndFlush();
181 trace_collector_->GetTrace(base::Bind(
182 &Prompt::OnTraceAvailable, base::Unretained(this), connection_id));
183 }
184
178 void OnTraceAvailable(int connection_id, std::string trace) { 185 void OnTraceAvailable(int connection_id, std::string trace) {
179 trace_collector_.reset(); 186 trace_collector_.reset();
180 Respond(connection_id, trace); 187 Respond(connection_id, trace);
181 } 188 }
182 189
183 void StartProfiling(int connection_id) { 190 void StartProfiling(int connection_id) {
184 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING) 191 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING)
185 Error(connection_id, 192 Error(connection_id,
186 "Profiling requires is_debug=false and enable_profiling=true"); 193 "Profiling requires is_debug=false and enable_profiling=true");
187 return; 194 return;
(...skipping 26 matching lines...) Expand all
214 }; 221 };
215 222
216 } // namespace debugger 223 } // namespace debugger
217 } // namespace sky 224 } // namespace sky
218 225
219 MojoResult MojoMain(MojoHandle shell_handle) { 226 MojoResult MojoMain(MojoHandle shell_handle) {
220 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); 227 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt);
221 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); 228 runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
222 return runner.Run(shell_handle); 229 return runner.Run(shell_handle);
223 } 230 }
OLDNEW
« no previous file with comments | « no previous file | sky/tools/skydb » ('j') | sky/tools/skydb » ('J')

Powered by Google App Engine
This is Rietveld 408576698