Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
utils.BaseCoreDumpArchiver Class Reference
Inheritance diagram for utils.BaseCoreDumpArchiver:
utils.PosixCoreDumpArchiver utils.WindowsCoreDumpArchiver utils.LinuxCoreDumpArchiver utils.MacOSCoreDumpArchiver

Public Member Functions

 __init__ (self, search_dir, output_directory)
 
 __enter__ (self)
 
 __exit__ (self, *_)
 

Protected Member Functions

 _safe_cleanup (self)
 
 _archive (self, crashes)
 
 _is_shard (self)
 
 _report_missing_crashes (self, missing, throw=False)
 
 _get_file_name (self, file)
 
 _move (self, files)
 
 _tar (self, file)
 
 _upload (self, files)
 
 _find_all_coredumps (self)
 
 _find_unexpected_crashes (self)
 
 _cleanup (self)
 

Protected Attributes

 _bucket
 
 _binaries_dir
 
 _search_dir
 
 _output_directory
 

Static Protected Attributes

str _UNEXPECTED_CRASHES_FILE = 'unexpected-crashes'
 

Detailed Description

This class reads coredumps file written by UnexpectedCrashDumpArchiver
into the current working directory and uploads all cores and binaries
listed in it into Cloud Storage (see
pkg/test_runner/lib/src/test_progress.dart).

Definition at line 610 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

utils.BaseCoreDumpArchiver.__init__ (   self,
  search_dir,
  output_directory 
)

Reimplemented in utils.LinuxCoreDumpArchiver, utils.MacOSCoreDumpArchiver, utils.WindowsCoreDumpArchiver, and utils.PosixCoreDumpArchiver.

Definition at line 620 of file utils.py.

620 def __init__(self, search_dir, output_directory):
621 self._bucket = 'dart-temp-crash-archive'
622 self._binaries_dir = os.getcwd()
623 self._search_dir = search_dir
624 self._output_directory = output_directory
625

Member Function Documentation

◆ __enter__()

utils.BaseCoreDumpArchiver.__enter__ (   self)

Definition at line 633 of file utils.py.

633 def __enter__(self):
634 print('INFO: Core dump archiving is activated')
635
636 # Cleanup any stale files
637 if self._safe_cleanup():
638 print('WARNING: Found and removed stale coredumps')
639
void print(void *str)
Definition bridge.cpp:126

◆ __exit__()

utils.BaseCoreDumpArchiver.__exit__ (   self,
_ 
)

Reimplemented in utils.WindowsCoreDumpArchiver.

Definition at line 640 of file utils.py.

640 def __exit__(self, *_):
641 try:
642 crashes = self._find_unexpected_crashes()
643 if crashes:
644 # If we get a ton of crashes, only archive 10 dumps.
645 archive_crashes = crashes[:10]
646 print('Archiving coredumps for crash (if possible):')
647 for crash in archive_crashes:
648 print('----> {}'.format(crash))
649
650 sys.stdout.flush()
651
652 self._archive(archive_crashes)
653 else:
654 print('INFO: No unexpected crashes recorded')
655 dumps = self._find_all_coredumps()
656 if dumps:
657 print('INFO: However there are {} core dumps found'.format(
658 len(dumps)))
659 for dump in dumps:
660 print('INFO: -> {}'.format(dump))
661 print()
662 except Exception as error:
663 print('ERROR: Failed to archive crashes: {}'.format(error))
664 raise
665
666 finally:
667 self._safe_cleanup()
668
uint32_t uint32_t * format

◆ _archive()

utils.BaseCoreDumpArchiver._archive (   self,
  crashes 
)
protected

Definition at line 669 of file utils.py.

669 def _archive(self, crashes):
670 files = set()
671 missing = []
672 for crash in crashes:
673 files.update(crash.binaries)
674 core = self._find_coredump_file(crash)
675 if core:
676 files.add(core)
677 else:
678 missing.append(crash)
679 if self._output_directory is not None and self._is_shard():
680 print(
681 "INFO: Moving collected dumps and binaries into output directory\n"
682 "INFO: They will be uploaded to isolate server. Look for \"isolated"
683 " out\" under the failed step on the build page.\n"
684 "INFO: For more information see runtime/docs/infra/coredumps.md"
685 )
686 self._move(files)
687 else:
688 print(
689 "INFO: Uploading collected dumps and binaries into Cloud Storage\n"
690 "INFO: Use `gsutil.py cp from-url to-path` to download them.\n"
691 "INFO: For more information see runtime/docs/infra/coredumps.md"
692 )
693 self._upload(files)
694
695 if missing:
696 self._report_missing_crashes(missing, throw=False)
697

◆ _cleanup()

utils.BaseCoreDumpArchiver._cleanup (   self)
protected

Reimplemented in utils.PosixCoreDumpArchiver, and utils.WindowsCoreDumpArchiver.

Definition at line 801 of file utils.py.

801 def _cleanup(self):
802 found = False
803 if os.path.exists(BaseCoreDumpArchiver._UNEXPECTED_CRASHES_FILE):
804 os.unlink(BaseCoreDumpArchiver._UNEXPECTED_CRASHES_FILE)
805 found = True
806 for binary in glob.glob(os.path.join(self._binaries_dir, 'binary.*')):
807 found = True
808 TryUnlink(binary)
809
810 return found
811
812

◆ _find_all_coredumps()

utils.BaseCoreDumpArchiver._find_all_coredumps (   self)
protected
Return coredumps that were recorded (if supported by the platform).
This method will be overridden by concrete platform specific implementations.

Reimplemented in utils.WindowsCoreDumpArchiver.

Definition at line 781 of file utils.py.

781 def _find_all_coredumps(self):
782 """Return coredumps that were recorded (if supported by the platform).
783 This method will be overridden by concrete platform specific implementations.
784 """
785 return []
786

◆ _find_unexpected_crashes()

utils.BaseCoreDumpArchiver._find_unexpected_crashes (   self)
protected
Load coredumps file. Each line has the following format:

test-name,pid,binary-file1,binary-file2,...

Definition at line 787 of file utils.py.

787 def _find_unexpected_crashes(self):
788 """Load coredumps file. Each line has the following format:
789
790 test-name,pid,binary-file1,binary-file2,...
791 """
792 try:
793 with open(BaseCoreDumpArchiver._UNEXPECTED_CRASHES_FILE) as f:
794 return [
795 UnexpectedCrash(*ln.strip('\n').split(','))
796 for ln in f.readlines()
797 ]
798 except:
799 return []
800

◆ _get_file_name()

utils.BaseCoreDumpArchiver._get_file_name (   self,
  file 
)
protected

Definition at line 717 of file utils.py.

717 def _get_file_name(self, file):
718 # Sanitize the name: actual cores follow 'core.%d' pattern, crashed
719 # binaries are copied next to cores and named
720 # 'binary.<mode>_<arch>_<binary_name>'.
721 # This should match the code in testing/dart/test_progress.dart
722 name = os.path.basename(file)
723 (prefix, suffix) = name.split('.', 1)
724 is_binary = prefix == 'binary'
725 if is_binary:
726 (mode, arch, binary_name) = suffix.split('_', 2)
727 name = binary_name
728 return (name, is_binary)
729

◆ _is_shard()

utils.BaseCoreDumpArchiver._is_shard (   self)
protected

Definition at line 699 of file utils.py.

699 def _is_shard(self):
700 return 'BUILDBOT_BUILDERNAME' not in os.environ
701

◆ _move()

utils.BaseCoreDumpArchiver._move (   self,
  files 
)
protected

Definition at line 730 of file utils.py.

730 def _move(self, files):
731 for file in files:
732 print('+++ Moving {} to output_directory ({})'.format(
733 file, self._output_directory))
734 (name, is_binary) = self._get_file_name(file)
735 destination = os.path.join(self._output_directory, name)
736 shutil.move(file, destination)
737 if is_binary and os.path.exists(file + '.pdb'):
738 # Also move a PDB file if there is one.
739 pdb = os.path.join(self._output_directory, name + '.pdb')
740 shutil.move(file + '.pdb', pdb)
741

◆ _report_missing_crashes()

utils.BaseCoreDumpArchiver._report_missing_crashes (   self,
  missing,
  throw = False 
)
protected

Reimplemented in utils.WindowsCoreDumpArchiver.

Definition at line 702 of file utils.py.

702 def _report_missing_crashes(self, missing, throw=False):
703 missing_as_string = ', '.join([str(c) for c in missing])
704 other_files = list(glob.glob(os.path.join(self._search_dir, '*')))
705 sys.stderr.write(
706 "Could not find crash dumps for '{}' in search directory '{}'.\n"
707 "Existing files which *did not* match the pattern inside the search "
708 "directory are are:\n {}\n".format(missing_as_string,
709 self._search_dir,
710 '\n '.join(other_files)))
711 # TODO: Figure out why windows coredump generation does not work.
712 # See http://dartbug.com/36469
713 if throw and GuessOS() != 'win32':
714 raise Exception(
715 'Missing crash dumps for: {}'.format(missing_as_string))
716

◆ _safe_cleanup()

utils.BaseCoreDumpArchiver._safe_cleanup (   self)
protected

Definition at line 626 of file utils.py.

626 def _safe_cleanup(self):
627 try:
628 return self._cleanup()
629 except Exception as error:
630 print('ERROR: Failure during cleanup: {}'.format(error))
631 return False
632

◆ _tar()

utils.BaseCoreDumpArchiver._tar (   self,
  file 
)
protected

Definition at line 742 of file utils.py.

742 def _tar(self, file):
743 (name, is_binary) = self._get_file_name(file)
744 tarname = '{}.tar.gz'.format(name)
745
746 # Compress the file.
747 tar = tarfile.open(tarname, mode='w:gz')
748 tar.add(file, arcname=name)
749 if is_binary and os.path.exists(file + '.pdb'):
750 # Also add a PDB file if there is one.
751 tar.add(file + '.pdb', arcname=name + '.pdb')
752 tar.close()
753 return tarname
754

◆ _upload()

utils.BaseCoreDumpArchiver._upload (   self,
  files 
)
protected

Definition at line 755 of file utils.py.

755 def _upload(self, files):
756 bot_utils = GetBotUtils()
757 gsutil = bot_utils.GSUtil()
758 storage_path = '{}/{}/'.format(self._bucket, uuid.uuid4())
759 gs_prefix = 'gs://{}'.format(storage_path)
760 http_prefix = 'https://storage.cloud.google.com/{}'.format(storage_path)
761
762 print('\n--- Uploading into {} ({}) ---'.format(gs_prefix, http_prefix))
763 for file in files:
764 tarname = self._tar(file)
765
766 # Remove / from absolute path to not have // in gs path.
767 gs_url = '{}{}'.format(gs_prefix, tarname)
768 http_url = '{}{}'.format(http_prefix, tarname)
769
770 try:
771 gsutil.upload(tarname, gs_url)
772 print('+++ Uploaded {} ({})'.format(gs_url, http_url))
773 except Exception as error:
774 print('!!! Failed to upload {}, error: {}'.format(
775 tarname, error))
776
777 TryUnlink(tarname)
778
779 print('--- Done ---\n')
780

Member Data Documentation

◆ _binaries_dir

utils.BaseCoreDumpArchiver._binaries_dir
protected

Definition at line 622 of file utils.py.

◆ _bucket

utils.BaseCoreDumpArchiver._bucket
protected

Definition at line 621 of file utils.py.

◆ _output_directory

utils.BaseCoreDumpArchiver._output_directory
protected

Definition at line 624 of file utils.py.

◆ _search_dir

utils.BaseCoreDumpArchiver._search_dir
protected

Definition at line 623 of file utils.py.

◆ _UNEXPECTED_CRASHES_FILE

str utils.BaseCoreDumpArchiver._UNEXPECTED_CRASHES_FILE = 'unexpected-crashes'
staticprotected

Definition at line 618 of file utils.py.


The documentation for this class was generated from the following file: