OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 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 |
| 5 # BSD-style license that can be found in the LICENSE file. |
| 6 # |
| 7 |
| 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 |
| 10 # After we copy out the core files we delete the dumps localy |
| 11 |
| 12 import os |
| 13 import shutil |
| 14 import sys |
| 15 import subprocess |
| 16 import tarfile |
| 17 import uuid |
| 18 |
| 19 GCS_FOLDER = 'dart-crashes' |
| 20 |
| 21 def CreateTarball(dir, tarname): |
| 22 print 'Creating tar file: %s' % (tarname) |
| 23 tar = tarfile.open(tarname, mode='w:gz') |
| 24 tar.add(dir) |
| 25 tar.close() |
| 26 |
| 27 def CopyToGCS(filename): |
| 28 gs_location = 'gs://%s/%s/' % (GCS_FOLDER, uuid.uuid4()) |
| 29 cmd = ['gsutil', 'cp', filename, gs_location] |
| 30 print 'Running command: %s' % (cmd) |
| 31 subprocess.check_call(cmd) |
| 32 archived_filename = '%s%s' % (gs_location, filename.split('/').pop()) |
| 33 print 'Dump now available in %s' % (archived_filename) |
| 34 |
| 35 def Main(): |
| 36 print 'Looking for crash dumps' |
| 37 num_dumps = 0 |
| 38 for v in os.listdir('/tmp'): |
| 39 if v.startswith('coredump'): |
| 40 fullpath = '/tmp/%s' % (v) |
| 41 if os.path.isdir(fullpath): |
| 42 num_dumps += 1 |
| 43 tarname = '%s.tar.gz' % fullpath |
| 44 CreateTarball(fullpath, tarname) |
| 45 CopyToGCS(tarname) |
| 46 os.unlink(tarname) |
| 47 shutil.rmtree(fullpath) |
| 48 print 'Found %s core dumps' % (num_dumps) |
| 49 |
| 50 if __name__ == '__main__': |
| 51 sys.exit(Main()) |
OLD | NEW |