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

Side by Side Diff: runtime/bin/vmstats_impl.cc

Issue 12340088: - Fix string formatting. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/vmstats_impl.h" 5 #include "bin/vmstats_impl.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "bin/fdutils.h" 9 #include "bin/fdutils.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return; 52 return;
53 } 53 }
54 54
55 const intptr_t BACKLOG = 128; // Default value from HttpServer.dart 55 const intptr_t BACKLOG = 128; // Default value from HttpServer.dart
56 int64_t address = ServerSocket::CreateBindListen(host_ip, port, BACKLOG); 56 int64_t address = ServerSocket::CreateBindListen(host_ip, port, BACKLOG);
57 if (address < 0) { 57 if (address < 0) {
58 Log::PrintErr("Failed binding VmStats socket: %s:%d\n", host, port); 58 Log::PrintErr("Failed binding VmStats socket: %s:%d\n", host, port);
59 return; 59 return;
60 } 60 }
61 instance_->bind_address_ = address; 61 instance_->bind_address_ = address;
62 Log::Print( 62 Log::Print("VmStats URL: http://%s:%"Pd"/\n", host, Socket::GetPort(address));
63 #if defined(TARGET_ARCH_X64)
64 "VmStats URL: http://%s:%ld/\n",
65 #else
66 "VmStats URL: http://%s:%d/\n",
67 #endif
68 host,
69 Socket::GetPort(address));
70 63
71 instance_->running_ = true; 64 instance_->running_ = true;
72 int errno = dart::Thread::Start(WebServer, address); 65 int err = dart::Thread::Start(WebServer, address);
73 if (errno != 0) { 66 if (err != 0) {
74 Log::PrintErr("Failed starting VmStats thread: %d\n", errno); 67 Log::PrintErr("Failed starting VmStats thread: %d\n", err);
75 Shutdown(); 68 Shutdown();
76 } 69 }
77 } 70 }
78 71
79 72
80 void VmStats::Stop() { 73 void VmStats::Stop() {
81 MonitorLocker ml(&instance_monitor_); 74 MonitorLocker ml(&instance_monitor_);
82 if (instance_ != NULL) { 75 if (instance_ != NULL) {
83 instance_->running_ = false; 76 instance_->running_ = false;
84 } 77 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (strcmp(url, "/isolates") == 0) { 196 if (strcmp(url, "/isolates") == 0) {
204 content = instance_->IsolatesStatus(); 197 content = instance_->IsolatesStatus();
205 } else { 198 } else {
206 // Check plug-ins. 199 // Check plug-ins.
207 content = VmStatusService::GetVmStatus(url); 200 content = VmStatusService::GetVmStatus(url);
208 } 201 }
209 202
210 if (content != NULL) { 203 if (content != NULL) {
211 size_t content_len = strlen(content); 204 size_t content_len = strlen(content);
212 len = snprintf(buffer, BUFSIZE, 205 len = snprintf(buffer, BUFSIZE,
213 #if defined(TARGET_ARCH_X64)
214 "HTTP/1.1 200 OK\nContent-Type: application/json; charset=UTF-8\n" 206 "HTTP/1.1 200 OK\nContent-Type: application/json; charset=UTF-8\n"
215 "Content-Length: %lx\n\n", 207 "Content-Length: %"Pu"\n\n",
216 #else
217 "HTTP/1.1 200 OK\nContent-Type: application/json; charset=UTF-8\n"
218 "Content-Length: %d\n\n",
219 #endif
220 content_len); 208 content_len);
221 Socket::Write(socket, buffer, strlen(buffer)); 209 Socket::Write(socket, buffer, strlen(buffer));
222 Socket::Write(socket, content, content_len); 210 Socket::Write(socket, content, content_len);
223 Socket::Write(socket, "\n", 1); 211 Socket::Write(socket, "\n", 1);
224 Socket::Write(socket, buffer, strlen(buffer)); 212 Socket::Write(socket, buffer, strlen(buffer));
225 free(content); 213 free(content);
226 } else { 214 } else {
227 // No status content with this URL, return file or resource content. 215 // No status content with this URL, return file or resource content.
228 std::string path(instance_->root_directory_); 216 std::string path(instance_->root_directory_);
229 path.append(url); 217 path.append(url);
230 218
231 // Expand directory URLs. 219 // Expand directory URLs.
232 if (strcmp(url, "/") == 0) { 220 if (strcmp(url, "/") == 0) {
233 path.append(VMSTATS_HTML); 221 path.append(VMSTATS_HTML);
234 } else if (url[strlen(url) - 1] == '/') { 222 } else if (url[strlen(url) - 1] == '/') {
235 path.append(INDEX_HTML); 223 path.append(INDEX_HTML);
236 } 224 }
237 225
238 bool success = false; 226 bool success = false;
239 if (File::Exists(path.c_str())) { 227 if (File::Exists(path.c_str())) {
240 File* f = File::Open(path.c_str(), File::kRead); 228 File* f = File::Open(path.c_str(), File::kRead);
241 if (f != NULL) { 229 if (f != NULL) {
242 intptr_t len = f->Length(); 230 intptr_t len = f->Length();
243 char* text_buffer = reinterpret_cast<char*>(malloc(len)); 231 char* text_buffer = reinterpret_cast<char*>(malloc(len));
244 if (f->ReadFully(text_buffer, len)) { 232 if (f->ReadFully(text_buffer, len)) {
245 const char* content_type = ContentType(path.c_str()); 233 const char* content_type = ContentType(path.c_str());
246 snprintf(buffer, BUFSIZE, 234 snprintf(buffer, BUFSIZE,
247 #if defined(TARGET_ARCH_X64)
248 "HTTP/1.1 200 OK\nContent-Type: %s\n" 235 "HTTP/1.1 200 OK\nContent-Type: %s\n"
249 "Content-Length: %ld\n\n", 236 "Content-Length: %"Pu"\n\n",
250 #else
251 "HTTP/1.1 200 OK\nContent-Type: %s\n"
252 "Content-Length: %d\n\n",
253 #endif
254 content_type, len); 237 content_type, len);
255 Socket::Write(socket, buffer, strlen(buffer)); 238 Socket::Write(socket, buffer, strlen(buffer));
256 Socket::Write(socket, text_buffer, len); 239 Socket::Write(socket, text_buffer, len);
257 Socket::Write(socket, "\n", 1); 240 Socket::Write(socket, "\n", 1);
258 success = true; 241 success = true;
259 } 242 }
260 free(text_buffer); 243 free(text_buffer);
261 delete f; 244 delete f;
262 } 245 }
263 } else { 246 } else {
(...skipping 14 matching lines...) Expand all
278 char* VmStats::IsolatesStatus() { 261 char* VmStats::IsolatesStatus() {
279 std::ostringstream stream; 262 std::ostringstream stream;
280 stream << '{' << std::endl; 263 stream << '{' << std::endl;
281 stream << "\"isolates\": [" << std::endl; 264 stream << "\"isolates\": [" << std::endl;
282 IsolateTable::iterator itr; 265 IsolateTable::iterator itr;
283 bool first = true; 266 bool first = true;
284 for (itr = isolate_table_.begin(); itr != isolate_table_.end(); ++itr) { 267 for (itr = isolate_table_.begin(); itr != isolate_table_.end(); ++itr) {
285 Dart_Isolate isolate = itr->second; 268 Dart_Isolate isolate = itr->second;
286 static char request[512]; 269 static char request[512];
287 snprintf(request, sizeof(request), 270 snprintf(request, sizeof(request),
288 #if defined(TARGET_ARCH_X64) 271 "/isolate/0x%"Px,
289 "/isolate/0x%lx", 272 reinterpret_cast<intptr_t>(isolate));
290 #else
291 "/isolate/0x%llx",
292 #endif
293 reinterpret_cast<int64_t>(isolate));
294 char* status = VmStatusService::GetVmStatus(request); 273 char* status = VmStatusService::GetVmStatus(request);
295 if (status != NULL) { 274 if (status != NULL) {
296 stream << status; 275 stream << status;
297 if (!first) { 276 if (!first) {
298 stream << "," << std::endl; 277 stream << "," << std::endl;
299 } 278 }
300 first = false; 279 first = false;
301 } 280 }
302 free(status); 281 free(status);
303 } 282 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 VmStatusPlugin* plugin = instance_->registered_plugin_list_; 323 VmStatusPlugin* plugin = instance_->registered_plugin_list_;
345 while (plugin != NULL) { 324 while (plugin != NULL) {
346 char* result = (plugin->callback())(request); 325 char* result = (plugin->callback())(request);
347 if (result != NULL) { 326 if (result != NULL) {
348 return result; 327 return result;
349 } 328 }
350 plugin = plugin->next(); 329 plugin = plugin->next();
351 } 330 }
352 return NULL; 331 return NULL;
353 } 332 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698