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 uuid | 18 import uuid |
18 | 19 |
19 GCS_FOLDER = 'dart-crashes' | 20 GCS_FOLDER = 'dart-crashes' |
20 | 21 |
21 def CreateTarball(dir, tarname): | 22 def CreateTarball(dir, tarname): |
22 print 'Creating tar file: %s' % (tarname) | 23 print 'Creating tar file: %s' % (tarname) |
23 tar = tarfile.open(tarname, mode='w:gz') | 24 tar = tarfile.open(tarname, mode='w:gz') |
24 tar.add(dir) | 25 tar.add(dir) |
25 tar.close() | 26 tar.close() |
26 | 27 |
27 def CopyToGCS(filename): | 28 def CopyToGCS(filename): |
28 gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4()) | 29 gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4()) |
29 cmd = ['gsutil', 'cp', filename, gs_location] | 30 cmd = ['gsutil', 'cp', filename, gs_location] |
30 print 'Running command: %s' % (cmd) | 31 print 'Running command: %s' % (cmd) |
31 subprocess.check_call(cmd) | 32 subprocess.check_call(cmd) |
32 archived_filename = '%s%s' % (gs_location, filename.split('/').pop()) | 33 archived_filename = '%s%s' % (gs_location, filename.split('/').pop()) |
33 print 'Dump now available in %s' % (archived_filename) | 34 print 'Dump now available in %s' % (archived_filename) |
34 | 35 |
35 def Main(): | 36 def Main(): |
| 37 if utils.GuessOS() != 'linux': |
| 38 print 'Currently only archiving crash dumps on linux' |
| 39 return 0 |
36 print 'Looking for crash dumps' | 40 print 'Looking for crash dumps' |
37 num_dumps = 0 | 41 num_dumps = 0 |
38 for v in os.listdir('/tmp'): | 42 for v in os.listdir('/tmp'): |
39 if v.startswith('coredump'): | 43 if v.startswith('coredump'): |
40 fullpath = '/tmp/%s' % (v) | 44 fullpath = '/tmp/%s' % (v) |
41 if os.path.isdir(fullpath): | 45 if os.path.isdir(fullpath): |
42 num_dumps += 1 | 46 num_dumps += 1 |
43 tarname = '%s.tar.gz' % fullpath | 47 tarname = '%s.tar.gz' % fullpath |
44 CreateTarball(fullpath, tarname) | 48 CreateTarball(fullpath, tarname) |
45 CopyToGCS(tarname) | 49 CopyToGCS(tarname) |
46 os.unlink(tarname) | 50 os.unlink(tarname) |
47 shutil.rmtree(fullpath) | 51 shutil.rmtree(fullpath) |
48 print 'Found %s core dumps' % (num_dumps) | 52 print 'Found %s core dumps' % (num_dumps) |
49 | 53 |
50 if __name__ == '__main__': | 54 if __name__ == '__main__': |
51 sys.exit(Main()) | 55 sys.exit(Main()) |
OLD | NEW |