OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 # | 6 # |
7 | 7 |
8 # A script that copies a core file and binary to GCS | 8 # A script that copies a core file and binary to GCS |
9 # We expect the dumps to be located in /tmp/coredump_PID directory | 9 # We expect the dumps to be located in /tmp/coredump_PID directory |
10 # After we copy out the core files we delete the dumps localy | 10 # After we copy out the core files we delete the dumps localy |
11 | 11 |
12 import os | 12 import os |
13 import shutil | 13 import shutil |
14 import sys | 14 import sys |
15 import subprocess | 15 import subprocess |
16 import tarfile | 16 import tarfile |
17 import utils | 17 import utils |
18 import uuid | 18 import uuid |
19 | 19 |
| 20 from glob import glob |
| 21 |
20 GCS_FOLDER = 'dart-temp-crash-archive' | 22 GCS_FOLDER = 'dart-temp-crash-archive' |
21 GSUTIL='/b/build/scripts/slave/gsutil' | 23 GSUTIL='/b/build/scripts/slave/gsutil' |
22 | 24 |
23 def CreateTarball(input_dir, tarname): | 25 def CreateTarball(input_dir, tarname): |
24 print 'Creating tar file: %s' % tarname | 26 print 'Creating tar file: %s' % tarname |
25 tar = tarfile.open(tarname, mode='w:gz') | 27 tar = tarfile.open(tarname, mode='w:gz') |
26 tar.add(input_dir) | 28 tar.add(input_dir) |
27 tar.close() | 29 tar.close() |
28 | 30 |
29 def CopyToGCS(filename): | 31 def CopyToGCS(filename): |
30 gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4()) | 32 gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4()) |
31 cmd = [GSUTIL, 'cp', filename, gs_location] | 33 cmd = [GSUTIL, 'cp', filename, gs_location] |
32 print 'Running command: %s' % cmd | 34 print 'Running command: %s' % cmd |
33 subprocess.check_call(cmd) | 35 subprocess.check_call(cmd) |
34 archived_filename = '%s%s' % (gs_location, filename.split('/').pop()) | 36 archived_filename = '%s%s' % (gs_location, filename.split('/').pop()) |
35 print 'Dump now available in %s' % archived_filename | 37 print 'Dump now available in %s' % archived_filename |
36 | 38 |
37 def TEMPArchiveBuild(): | 39 def TEMPArchiveBuild(): |
38 d = '/b/build/slave/vm-linux-debug-x64-asan-be/build/dart/out/DebugX64/dart' | 40 if not 'PWD' in os.environ: |
39 CopyToGCS(d) | 41 return |
| 42 pwd = os.environ['PWD'] |
| 43 print pwd |
| 44 if not 'vm-' in pwd: |
| 45 return |
| 46 if 'win' in pwd or 'release' in pwd: |
| 47 return |
| 48 files = glob('%s/out/Debug*/dart' % pwd) |
| 49 files.extend(glob('%s/xcodebuild/Debug*/dart' % pwd)) |
| 50 print('Archiving: %s' % files) |
| 51 for f in files: |
| 52 CopyToGCS(f) |
40 | 53 |
41 def Main(): | 54 def Main(): |
42 if 'PWD' in os.environ and 'x64-asan' in os.environ['PWD']: | 55 TEMPArchiveBuild() |
43 TEMPArchiveBuild() | |
44 if utils.GuessOS() != 'linux': | 56 if utils.GuessOS() != 'linux': |
45 print 'Currently only archiving crash dumps on linux' | 57 print 'Currently only archiving crash dumps on linux' |
46 return 0 | 58 return 0 |
47 print 'Looking for crash dumps' | 59 print 'Looking for crash dumps' |
48 num_dumps = 0 | 60 num_dumps = 0 |
49 for v in os.listdir('/tmp'): | 61 for v in os.listdir('/tmp'): |
50 if v.startswith('coredump'): | 62 if v.startswith('coredump'): |
51 fullpath = '/tmp/%s' % v | 63 fullpath = '/tmp/%s' % v |
52 if os.path.isdir(fullpath): | 64 if os.path.isdir(fullpath): |
53 num_dumps += 1 | 65 num_dumps += 1 |
54 tarname = '%s.tar.gz' % fullpath | 66 tarname = '%s.tar.gz' % fullpath |
55 CreateTarball(fullpath, tarname) | 67 CreateTarball(fullpath, tarname) |
56 CopyToGCS(tarname) | 68 CopyToGCS(tarname) |
57 os.unlink(tarname) | 69 os.unlink(tarname) |
58 shutil.rmtree(fullpath) | 70 shutil.rmtree(fullpath) |
59 print 'Found %s core dumps' % num_dumps | 71 print 'Found %s core dumps' % num_dumps |
60 | 72 |
61 if __name__ == '__main__': | 73 if __name__ == '__main__': |
62 sys.exit(Main()) | 74 sys.exit(Main()) |
OLD | NEW |