| OLD | NEW |
| (Empty) | |
| 1 library server.performance; |
| 2 |
| 3 import 'dart:async'; |
| 4 import 'dart:convert'; |
| 5 import 'dart:io'; |
| 6 |
| 7 import 'package:args/args.dart'; |
| 8 import 'package:logging/logging.dart'; |
| 9 |
| 10 import 'driver.dart'; |
| 11 import 'input_converter.dart'; |
| 12 import 'operation.dart'; |
| 13 |
| 14 /** |
| 15 * Launch and interact with the analysis server. |
| 16 */ |
| 17 main(List<String> rawArgs) { |
| 18 Logger logger = new Logger('Performance Measurement Client'); |
| 19 logger.onRecord.listen((LogRecord rec) { |
| 20 print(rec.message); |
| 21 }); |
| 22 Driver driver = new Driver(logger); |
| 23 |
| 24 ArgResults args = parseArgs(rawArgs); |
| 25 Stream<Operation> stream = openInput(args); |
| 26 StreamSubscription<Operation> subscription; |
| 27 subscription = stream.listen((Operation op) { |
| 28 Future future = driver.perform(op); |
| 29 if (future != null) { |
| 30 logger.log(Level.FINE, 'pausing operations for ${op.runtimeType}'); |
| 31 subscription.pause(future.then((_) { |
| 32 logger.log(Level.FINE, 'resuming operations'); |
| 33 })); |
| 34 } |
| 35 }, onDone: () { |
| 36 subscription.cancel(); |
| 37 driver.stopServer(); |
| 38 }, onError: (e, s) { |
| 39 subscription.cancel(); |
| 40 logger.log(Level.WARNING, '$e\n$s'); |
| 41 driver.stopServer(); |
| 42 throw e; |
| 43 }); |
| 44 driver.runComplete.then((Results results) { |
| 45 results.printResults(); |
| 46 }).whenComplete(() { |
| 47 return subscription.cancel(); |
| 48 }); |
| 49 } |
| 50 |
| 51 const HELP_CMDLINE_OPTION = 'help'; |
| 52 const INPUT_CMDLINE_OPTION = 'input'; |
| 53 const VERBOSE_CMDLINE_OPTION = 'verbose'; |
| 54 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; |
| 55 |
| 56 /** |
| 57 * Open and return the input stream specifying how this client |
| 58 * should interact with the analysis server. |
| 59 */ |
| 60 Stream<Operation> openInput(ArgResults args) { |
| 61 Stream<List<int>> inputRaw; |
| 62 String inputPath = args[INPUT_CMDLINE_OPTION]; |
| 63 if (inputPath == null) { |
| 64 return null; |
| 65 } |
| 66 if (inputPath == 'stdin') { |
| 67 inputRaw = stdin; |
| 68 } else { |
| 69 inputRaw = new File(inputPath).openRead(); |
| 70 } |
| 71 return inputRaw |
| 72 .transform(SYSTEM_ENCODING.decoder) |
| 73 .transform(new LineSplitter()) |
| 74 .transform(new InputConverter()); |
| 75 } |
| 76 |
| 77 /** |
| 78 * Parse the command line arguments. |
| 79 */ |
| 80 ArgResults parseArgs(List<String> rawArgs) { |
| 81 ArgParser parser = new ArgParser(); |
| 82 |
| 83 parser.addOption(INPUT_CMDLINE_OPTION, |
| 84 abbr: 'i', |
| 85 help: 'The input file specifying how this client should interact ' |
| 86 'with the server. If the input file name is "stdin", ' |
| 87 'then the instructions are read from standard input.'); |
| 88 parser.addFlag(VERBOSE_CMDLINE_OPTION, |
| 89 abbr: 'v', help: 'Verbose logging', negatable: false); |
| 90 parser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, |
| 91 help: 'Extra verbose logging', negatable: false); |
| 92 parser.addFlag(HELP_CMDLINE_OPTION, |
| 93 abbr: 'h', help: 'Print this help information', negatable: false); |
| 94 |
| 95 ArgResults args = parser.parse(rawArgs); |
| 96 bool showHelp = args[HELP_CMDLINE_OPTION] || args.rest.isNotEmpty; |
| 97 |
| 98 if (args[INPUT_CMDLINE_OPTION] == null || |
| 99 args[INPUT_CMDLINE_OPTION].isEmpty) { |
| 100 print('missing "input" argument'); |
| 101 showHelp = true; |
| 102 } |
| 103 |
| 104 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { |
| 105 Logger.root.level = Level.FINE; |
| 106 } else if (args[VERBOSE_CMDLINE_OPTION]) { |
| 107 Logger.root.level = Level.INFO; |
| 108 } else { |
| 109 Logger.root.level = Level.WARNING; |
| 110 } |
| 111 |
| 112 if (showHelp) { |
| 113 print(''); |
| 114 print('Launch and interact with the AnalysisServer'); |
| 115 print(parser.usage); |
| 116 exit(1); |
| 117 } |
| 118 |
| 119 return args; |
| 120 } |
| OLD | NEW |