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

Side by Side Diff: pkg/analysis_server/lib/driver.dart

Issue 664743002: Add command-line options for instrumentation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library driver; 5 library driver;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analysis_server/http_server.dart'; 9 import 'package:analysis_server/http_server.dart';
10 import 'package:analysis_server/src/socket_server.dart'; 10 import 'package:analysis_server/src/socket_server.dart';
11 import 'package:analysis_server/stdio_server.dart'; 11 import 'package:analysis_server/stdio_server.dart';
12 import 'package:analyzer/src/generated/java_io.dart'; 12 import 'package:analyzer/src/generated/java_io.dart';
13 import 'package:analyzer/src/generated/sdk.dart'; 13 import 'package:analyzer/src/generated/sdk.dart';
14 import 'package:analyzer/src/generated/sdk_io.dart'; 14 import 'package:analyzer/src/generated/sdk_io.dart';
15 import 'package:args/args.dart'; 15 import 'package:args/args.dart';
16 import 'package:logging/logging.dart'; 16 import 'package:logging/logging.dart';
17 17
18 /** 18 /**
19 * The [Driver] class represents a single running instance of the analysis 19 * The [Driver] class represents a single running instance of the analysis
20 * server application. It is responsible for parsing command line options 20 * server application. It is responsible for parsing command line options
21 * and starting the HTTP and/or stdio servers. 21 * and starting the HTTP and/or stdio servers.
22 */ 22 */
23 class Driver { 23 class Driver {
24 /** 24 /**
25 * The name of the application that is used to start a server. 25 * The name of the application that is used to start a server.
26 */ 26 */
27 static const BINARY_NAME = 'server'; 27 static const BINARY_NAME = 'server';
28 28
29 /** 29 /**
30 * The name of the option used to enable instrumentation.
31 */
32 static const String ENABLE_INSTRUMENTATION_OPTION = "enable-instrumentation";
33
34 /**
30 * The name of the option used to print usage information. 35 * The name of the option used to print usage information.
31 */ 36 */
32 static const String HELP_OPTION = "help"; 37 static const String HELP_OPTION = "help";
33 38
34 /** 39 /**
40 * The name of the option used to specify the log file to which
41 * instrumentation data is to be written.
42 */
43 static const String INSTRUMENTATION_LOG_FILE_OPTION = "instrumentation-log-fil e";
44
45 /**
35 * The name of the option used to specify the port to which the server will 46 * The name of the option used to specify the port to which the server will
36 * connect. 47 * connect.
37 */ 48 */
38 static const String PORT_OPTION = "port"; 49 static const String PORT_OPTION = "port";
39 50
40 /** 51 /**
41 * The name of the option used to specify the log file.
42 */
43 static const String LOG_FILE_OPTION = "log";
44
45 /**
46 * The path to the SDK. 52 * The path to the SDK.
47 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is 53 * TODO(paulberry): get rid of this once the 'analysis.updateSdks' request is
48 * operational. 54 * operational.
49 */ 55 */
50 static const String SDK_OPTION = 'sdk'; 56 static const String SDK_OPTION = 'sdk';
51 57
52 SocketServer socketServer; 58 SocketServer socketServer;
53 59
54 HttpAnalysisServer httpServer; 60 HttpAnalysisServer httpServer;
55 61
56 StdioAnalysisServer stdioServer; 62 StdioAnalysisServer stdioServer;
57 63
58 Driver() { 64 Driver() {
59 } 65 }
60 66
61 /** 67 /**
62 * Use the given command-line arguments to start this server. 68 * Use the given command-line arguments to start this server.
63 */ 69 */
64 void start(List<String> args) { 70 void start(List<String> args) {
65 ArgParser parser = new ArgParser(); 71 ArgParser parser = new ArgParser();
66 parser.addFlag(HELP_OPTION, help: 72 parser.addFlag(ENABLE_INSTRUMENTATION_OPTION,
67 "print this help message without starting a server", defaultsTo: false, 73 help: "enable sending instrumentation information to a server",
74 defaultsTo: false,
68 negatable: false); 75 negatable: false);
69 parser.addOption(PORT_OPTION, help: 76 parser.addFlag(HELP_OPTION,
70 "[port] the port on which the server will listen"); 77 help: "print this help message without starting a server",
71 parser.addOption(LOG_FILE_OPTION, help: 78 defaultsTo: false,
72 "[path] file to log debugging messages to"); 79 negatable: false);
73 parser.addOption(SDK_OPTION, help: 80 parser.addOption(INSTRUMENTATION_LOG_FILE_OPTION,
74 "[path] path to the sdk"); 81 help: "[path] the file to which instrumentation data will be logged");
82 parser.addOption(PORT_OPTION,
83 help: "[port] the port on which the server will listen");
84 parser.addOption(SDK_OPTION,
85 help: "[path] the path to the sdk");
75 86
76 ArgResults results = parser.parse(args); 87 ArgResults results = parser.parse(args);
77 if (results[HELP_OPTION]) { 88 if (results[HELP_OPTION]) {
78 _printUsage(parser); 89 _printUsage(parser);
79 return; 90 return;
80 } 91 }
81 if (results[LOG_FILE_OPTION] != null) { 92 if (results[ENABLE_INSTRUMENTATION_OPTION]) {
82 try { 93 if (results[INSTRUMENTATION_LOG_FILE_OPTION] != null) {
83 File file = new File(results[LOG_FILE_OPTION]); 94 // Initialize the instrumentation system with logging.
Paul Berry 2014/10/17 15:51:43 Nit: Can we make these TODO comments?
84 IOSink sink = file.openWrite(); 95 } else {
85 Logger.root.onRecord.listen((LogRecord record) { 96 // Initialize the instrumentation system without logging.
86 sink.writeln(record);
87 });
88 } catch (exception) {
89 print('Could not open log file: $exception');
90 exitCode = 1;
91 return;
92 } 97 }
93 } 98 }
94 int port; 99 int port;
95 bool serve_http = false; 100 bool serve_http = false;
96 if (results[PORT_OPTION] != null) { 101 if (results[PORT_OPTION] != null) {
97 serve_http = true; 102 serve_http = true;
98 try { 103 try {
99 port = int.parse(results[PORT_OPTION]); 104 port = int.parse(results[PORT_OPTION]);
100 } on FormatException { 105 } on FormatException {
101 print('Invalid port number: ${results[PORT_OPTION]}'); 106 print('Invalid port number: ${results[PORT_OPTION]}');
(...skipping 30 matching lines...) Expand all
132 /** 137 /**
133 * Print information about how to use the server. 138 * Print information about how to use the server.
134 */ 139 */
135 void _printUsage(ArgParser parser) { 140 void _printUsage(ArgParser parser) {
136 print('Usage: $BINARY_NAME [flags]'); 141 print('Usage: $BINARY_NAME [flags]');
137 print(''); 142 print('');
138 print('Supported flags are:'); 143 print('Supported flags are:');
139 print(parser.getUsage()); 144 print(parser.getUsage());
140 } 145 }
141 } 146 }
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