| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 server.performance; | 5 library server.performance; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 /** | 62 /** |
| 63 * The amount of time to give the server to respond to a shutdown request | 63 * The amount of time to give the server to respond to a shutdown request |
| 64 * before forcibly terminating it. | 64 * before forcibly terminating it. |
| 65 */ | 65 */ |
| 66 const Duration SHUTDOWN_TIMEOUT = const Duration(seconds: 25); | 66 const Duration SHUTDOWN_TIMEOUT = const Duration(seconds: 25); |
| 67 | 67 |
| 68 const TMP_SRC_DIR_OPTION = 'tmpSrcDir'; | 68 const TMP_SRC_DIR_OPTION = 'tmpSrcDir'; |
| 69 const VERBOSE_CMDLINE_OPTION = 'verbose'; | 69 const VERBOSE_CMDLINE_OPTION = 'verbose'; |
| 70 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; | 70 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; |
| 71 | 71 |
| 72 ArgParser _argParser; |
| 73 |
| 74 ArgParser get argParser { |
| 75 _argParser = new ArgParser(); |
| 76 |
| 77 _argParser.addOption(INPUT_CMDLINE_OPTION, abbr: 'i', help: '<filePath>\n' |
| 78 'The input file specifying how this client should interact with the server
.\n' |
| 79 'If the input file name is "stdin", then the instructions are read from st
andard input.'); |
| 80 _argParser.addOption(MAP_OPTION, |
| 81 abbr: 'm', |
| 82 allowMultiple: true, |
| 83 splitCommas: false, |
| 84 help: '<oldSrcPath>,<newSrcPath>\n' |
| 85 'This option defines a mapping from the original source directory <old
SrcPath>\n' |
| 86 'when the instrumentation or log file was generated\n' |
| 87 'to the target source directory <newSrcPath> used during performance t
esting.\n' |
| 88 'Multiple mappings can be specified.\n' |
| 89 'WARNING: The contents of the target directory will be modified'); |
| 90 _argParser.addOption(TMP_SRC_DIR_OPTION, abbr: 't', help: '<dirPath>\n' |
| 91 'The temporary directory containing source used during performance measure
ment.\n' |
| 92 'WARNING: The contents of the target directory will be modified'); |
| 93 _argParser.addFlag(NEW_TASK_MODEL_OPTION, |
| 94 help: "enable the use of the new task model", |
| 95 defaultsTo: false, |
| 96 negatable: false); |
| 97 _argParser.addOption(DIAGNOSTIC_PORT_OPTION, |
| 98 abbr: 'd', |
| 99 help: 'localhost port on which server will provide diagnostic web pages'); |
| 100 _argParser.addFlag(VERBOSE_CMDLINE_OPTION, |
| 101 abbr: 'v', help: 'Verbose logging', negatable: false); |
| 102 _argParser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, |
| 103 help: 'Extra verbose logging', negatable: false); |
| 104 _argParser.addFlag(HELP_CMDLINE_OPTION, |
| 105 abbr: 'h', help: 'Print this help information', negatable: false); |
| 106 return _argParser; |
| 107 } |
| 108 |
| 72 /** | 109 /** |
| 73 * Open and return the input stream specifying how this client | 110 * Open and return the input stream specifying how this client |
| 74 * should interact with the analysis server. | 111 * should interact with the analysis server. |
| 75 */ | 112 */ |
| 76 Stream<Operation> openInput(PerfArgs args) { | 113 Stream<Operation> openInput(PerfArgs args) { |
| 77 var logger = new Logger('openInput'); | 114 var logger = new Logger('openInput'); |
| 78 Stream<List<int>> inputRaw; | 115 Stream<List<int>> inputRaw; |
| 79 if (args.inputPath == 'stdin') { | 116 if (args.inputPath == 'stdin') { |
| 80 inputRaw = stdin; | 117 inputRaw = stdin; |
| 81 } else { | 118 } else { |
| 82 inputRaw = new File(args.inputPath).openRead(); | 119 inputRaw = new File(args.inputPath).openRead(); |
| 83 } | 120 } |
| 84 for (PathMapEntry entry in args.srcPathMap.entries) { | 121 for (PathMapEntry entry in args.srcPathMap.entries) { |
| 85 logger.log(Level.INFO, 'mapping source path\n' | 122 logger.log(Level.INFO, 'mapping source path\n' |
| 86 ' from ${entry.oldSrcPrefix}\n to ${entry.newSrcPrefix}'); | 123 ' from ${entry.oldSrcPrefix}\n to ${entry.newSrcPrefix}'); |
| 87 } | 124 } |
| 88 logger.log(Level.INFO, 'tmpSrcDir: ${args.tmpSrcDirPath}'); | 125 logger.log(Level.INFO, 'tmpSrcDir: ${args.tmpSrcDirPath}'); |
| 89 return inputRaw | 126 return inputRaw |
| 90 .transform(SYSTEM_ENCODING.decoder) | 127 .transform(SYSTEM_ENCODING.decoder) |
| 91 .transform(new LineSplitter()) | 128 .transform(new LineSplitter()) |
| 92 .transform(new InputConverter(args.tmpSrcDirPath, args.srcPathMap)); | 129 .transform(new InputConverter(args.tmpSrcDirPath, args.srcPathMap)); |
| 93 } | 130 } |
| 94 | 131 |
| 95 /** | 132 /** |
| 96 * Parse the command line arguments. | 133 * Parse the command line arguments. |
| 97 */ | 134 */ |
| 98 PerfArgs parseArgs(List<String> rawArgs) { | 135 PerfArgs parseArgs(List<String> rawArgs) { |
| 99 ArgParser parser = new ArgParser(); | |
| 100 | |
| 101 parser.addOption(INPUT_CMDLINE_OPTION, abbr: 'i', help: '<filePath>\n' | |
| 102 'The input file specifying how this client should interact with the server
.\n' | |
| 103 'If the input file name is "stdin", then the instructions are read from st
andard input.'); | |
| 104 parser.addOption(MAP_OPTION, | |
| 105 abbr: 'm', | |
| 106 allowMultiple: true, | |
| 107 splitCommas: false, | |
| 108 help: '<oldSrcPath>,<newSrcPath>\n' | |
| 109 'This option defines a mapping from the original source directory <oldSrcP
ath>\n' | |
| 110 'when the instrumentation or log file was generated\n' | |
| 111 'to the target source directory <newSrcPath> used during performance testi
ng.\n' | |
| 112 'Multiple mappings can be specified.\n' | |
| 113 'WARNING: The contents of the target directory will be modified'); | |
| 114 parser.addOption(TMP_SRC_DIR_OPTION, abbr: 't', help: '<dirPath>\n' | |
| 115 'The temporary directory containing source used during performance measure
ment.\n' | |
| 116 'WARNING: The contents of the target directory will be modified'); | |
| 117 parser.addFlag(NEW_TASK_MODEL_OPTION, | |
| 118 help: "enable the use of the new task model", | |
| 119 defaultsTo: false, | |
| 120 negatable: false); | |
| 121 parser.addOption(DIAGNOSTIC_PORT_OPTION, | |
| 122 abbr: 'd', | |
| 123 help: 'localhost port on which server will provide diagnostic web pages'); | |
| 124 parser.addFlag(VERBOSE_CMDLINE_OPTION, | |
| 125 abbr: 'v', help: 'Verbose logging', negatable: false); | |
| 126 parser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, | |
| 127 help: 'Extra verbose logging', negatable: false); | |
| 128 parser.addFlag(HELP_CMDLINE_OPTION, | |
| 129 abbr: 'h', help: 'Print this help information', negatable: false); | |
| 130 | |
| 131 ArgResults args; | 136 ArgResults args; |
| 132 PerfArgs perfArgs = new PerfArgs(); | 137 PerfArgs perfArgs = new PerfArgs(); |
| 133 try { | 138 try { |
| 134 args = parser.parse(rawArgs); | 139 args = argParser.parse(rawArgs); |
| 135 } on Exception catch (e) { | 140 } on Exception catch (e) { |
| 136 print(e); | 141 print(e); |
| 137 printHelp(parser); | 142 printHelp(); |
| 138 exit(1); | 143 exit(1); |
| 139 } | 144 } |
| 140 | 145 |
| 141 bool showHelp = args[HELP_CMDLINE_OPTION] || args.rest.isNotEmpty; | 146 bool showHelp = args[HELP_CMDLINE_OPTION] || args.rest.isNotEmpty; |
| 142 | 147 |
| 143 bool isMissing(key) => args[key] == null || args[key].isEmpty; | 148 bool isMissing(key) => args[key] == null || args[key].isEmpty; |
| 144 | 149 |
| 145 perfArgs.inputPath = args[INPUT_CMDLINE_OPTION]; | 150 perfArgs.inputPath = args[INPUT_CMDLINE_OPTION]; |
| 146 if (isMissing(INPUT_CMDLINE_OPTION)) { | 151 if (isMissing(INPUT_CMDLINE_OPTION)) { |
| 147 print('missing $INPUT_CMDLINE_OPTION argument'); | 152 print('missing $INPUT_CMDLINE_OPTION argument'); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 187 |
| 183 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { | 188 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { |
| 184 Logger.root.level = Level.FINE; | 189 Logger.root.level = Level.FINE; |
| 185 } else if (args[VERBOSE_CMDLINE_OPTION]) { | 190 } else if (args[VERBOSE_CMDLINE_OPTION]) { |
| 186 Logger.root.level = Level.INFO; | 191 Logger.root.level = Level.INFO; |
| 187 } else { | 192 } else { |
| 188 Logger.root.level = Level.WARNING; | 193 Logger.root.level = Level.WARNING; |
| 189 } | 194 } |
| 190 | 195 |
| 191 if (showHelp) { | 196 if (showHelp) { |
| 192 printHelp(parser); | 197 printHelp(); |
| 193 exit(1); | 198 exit(1); |
| 194 } | 199 } |
| 195 | 200 |
| 196 return perfArgs; | 201 return perfArgs; |
| 197 } | 202 } |
| 198 | 203 |
| 199 void printHelp(ArgParser parser) { | 204 void printHelp() { |
| 200 print(''); | 205 print(''); |
| 201 print('Launch and interact with the AnalysisServer'); | 206 print('Launch and interact with the AnalysisServer'); |
| 202 print(''); | 207 print(''); |
| 203 print(parser.usage); | 208 print(argParser.usage); |
| 204 } | 209 } |
| 205 | 210 |
| 206 /** | 211 /** |
| 207 * Ensure that the given path has a trailing separator | 212 * Ensure that the given path has a trailing separator |
| 208 */ | 213 */ |
| 209 String _withTrailingSeparator(String dirPath) { | 214 String _withTrailingSeparator(String dirPath) { |
| 210 if (dirPath != null && dirPath.length > 4) { | 215 if (dirPath != null && dirPath.length > 4) { |
| 211 if (!dirPath.endsWith(path.separator)) { | 216 if (!dirPath.endsWith(path.separator)) { |
| 212 return '$dirPath${path.separator}'; | 217 return '$dirPath${path.separator}'; |
| 213 } | 218 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 242 /** | 247 /** |
| 243 * The diagnostic port for Analysis Server or `null` if none. | 248 * The diagnostic port for Analysis Server or `null` if none. |
| 244 */ | 249 */ |
| 245 int diagnosticPort; | 250 int diagnosticPort; |
| 246 | 251 |
| 247 /** | 252 /** |
| 248 * `true` if the server should run using the new task model. | 253 * `true` if the server should run using the new task model. |
| 249 */ | 254 */ |
| 250 bool newTaskModel; | 255 bool newTaskModel; |
| 251 } | 256 } |
| OLD | NEW |