| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:io'; | |
| 6 import 'package:path/path.dart'; | |
| 7 import 'main.dart' as performance; | |
| 8 | |
| 9 // Local driver for performance measurement | |
| 10 | |
| 11 main(List<String> args) { | |
| 12 /* | |
| 13 * Parse arguments | |
| 14 */ | |
| 15 if (args.length != 3) printHelp('Expected 3 arguments'); | |
| 16 var gitDir = new Directory(args[0]); | |
| 17 if (!gitDir.existsSync()) printHelp('${gitDir.path} does not exist'); | |
| 18 if (!new Directory(join(gitDir.path, '.git')).existsSync()) printHelp( | |
| 19 '${gitDir.path} does not appear to be a local git repository'); | |
| 20 var branch = args[1]; | |
| 21 var inputFile = new File(args[2]); | |
| 22 if (!inputFile.existsSync()) printHelp('${inputFile.path} does not exist'); | |
| 23 /* | |
| 24 * Create a new temp directory | |
| 25 */ | |
| 26 var tmpDir = new Directory( | |
| 27 join(Directory.systemTemp.path, 'analysis_server_perf_target')); | |
| 28 if (!tmpDir.path.contains('tmp')) throw 'invalid tmp directory\n $tmpDir'; | |
| 29 print('Extracting target analysis environment into\n ${tmpDir.path}'); | |
| 30 if (tmpDir.existsSync()) tmpDir.deleteSync(recursive: true); | |
| 31 tmpDir.createSync(recursive: true); | |
| 32 /* | |
| 33 * Setup the initial target source in the temp directory | |
| 34 */ | |
| 35 var tarFilePath = join(tmpDir.path, 'targetSrc.tar'); | |
| 36 var result = Process.runSync('git', ['archive', branch, '-o', tarFilePath], | |
| 37 workingDirectory: gitDir.path); | |
| 38 if (result.exitCode != 0) throw 'failed to obtain target source: $result'; | |
| 39 var tmpSrcDirPath = join(tmpDir.path, 'targetSrc'); | |
| 40 new Directory(tmpSrcDirPath).createSync(); | |
| 41 result = Process.runSync('tar', ['-xf', tarFilePath], | |
| 42 workingDirectory: tmpSrcDirPath); | |
| 43 if (result.exitCode != 0) throw 'failed to extract target source: $result'; | |
| 44 /* | |
| 45 * Symlink the out or xcodebuild directory | |
| 46 */ | |
| 47 var outDirName = 'out'; | |
| 48 if (!new Directory(join(gitDir.path, outDirName)).existsSync()) { | |
| 49 outDirName = 'xcodebuild'; | |
| 50 } | |
| 51 if (!new Directory(join(gitDir.path, outDirName)).existsSync()) { | |
| 52 throw 'failed to find out or xcodebuild directory'; | |
| 53 } | |
| 54 result = Process.runSync('ln', [ | |
| 55 '-s', | |
| 56 join(gitDir.path, outDirName), | |
| 57 join(tmpSrcDirPath, outDirName) | |
| 58 ]); | |
| 59 if (result.exitCode != 0) throw 'failed to link out or xcodebuild: $result'; | |
| 60 /* | |
| 61 * Launch the performance analysis tool | |
| 62 */ | |
| 63 performance.main([ | |
| 64 //'-vv', // very verbose | |
| 65 //'-d8081', // analysis server localhost diagnostic port | |
| 66 '-i${inputFile.path}', | |
| 67 '-t$tmpSrcDirPath', | |
| 68 '-m${gitDir.path},$tmpSrcDirPath', | |
| 69 ]); | |
| 70 } | |
| 71 | |
| 72 /// Print help and exit | |
| 73 void printHelp([String errMsg]) { | |
| 74 if (errMsg != null) { | |
| 75 print(''); | |
| 76 print('Error: $errMsg'); | |
| 77 print(''); | |
| 78 } | |
| 79 print('Arguments: <gitDir> <branch> <inputFile>'); | |
| 80 print('gitDir = git repository containing the initial target source'); | |
| 81 print('branch = the branch containing the initial target source'); | |
| 82 print('inputFile = the instrumentation or log file'); | |
| 83 exit(1); | |
| 84 } | |
| OLD | NEW |