Chromium Code Reviews| Index: runtime/bin/main.cc |
| =================================================================== |
| --- runtime/bin/main.cc (revision 18477) |
| +++ runtime/bin/main.cc (working copy) |
| @@ -20,6 +20,7 @@ |
| #include "bin/log.h" |
| #include "bin/platform.h" |
| #include "bin/process.h" |
| +#include "bin/vmstats_impl.h" |
| #include "platform/globals.h" |
| // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| @@ -47,6 +48,9 @@ |
| static const char* debug_ip = DEFAULT_DEBUG_IP; |
| static int debug_port = 0; |
| +// Global state that defines the VmStats web server port and root directory. |
| +static int vmstats_port = 0; |
| +static const char* vmstats_root = NULL; |
| // Value of the --package-root flag. |
| // (This pointer points into an argv buffer and does not need to be |
| @@ -164,6 +168,31 @@ |
| } |
| +static bool ProcessVmStatsOption(const char* port) { |
| + ASSERT(port != NULL); |
| + if (*port == '\0') { |
| + vmstats_port = -1; // Dynamically assigned port number. |
| + } else { |
| + if ((*port == '=') || (*port == ':')) { |
| + vmstats_port = atoi(port + 1); |
| + } |
| + } |
| + if (vmstats_port == 0) { |
| + Log::PrintErr("unrecognized --stats option syntax. " |
| + "Use --stats[:<port number>]\n"); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| + |
| +static bool ProcessVmStatsRootOption(const char* arg) { |
| + ASSERT(arg != NULL); |
| + vmstats_root = arg; |
| + return true; |
| +} |
| + |
| + |
| static bool ProcessGenScriptSnapshotOption(const char* filename) { |
| if (filename != NULL && strlen(filename) != 0) { |
| // Ensure that are already running using a full snapshot. |
| @@ -207,6 +236,8 @@ |
| { "--debug", ProcessDebugOption }, |
| { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, |
| { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, |
| + { "--stats-root=", ProcessVmStatsRootOption }, |
| + { "--stats", ProcessVmStatsOption }, |
| { NULL, NULL } |
| }; |
| @@ -488,6 +519,7 @@ |
| return false; |
| } |
| Dart_ExitScope(); |
| + dart::VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate); |
| return true; |
| } |
| @@ -550,6 +582,10 @@ |
| "--generate-script-snapshot=<file_name>\n" |
| " loads Dart script and generates a snapshot in the specified file\n" |
| "\n" |
| +"--stats[:<port number>]\n" |
| +" enables VM stats service and listens on specified port for HTTP requests\n" |
| +" (default port number is dynamically assigned)\n" |
| +"\n" |
|
siva
2013/02/15 05:59:10
Should we also list help for the '--stats-root' op
Tom Ball
2013/02/16 00:57:19
Done.
|
| "The following options are only used for VM development and may\n" |
| "be changed in any future version:\n"); |
| const char* print_flags = "--print_flags"; |
| @@ -627,6 +663,7 @@ |
| static void ShutdownIsolate(void* callback_data) { |
| IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| + dart::VmStats::RemoveIsolate(isolate_data); |
| EventHandler* handler = isolate_data->event_handler; |
| if (handler != NULL) handler->Shutdown(); |
| delete isolate_data; |
| @@ -713,6 +750,10 @@ |
| Dart_EnterScope(); |
| + if (vmstats_port > 0) { |
|
siva
2013/02/15 05:59:10
What about the case when vmstats_port is -1 ?
Tom Ball
2013/02/16 00:57:19
Good catch. It turns out 0 is the official dynamic
|
| + dart::VmStats::Start(vmstats_port, vmstats_root); |
| + } |
| + |
| if (generate_script_snapshot) { |
| // First create a snapshot. |
| Dart_Handle result; |
| @@ -773,6 +814,7 @@ |
| } |
| Dart_ExitScope(); |
| + dart::VmStats::Stop(); |
| // Shutdown the isolate. |
| Dart_ShutdownIsolate(); |
| // Terminate process exit-code handler. |