def load_basic_files(dump_path,
                      multiple,
                      no_dump=False,
                      alternative_dirs=None):
     prefix = SubCommand._find_prefix(dump_path)
     # If the target process is estimated to be working on Android, converts
     # a path in the Android device to a path estimated to be corresponding in
     # the host.  Use --alternative-dirs to specify the conversion manually.
     if not alternative_dirs:
         alternative_dirs = SubCommand._estimate_alternative_dirs(prefix)
     if alternative_dirs:
         for device, host in alternative_dirs.iteritems():
             LOGGER.info('Assuming %s on device as %s on host' %
                         (device, host))
     symbol_data_sources = SymbolDataSources(prefix, alternative_dirs)
     symbol_data_sources.prepare()
     bucket_set = BucketSet()
     bucket_set.load(prefix)
     if not no_dump:
         if multiple:
             dump_list = DumpList.load(
                 SubCommand._find_all_dumps(dump_path))
         else:
             dump = Dump.load(dump_path)
     symbol_mapping_cache = SymbolMappingCache()
     with open(prefix + '.cache.function', 'a+') as cache_f:
         symbol_mapping_cache.update(
             FUNCTION_SYMBOLS, bucket_set,
             SymbolFinder(FUNCTION_SYMBOLS, symbol_data_sources), cache_f)
     with open(prefix + '.cache.typeinfo', 'a+') as cache_f:
         symbol_mapping_cache.update(
             TYPEINFO_SYMBOLS, bucket_set,
             SymbolFinder(TYPEINFO_SYMBOLS, symbol_data_sources), cache_f)
     with open(prefix + '.cache.sourcefile', 'a+') as cache_f:
         symbol_mapping_cache.update(
             SOURCEFILE_SYMBOLS, bucket_set,
             SymbolFinder(SOURCEFILE_SYMBOLS, symbol_data_sources), cache_f)
     bucket_set.symbolize(symbol_mapping_cache)
     if no_dump:
         return bucket_set
     elif multiple:
         return (bucket_set, dump_list)
     else:
         return (bucket_set, dump)
Пример #2
0
    def do(self, sys_argv):
        options, args = self._parse_args(sys_argv, 2)
        dump_path = args[1]
        gs_path = args[2]

        dump_files = SubCommand._find_all_dumps(dump_path)
        bucket_files = SubCommand._find_all_buckets(dump_path)
        prefix = SubCommand._find_prefix(dump_path)
        symbol_data_sources = SymbolDataSources(prefix)
        symbol_data_sources.prepare()
        symbol_path = symbol_data_sources.path()

        handle_zip, filename_zip = tempfile.mkstemp('.zip', 'dmprof')
        os.close(handle_zip)

        try:
            file_zip = zipfile.ZipFile(filename_zip, 'w', zipfile.ZIP_DEFLATED)
            for filename in dump_files:
                file_zip.write(filename,
                               os.path.basename(os.path.abspath(filename)))
            for filename in bucket_files:
                file_zip.write(filename,
                               os.path.basename(os.path.abspath(filename)))

            symbol_basename = os.path.basename(os.path.abspath(symbol_path))
            for filename in os.listdir(symbol_path):
                if not filename.startswith('.'):
                    file_zip.write(
                        os.path.join(symbol_path, filename),
                        os.path.join(
                            symbol_basename,
                            os.path.basename(os.path.abspath(filename))))
            file_zip.close()

            returncode = UploadCommand._run_gsutil(options.gsutil, 'cp', '-a',
                                                   'public-read', filename_zip,
                                                   gs_path)
        finally:
            os.remove(filename_zip)

        return returncode