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