| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 results.printResults(); | 54 results.printResults(); |
| 55 }).whenComplete(() { | 55 }).whenComplete(() { |
| 56 return subscription.cancel(); | 56 return subscription.cancel(); |
| 57 }); | 57 }); |
| 58 } | 58 } |
| 59 | 59 |
| 60 const HELP_CMDLINE_OPTION = 'help'; | 60 const HELP_CMDLINE_OPTION = 'help'; |
| 61 const INPUT_CMDLINE_OPTION = 'input'; | 61 const INPUT_CMDLINE_OPTION = 'input'; |
| 62 const MAP_FROM_OPTION = 'mapFrom'; | 62 const MAP_FROM_OPTION = 'mapFrom'; |
| 63 const MAP_TO_OPTION = 'mapTo'; | 63 const MAP_TO_OPTION = 'mapTo'; |
| 64 const TMP_SRC_DIR_OPTION = 'tmpSrcDir'; |
| 64 const VERBOSE_CMDLINE_OPTION = 'verbose'; | 65 const VERBOSE_CMDLINE_OPTION = 'verbose'; |
| 65 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; | 66 const VERY_VERBOSE_CMDLINE_OPTION = 'vv'; |
| 66 | 67 |
| 67 /** | 68 /** |
| 68 * Open and return the input stream specifying how this client | 69 * Open and return the input stream specifying how this client |
| 69 * should interact with the analysis server. | 70 * should interact with the analysis server. |
| 70 */ | 71 */ |
| 71 Stream<Operation> openInput(ArgResults args) { | 72 Stream<Operation> openInput(ArgResults args) { |
| 73 var logger = new Logger('openInput'); |
| 72 Stream<List<int>> inputRaw; | 74 Stream<List<int>> inputRaw; |
| 73 String inputPath = args[INPUT_CMDLINE_OPTION]; | 75 String inputPath = args[INPUT_CMDLINE_OPTION]; |
| 74 if (inputPath == null) { | 76 if (inputPath == null) { |
| 75 return null; | 77 return null; |
| 76 } | 78 } |
| 77 if (inputPath == 'stdin') { | 79 if (inputPath == 'stdin') { |
| 78 inputRaw = stdin; | 80 inputRaw = stdin; |
| 79 } else { | 81 } else { |
| 80 inputRaw = new File(inputPath).openRead(); | 82 inputRaw = new File(inputPath).openRead(); |
| 81 } | 83 } |
| 82 Map<String, String> srcPathMap = new Map<String, String>(); | 84 Map<String, String> srcPathMap = new Map<String, String>(); |
| 83 String mapFrom = args[MAP_FROM_OPTION]; | 85 String mapFrom = args[MAP_FROM_OPTION]; |
| 84 if (mapFrom != null && mapFrom.isNotEmpty) { | 86 if (mapFrom != null && mapFrom.isNotEmpty) { |
| 85 String mapTo = args[MAP_TO_OPTION]; | 87 String mapTo = args[MAP_TO_OPTION]; |
| 86 srcPathMap[mapFrom] = mapTo; | 88 srcPathMap[mapFrom] = mapTo; |
| 87 new Logger('openInput').log( | 89 logger.log( |
| 88 Level.INFO, 'mapping source paths\n from $mapFrom\n to $mapTo'); | 90 Level.INFO, 'mapping source paths\n from $mapFrom\n to $mapTo'); |
| 89 } | 91 } |
| 92 String tmpSrcDirPath = args[TMP_SRC_DIR_OPTION]; |
| 93 logger.log(Level.INFO, 'tmpSrcDir: $tmpSrcDirPath'); |
| 90 return inputRaw | 94 return inputRaw |
| 91 .transform(SYSTEM_ENCODING.decoder) | 95 .transform(SYSTEM_ENCODING.decoder) |
| 92 .transform(new LineSplitter()) | 96 .transform(new LineSplitter()) |
| 93 .transform(new InputConverter(srcPathMap)); | 97 .transform(new InputConverter(tmpSrcDirPath, srcPathMap)); |
| 94 } | 98 } |
| 95 | 99 |
| 96 /** | 100 /** |
| 97 * Parse the command line arguments. | 101 * Parse the command line arguments. |
| 98 */ | 102 */ |
| 99 ArgResults parseArgs(List<String> rawArgs) { | 103 ArgResults parseArgs(List<String> rawArgs) { |
| 100 ArgParser parser = new ArgParser(); | 104 ArgParser parser = new ArgParser(); |
| 101 | 105 |
| 102 parser.addOption(INPUT_CMDLINE_OPTION, | 106 parser.addOption(INPUT_CMDLINE_OPTION, abbr: 'i', help: '<filePath>\n' |
| 103 abbr: 'i', | 107 'The input file specifying how this client should interact with the server
.\n' |
| 104 help: 'The input file specifying how this client should interact ' | 108 'If the input file name is "stdin", then the instructions are read from st
andard input.'); |
| 105 'with the server. If the input file name is "stdin", ' | |
| 106 'then the instructions are read from standard input.'); | |
| 107 parser.addOption(MAP_FROM_OPTION, | 109 parser.addOption(MAP_FROM_OPTION, |
| 108 help: 'The original source directory when the instrumentation ' | 110 help: 'The original source directory when the instrumentation ' |
| 109 'or log file was generated.'); | 111 'or log file was generated.'); |
| 110 parser.addOption(MAP_TO_OPTION, | 112 parser.addOption(MAP_TO_OPTION, |
| 111 help: 'The target source directory used during performance testing. ' | 113 help: 'The target source directory used during performance testing. ' |
| 112 'WARNING: The contents of this directory will be modified'); | 114 'WARNING: The contents of this directory will be modified'); |
| 115 parser.addOption(TMP_SRC_DIR_OPTION, abbr: 't', help: '<dirPath>\n' |
| 116 'The temporary directory containing source used during performance measure
ment.\n' |
| 117 'WARNING: The contents of the target directory will be modified'); |
| 113 parser.addFlag(VERBOSE_CMDLINE_OPTION, | 118 parser.addFlag(VERBOSE_CMDLINE_OPTION, |
| 114 abbr: 'v', help: 'Verbose logging', negatable: false); | 119 abbr: 'v', help: 'Verbose logging', negatable: false); |
| 115 parser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, | 120 parser.addFlag(VERY_VERBOSE_CMDLINE_OPTION, |
| 116 help: 'Extra verbose logging', negatable: false); | 121 help: 'Extra verbose logging', negatable: false); |
| 117 parser.addFlag(HELP_CMDLINE_OPTION, | 122 parser.addFlag(HELP_CMDLINE_OPTION, |
| 118 abbr: 'h', help: 'Print this help information', negatable: false); | 123 abbr: 'h', help: 'Print this help information', negatable: false); |
| 119 | 124 |
| 120 ArgResults args; | 125 ArgResults args; |
| 121 try { | 126 try { |
| 122 args = parser.parse(rawArgs); | 127 args = parser.parse(rawArgs); |
| 123 } on Exception catch (e) { | 128 } on Exception catch (e) { |
| 124 print(e); | 129 print(e); |
| 125 printHelp(parser); | 130 printHelp(parser); |
| 126 exit(1); | 131 exit(1); |
| 127 } | 132 } |
| 128 | 133 |
| 129 bool showHelp = args[HELP_CMDLINE_OPTION] || args.rest.isNotEmpty; | 134 bool showHelp = args[HELP_CMDLINE_OPTION] || args.rest.isNotEmpty; |
| 130 | 135 |
| 131 bool isMissing(key) => args[key] == null || args[key].isEmpty; | 136 bool isMissing(key) => args[key] == null || args[key].isEmpty; |
| 132 | 137 |
| 133 if (isMissing(INPUT_CMDLINE_OPTION)) { | 138 if (isMissing(INPUT_CMDLINE_OPTION)) { |
| 134 print('missing "input" argument'); | 139 print('missing $INPUT_CMDLINE_OPTION argument'); |
| 135 showHelp = true; | 140 showHelp = true; |
| 136 } | 141 } |
| 137 | 142 |
| 138 if (isMissing(MAP_FROM_OPTION) != isMissing(MAP_TO_OPTION)) { | 143 if (isMissing(MAP_FROM_OPTION) != isMissing(MAP_TO_OPTION)) { |
| 139 print('must specifiy both $MAP_FROM_OPTION and $MAP_TO_OPTION'); | 144 print('must specifiy both $MAP_FROM_OPTION and $MAP_TO_OPTION'); |
| 140 showHelp = true; | 145 showHelp = true; |
| 141 } | 146 } |
| 142 | 147 |
| 148 if (isMissing(TMP_SRC_DIR_OPTION)) { |
| 149 print('missing $TMP_SRC_DIR_OPTION argument'); |
| 150 showHelp = true; |
| 151 } |
| 152 |
| 143 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { | 153 if (args[VERY_VERBOSE_CMDLINE_OPTION] || rawArgs.contains('-vv')) { |
| 144 Logger.root.level = Level.FINE; | 154 Logger.root.level = Level.FINE; |
| 145 } else if (args[VERBOSE_CMDLINE_OPTION]) { | 155 } else if (args[VERBOSE_CMDLINE_OPTION]) { |
| 146 Logger.root.level = Level.INFO; | 156 Logger.root.level = Level.INFO; |
| 147 } else { | 157 } else { |
| 148 Logger.root.level = Level.WARNING; | 158 Logger.root.level = Level.WARNING; |
| 149 } | 159 } |
| 150 | 160 |
| 151 if (showHelp) { | 161 if (showHelp) { |
| 152 printHelp(parser); | 162 printHelp(parser); |
| 153 exit(1); | 163 exit(1); |
| 154 } | 164 } |
| 155 | 165 |
| 156 return args; | 166 return args; |
| 157 } | 167 } |
| 158 | 168 |
| 159 void printHelp(ArgParser parser) { | 169 void printHelp(ArgParser parser) { |
| 160 print(''); | 170 print(''); |
| 161 print('Launch and interact with the AnalysisServer'); | 171 print('Launch and interact with the AnalysisServer'); |
| 172 print(''); |
| 162 print(parser.usage); | 173 print(parser.usage); |
| 163 } | 174 } |
| OLD | NEW |