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

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

Issue 12221022: Initial prototype of vmstats support, based on Dart VM Stats draft design doc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Code review feedback response 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
11 11
12 #include "bin/builtin.h" 12 #include "bin/builtin.h"
13 #include "bin/dartutils.h" 13 #include "bin/dartutils.h"
14 #include "bin/dbg_connection.h" 14 #include "bin/dbg_connection.h"
15 #include "bin/directory.h" 15 #include "bin/directory.h"
16 #include "bin/eventhandler.h" 16 #include "bin/eventhandler.h"
17 #include "bin/extensions.h" 17 #include "bin/extensions.h"
18 #include "bin/file.h" 18 #include "bin/file.h"
19 #include "bin/isolate_data.h" 19 #include "bin/isolate_data.h"
20 #include "bin/log.h" 20 #include "bin/log.h"
21 #include "bin/platform.h" 21 #include "bin/platform.h"
22 #include "bin/process.h" 22 #include "bin/process.h"
23 #include "bin/vmstats_impl.h"
23 #include "platform/globals.h" 24 #include "platform/globals.h"
24 25
25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 26 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
26 // it is initialized to NULL. 27 // it is initialized to NULL.
27 extern const uint8_t* snapshot_buffer; 28 extern const uint8_t* snapshot_buffer;
28 29
29 30
30 // Global state that stores a pointer to the application script snapshot. 31 // Global state that stores a pointer to the application script snapshot.
31 static bool use_script_snapshot = false; 32 static bool use_script_snapshot = false;
32 static bool generate_script_snapshot = false; 33 static bool generate_script_snapshot = false;
33 static File* snapshot_file = NULL; 34 static File* snapshot_file = NULL;
34 35
35 36
36 // Global state that indicates whether there is a debug breakpoint. 37 // Global state that indicates whether there is a debug breakpoint.
37 // This pointer points into an argv buffer and does not need to be 38 // This pointer points into an argv buffer and does not need to be
38 // free'd. 39 // free'd.
39 static const char* breakpoint_at = NULL; 40 static const char* breakpoint_at = NULL;
40 41
41 42
42 // Global state that indicates whether we should open a connection 43 // Global state that indicates whether we should open a connection
43 // and listen for a debugger to connect. 44 // and listen for a debugger to connect.
44 static bool start_debugger = false; 45 static bool start_debugger = false;
45 static const int DEFAULT_DEBUG_PORT = 5858; 46 static const int DEFAULT_DEBUG_PORT = 5858;
46 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; 47 static const char* DEFAULT_DEBUG_IP = "127.0.0.1";
47 static const char* debug_ip = DEFAULT_DEBUG_IP; 48 static const char* debug_ip = DEFAULT_DEBUG_IP;
48 static int debug_port = 0; 49 static int debug_port = 0;
49 50
51 // Global state that defines the VmStats web server port and root directory.
52 static int vmstats_port = -1;
53 static const char* vmstats_root = NULL;
50 54
51 // Value of the --package-root flag. 55 // Value of the --package-root flag.
52 // (This pointer points into an argv buffer and does not need to be 56 // (This pointer points into an argv buffer and does not need to be
53 // free'd.) 57 // free'd.)
54 static const char* package_root = NULL; 58 static const char* package_root = NULL;
55 59
56 60
57 // Global flag that is used to indicate that we want to compile all the 61 // Global flag that is used to indicate that we want to compile all the
58 // dart functions and not run anything. 62 // dart functions and not run anything.
59 static bool has_compile_all = false; 63 static bool has_compile_all = false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (snapshot_file == NULL) { 161 if (snapshot_file == NULL) {
158 Log::PrintErr("Unable to open file %s for reading the snapshot\n", 162 Log::PrintErr("Unable to open file %s for reading the snapshot\n",
159 filename); 163 filename);
160 return false; 164 return false;
161 } 165 }
162 } 166 }
163 return true; 167 return true;
164 } 168 }
165 169
166 170
171 static bool ProcessVmStatsOption(const char* port) {
172 ASSERT(port != NULL);
173 if (*port == '\0') {
174 vmstats_port = 0; // Dynamically assigned port number.
175 } else {
176 if ((*port == '=') || (*port == ':')) {
177 vmstats_port = atoi(port + 1);
178 }
179 }
180 if (vmstats_port < 0) {
181 Log::PrintErr("unrecognized --stats option syntax. "
182 "Use --stats[:<port number>]\n");
183 return false;
184 }
185 return true;
186 }
187
188
189 static bool ProcessVmStatsRootOption(const char* arg) {
190 ASSERT(arg != NULL);
191 vmstats_root = arg;
192 return true;
193 }
194
195
167 static bool ProcessGenScriptSnapshotOption(const char* filename) { 196 static bool ProcessGenScriptSnapshotOption(const char* filename) {
168 if (filename != NULL && strlen(filename) != 0) { 197 if (filename != NULL && strlen(filename) != 0) {
169 // Ensure that are already running using a full snapshot. 198 // Ensure that are already running using a full snapshot.
170 if (snapshot_buffer == NULL) { 199 if (snapshot_buffer == NULL) {
171 Log::PrintErr("Script snapshots cannot be generated in this version of" 200 Log::PrintErr("Script snapshots cannot be generated in this version of"
172 " dart\n"); 201 " dart\n");
173 return false; 202 return false;
174 } 203 }
175 if (use_script_snapshot) { 204 if (use_script_snapshot) {
176 Log::PrintErr("Incompatible options specified --use-script-snapshot " 205 Log::PrintErr("Incompatible options specified --use-script-snapshot "
(...skipping 23 matching lines...) Expand all
200 { "--verbose", ProcessVerboseOption }, 229 { "--verbose", ProcessVerboseOption },
201 { "-v", ProcessVerboseOption }, 230 { "-v", ProcessVerboseOption },
202 { "--package-root=", ProcessPackageRootOption }, 231 { "--package-root=", ProcessPackageRootOption },
203 { "-p", ProcessPackageRootOption }, 232 { "-p", ProcessPackageRootOption },
204 // VM specific options to the standalone dart program. 233 // VM specific options to the standalone dart program.
205 { "--break_at=", ProcessBreakpointOption }, 234 { "--break_at=", ProcessBreakpointOption },
206 { "--compile_all", ProcessCompileAllOption }, 235 { "--compile_all", ProcessCompileAllOption },
207 { "--debug", ProcessDebugOption }, 236 { "--debug", ProcessDebugOption },
208 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, 237 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption },
209 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, 238 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption },
239 { "--stats-root=", ProcessVmStatsRootOption },
240 { "--stats", ProcessVmStatsOption },
210 { NULL, NULL } 241 { NULL, NULL }
211 }; 242 };
212 243
213 244
214 static bool ProcessMainOptions(const char* option) { 245 static bool ProcessMainOptions(const char* option) {
215 int i = 0; 246 int i = 0;
216 const char* name = main_options[0].option_name; 247 const char* name = main_options[0].option_name;
217 while (name != NULL) { 248 while (name != NULL) {
218 int length = strlen(name); 249 int length = strlen(name);
219 if (strncmp(option, name, length) == 0) { 250 if (strncmp(option, name, length) == 0) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 char errbuf[256]; 512 char errbuf[256];
482 snprintf(errbuf, sizeof(errbuf), 513 snprintf(errbuf, sizeof(errbuf),
483 "Expected a library when loading script: %s", 514 "Expected a library when loading script: %s",
484 script_uri); 515 script_uri);
485 *error = strdup(errbuf); 516 *error = strdup(errbuf);
486 Dart_ExitScope(); 517 Dart_ExitScope();
487 Dart_ShutdownIsolate(); 518 Dart_ShutdownIsolate();
488 return false; 519 return false;
489 } 520 }
490 Dart_ExitScope(); 521 Dart_ExitScope();
522 dart::VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate);
491 return true; 523 return true;
492 } 524 }
493 525
494 526
495 static bool CreateIsolateAndSetup(const char* script_uri, 527 static bool CreateIsolateAndSetup(const char* script_uri,
496 const char* main, 528 const char* main,
497 void* data, char** error) { 529 void* data, char** error) {
498 return CreateIsolateAndSetupHelper(script_uri, 530 return CreateIsolateAndSetupHelper(script_uri,
499 main, 531 main,
500 new IsolateData(), 532 new IsolateData(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 " sets a breakpoint at specified location where <location> is one of :\n" 575 " sets a breakpoint at specified location where <location> is one of :\n"
544 " url:<line_num> e.g. test.dart:10\n" 576 " url:<line_num> e.g. test.dart:10\n"
545 " [<class_name>.]<function_name> e.g. B.foo\n" 577 " [<class_name>.]<function_name> e.g. B.foo\n"
546 "\n" 578 "\n"
547 "--use-script-snapshot=<file_name>\n" 579 "--use-script-snapshot=<file_name>\n"
548 " executes Dart script present in the specified snapshot file\n" 580 " executes Dart script present in the specified snapshot file\n"
549 "\n" 581 "\n"
550 "--generate-script-snapshot=<file_name>\n" 582 "--generate-script-snapshot=<file_name>\n"
551 " loads Dart script and generates a snapshot in the specified file\n" 583 " loads Dart script and generates a snapshot in the specified file\n"
552 "\n" 584 "\n"
585 "--stats[:<port number>]\n"
586 " enables VM stats service and listens on specified port for HTTP requests\n"
587 " (default port number is dynamically assigned)\n"
588 "\n"
589 "--stats-root=<path>\n"
590 " where to find static files used by the vmstats application\n"
591 " (used during vmstats plug-in development)\n"
592 "\n"
553 "The following options are only used for VM development and may\n" 593 "The following options are only used for VM development and may\n"
554 "be changed in any future version:\n"); 594 "be changed in any future version:\n");
555 const char* print_flags = "--print_flags"; 595 const char* print_flags = "--print_flags";
556 Dart_SetVMFlags(1, &print_flags); 596 Dart_SetVMFlags(1, &print_flags);
557 } 597 }
558 } 598 }
559 599
560 600
561 static Dart_Handle SetBreakpoint(const char* breakpoint_at, 601 static Dart_Handle SetBreakpoint(const char* breakpoint_at,
562 Dart_Handle library) { 602 Dart_Handle library) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 660
621 Dart_ExitScope(); 661 Dart_ExitScope();
622 Dart_ShutdownIsolate(); 662 Dart_ShutdownIsolate();
623 663
624 return kErrorExitCode; 664 return kErrorExitCode;
625 } 665 }
626 666
627 667
628 static void ShutdownIsolate(void* callback_data) { 668 static void ShutdownIsolate(void* callback_data) {
629 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); 669 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data);
670 dart::VmStats::RemoveIsolate(isolate_data);
630 EventHandler* handler = isolate_data->event_handler; 671 EventHandler* handler = isolate_data->event_handler;
631 if (handler != NULL) handler->Shutdown(); 672 if (handler != NULL) handler->Shutdown();
632 delete isolate_data; 673 delete isolate_data;
633 } 674 }
634 675
635 676
636 int main(int argc, char** argv) { 677 int main(int argc, char** argv) {
637 char* executable_name; 678 char* executable_name;
638 char* script_name; 679 char* script_name;
639 CommandLineOptions vm_options(argc); 680 CommandLineOptions vm_options(argc);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return kErrorExitCode; // Indicates we encountered an error. 747 return kErrorExitCode; // Indicates we encountered an error.
707 } 748 }
708 delete [] isolate_name; 749 delete [] isolate_name;
709 750
710 Dart_Isolate isolate = Dart_CurrentIsolate(); 751 Dart_Isolate isolate = Dart_CurrentIsolate();
711 ASSERT(isolate != NULL); 752 ASSERT(isolate != NULL);
712 Dart_Handle result; 753 Dart_Handle result;
713 754
714 Dart_EnterScope(); 755 Dart_EnterScope();
715 756
757 if (vmstats_port >= 0) {
758 dart::VmStats::Start(vmstats_port, vmstats_root);
759 }
760
716 if (generate_script_snapshot) { 761 if (generate_script_snapshot) {
717 // First create a snapshot. 762 // First create a snapshot.
718 Dart_Handle result; 763 Dart_Handle result;
719 uint8_t* buffer = NULL; 764 uint8_t* buffer = NULL;
720 intptr_t size = 0; 765 intptr_t size = 0;
721 result = Dart_CreateScriptSnapshot(&buffer, &size); 766 result = Dart_CreateScriptSnapshot(&buffer, &size);
722 if (Dart_IsError(result)) { 767 if (Dart_IsError(result)) {
723 Log::PrintErr("%s\n", Dart_GetError(result)); 768 Log::PrintErr("%s\n", Dart_GetError(result));
724 Dart_ExitScope(); 769 Dart_ExitScope();
725 Dart_ShutdownIsolate(); 770 Dart_ShutdownIsolate();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 return ErrorExit("%s\n", Dart_GetError(result)); 811 return ErrorExit("%s\n", Dart_GetError(result));
767 } 812 }
768 // Keep handling messages until the last active receive port is closed. 813 // Keep handling messages until the last active receive port is closed.
769 result = Dart_RunLoop(); 814 result = Dart_RunLoop();
770 if (Dart_IsError(result)) { 815 if (Dart_IsError(result)) {
771 return ErrorExit("%s\n", Dart_GetError(result)); 816 return ErrorExit("%s\n", Dart_GetError(result));
772 } 817 }
773 } 818 }
774 819
775 Dart_ExitScope(); 820 Dart_ExitScope();
821 dart::VmStats::Stop();
776 // Shutdown the isolate. 822 // Shutdown the isolate.
777 Dart_ShutdownIsolate(); 823 Dart_ShutdownIsolate();
778 // Terminate process exit-code handler. 824 // Terminate process exit-code handler.
779 Process::TerminateExitCodeHandler(); 825 Process::TerminateExitCodeHandler();
780 // Free copied argument strings if converted. 826 // Free copied argument strings if converted.
781 if (argv_converted) { 827 if (argv_converted) {
782 for (int i = 0; i < argc; i++) free(argv[i]); 828 for (int i = 0; i < argc; i++) free(argv[i]);
783 } 829 }
784 830
785 return Process::GlobalExitCode(); 831 return Process::GlobalExitCode();
786 } 832 }
OLDNEW
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/vmstats.h » ('j') | runtime/bin/vmstats_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698