| 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 |
| 11 import 'package:args/args.dart'; | 11 import 'package:args/args.dart'; |
| 12 import 'package:logging/logging.dart'; | 12 import 'package:logging/logging.dart'; |
| 13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
| 14 | 14 |
| 15 import 'driver.dart'; | 15 import 'driver.dart'; |
| 16 import 'input_converter.dart'; | 16 import 'input_converter.dart'; |
| 17 import 'operation.dart'; | 17 import 'operation.dart'; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Launch and interact with the analysis server. | 20 * Launch and interact with the analysis server. |
| 21 */ | 21 */ |
| 22 main(List<String> rawArgs) { | 22 main(List<String> rawArgs) { |
| 23 Logger logger = new Logger('Performance Measurement Client'); | 23 Logger logger = new Logger('Performance Measurement Client'); |
| 24 logger.onRecord.listen((LogRecord rec) { | 24 logger.onRecord.listen((LogRecord rec) { |
| 25 print(rec.message); | 25 print(rec.message); |
| 26 }); | 26 }); |
| 27 PerfArgs args = parseArgs(rawArgs); | 27 PerfArgs args = parseArgs(rawArgs); |
| 28 | 28 |
| 29 Driver driver = new Driver( | 29 Driver driver = new Driver(diagnosticPort: args.diagnosticPort); |
| 30 diagnosticPort: args.diagnosticPort, newTaskModel: args.newTaskModel); | |
| 31 Stream<Operation> stream = openInput(args); | 30 Stream<Operation> stream = openInput(args); |
| 32 StreamSubscription<Operation> subscription; | 31 StreamSubscription<Operation> subscription; |
| 33 subscription = stream.listen((Operation op) { | 32 subscription = stream.listen((Operation op) { |
| 34 Future future = driver.perform(op); | 33 Future future = driver.perform(op); |
| 35 if (future != null) { | 34 if (future != null) { |
| 36 logger.log(Level.FINE, 'pausing operations for ${op.runtimeType}'); | 35 logger.log(Level.FINE, 'pausing operations for ${op.runtimeType}'); |
| 37 subscription.pause(future.then((_) { | 36 subscription.pause(future.then((_) { |
| 38 logger.log(Level.FINE, 'resuming operations'); | 37 logger.log(Level.FINE, 'resuming operations'); |
| 39 })); | 38 })); |
| 40 } | 39 } |
| 41 }, onDone: () { | 40 }, onDone: () { |
| 42 subscription.cancel(); | 41 subscription.cancel(); |
| 43 driver.stopServer(SHUTDOWN_TIMEOUT); | 42 driver.stopServer(SHUTDOWN_TIMEOUT); |
| 44 }, onError: (e, s) { | 43 }, onError: (e, s) { |
| 45 subscription.cancel(); | 44 subscription.cancel(); |
| 46 logger.log(Level.SEVERE, '$e\n$s'); | 45 logger.log(Level.SEVERE, '$e\n$s'); |
| 47 driver.stopServer(SHUTDOWN_TIMEOUT); | 46 driver.stopServer(SHUTDOWN_TIMEOUT); |
| 48 }); | 47 }); |
| 49 driver.runComplete.then((Results results) { | 48 driver.runComplete.then((Results results) { |
| 50 results.printResults(); | 49 results.printResults(); |
| 51 }).whenComplete(() { | 50 }).whenComplete(() { |
| 52 return subscription.cancel(); | 51 return subscription.cancel(); |
| 53 }); | 52 }); |
| 54 } | 53 } |
| 55 | 54 |
| 56 const DIAGNOSTIC_PORT_OPTION = 'diagnosticPort'; | 55 const DIAGNOSTIC_PORT_OPTION = 'diagnosticPort'; |
| 57 const HELP_CMDLINE_OPTION = 'help'; | 56 const HELP_CMDLINE_OPTION = 'help'; |
| 58 const INPUT_CMDLINE_OPTION = 'input'; | 57 const INPUT_CMDLINE_OPTION = 'input'; |
| 59 const MAP_OPTION = 'map'; | 58 const MAP_OPTION = 'map'; |
| 60 const NEW_TASK_MODEL_OPTION = 'newTaskModel'; | |
| 61 | 59 |
| 62 /** | 60 /** |
| 63 * The amount of time to give the server to respond to a shutdown request | 61 * The amount of time to give the server to respond to a shutdown request |
| 64 * before forcibly terminating it. | 62 * before forcibly terminating it. |
| 65 */ | 63 */ |
| 66 const Duration SHUTDOWN_TIMEOUT = const Duration(seconds: 25); | 64 const Duration SHUTDOWN_TIMEOUT = const Duration(seconds: 25); |
| 67 | 65 |
| 68 const TMP_SRC_DIR_OPTION = 'tmpSrcDir'; | 66 const TMP_SRC_DIR_OPTION = 'tmpSrcDir'; |
| 69 const VERBOSE_CMDLINE_OPTION = 'verbose'; | 67 const VERBOSE_CMDLINE_OPTION = 'verbose'; |
| 70 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; | 68 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 'This option defines a mapping from the original source directory <old
SrcPath>\n' | 85 'This option defines a mapping from the original source directory <old
SrcPath>\n' |
| 88 'when the instrumentation or log file was generated\n' | 86 'when the instrumentation or log file was generated\n' |
| 89 'to the target source directory <newSrcPath> used during performance t
esting.\n' | 87 'to the target source directory <newSrcPath> used during performance t
esting.\n' |
| 90 'Multiple mappings can be specified.\n' | 88 'Multiple mappings can be specified.\n' |
| 91 'WARNING: The contents of the target directory will be modified'); | 89 'WARNING: The contents of the target directory will be modified'); |
| 92 _argParser.addOption(TMP_SRC_DIR_OPTION, | 90 _argParser.addOption(TMP_SRC_DIR_OPTION, |
| 93 abbr: 't', | 91 abbr: 't', |
| 94 help: '<dirPath>\n' | 92 help: '<dirPath>\n' |
| 95 'The temporary directory containing source used during performance mea
surement.\n' | 93 'The temporary directory containing source used during performance mea
surement.\n' |
| 96 'WARNING: The contents of the target directory will be modified'); | 94 'WARNING: The contents of the target directory will be modified'); |
| 97 _argParser.addFlag(NEW_TASK_MODEL_OPTION, | |
| 98 help: "enable the use of the new task model", | |
| 99 defaultsTo: false, | |
| 100 negatable: false); | |
| 101 _argParser.addOption(DIAGNOSTIC_PORT_OPTION, | 95 _argParser.addOption(DIAGNOSTIC_PORT_OPTION, |
| 102 abbr: 'd', | 96 abbr: 'd', |
| 103 help: 'localhost port on which server will provide diagnostic web pages'); | 97 help: 'localhost port on which server will provide diagnostic web pages'); |
| 104 _argParser.addFlag(VERBOSE_CMDLINE_OPTION, | 98 _argParser.addFlag(VERBOSE_CMDLINE_OPTION, |
| 105 abbr: 'v', help: 'Verbose logging', negatable: false); | 99 abbr: 'v', help: 'Verbose logging', negatable: false); |
| 106 _argParser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, | 100 _argParser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, |
| 107 help: 'Extra verbose logging', negatable: false); | 101 help: 'Extra verbose logging', negatable: false); |
| 108 _argParser.addFlag(HELP_CMDLINE_OPTION, | 102 _argParser.addFlag(HELP_CMDLINE_OPTION, |
| 109 abbr: 'h', help: 'Print this help information', negatable: false); | 103 abbr: 'h', help: 'Print this help information', negatable: false); |
| 110 return _argParser; | 104 return _argParser; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 print('must specifiy $MAP_OPTION <oldSrcPath>,<newSrcPath>'); | 168 print('must specifiy $MAP_OPTION <oldSrcPath>,<newSrcPath>'); |
| 175 showHelp = true; | 169 showHelp = true; |
| 176 } | 170 } |
| 177 | 171 |
| 178 perfArgs.tmpSrcDirPath = _withTrailingSeparator(args[TMP_SRC_DIR_OPTION]); | 172 perfArgs.tmpSrcDirPath = _withTrailingSeparator(args[TMP_SRC_DIR_OPTION]); |
| 179 if (isMissing(TMP_SRC_DIR_OPTION)) { | 173 if (isMissing(TMP_SRC_DIR_OPTION)) { |
| 180 print('missing $TMP_SRC_DIR_OPTION argument'); | 174 print('missing $TMP_SRC_DIR_OPTION argument'); |
| 181 showHelp = true; | 175 showHelp = true; |
| 182 } | 176 } |
| 183 | 177 |
| 184 perfArgs.newTaskModel = args[NEW_TASK_MODEL_OPTION]; | |
| 185 | |
| 186 String portText = args[DIAGNOSTIC_PORT_OPTION]; | 178 String portText = args[DIAGNOSTIC_PORT_OPTION]; |
| 187 if (portText != null) { | 179 if (portText != null) { |
| 188 perfArgs.diagnosticPort = int.parse(portText, onError: (s) { | 180 perfArgs.diagnosticPort = int.parse(portText, onError: (s) { |
| 189 print('invalid $DIAGNOSTIC_PORT_OPTION: $s'); | 181 print('invalid $DIAGNOSTIC_PORT_OPTION: $s'); |
| 190 showHelp = true; | 182 showHelp = true; |
| 191 }); | 183 }); |
| 192 } | 184 } |
| 193 | 185 |
| 194 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { | 186 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { |
| 195 Logger.root.level = Level.FINE; | 187 Logger.root.level = Level.FINE; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 238 |
| 247 /** | 239 /** |
| 248 * The temporary directory containing source used during performance measureme
nt. | 240 * The temporary directory containing source used during performance measureme
nt. |
| 249 */ | 241 */ |
| 250 String tmpSrcDirPath; | 242 String tmpSrcDirPath; |
| 251 | 243 |
| 252 /** | 244 /** |
| 253 * The diagnostic port for Analysis Server or `null` if none. | 245 * The diagnostic port for Analysis Server or `null` if none. |
| 254 */ | 246 */ |
| 255 int diagnosticPort; | 247 int diagnosticPort; |
| 256 | |
| 257 /** | |
| 258 * `true` if the server should run using the new task model. | |
| 259 */ | |
| 260 bool newTaskModel; | |
| 261 } | 248 } |
| OLD | NEW |