def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) procrank = open(os.path.join(out_dir, "b2g-procrank"), "r").read().split("\n") proc_names = {} for line in procrank: # App names may contain spaces and special characters (e.g. # '(Preallocated app)'). But for our purposes here, it's easier to # look at only the first word, and to strip off any special characters. # # We also assume that if an app name contains numbers, it contains them # only in the first word. match = re.match(r"^(\S+)\s+\D*(\d+)", line) if not match: continue proc_names[int(match.group(2))] = re.sub("\W", "", match.group(1)).lower() for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) from the name # of the dmd file (e.g. dmd-9999999-111.txt.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r"^dmd-(\d+)-(\d+).", basename) if dmd_filename_match: creation_time = datetime.fromtimestamp(int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) if pid in proc_names: proc_name = proc_names[pid] outfile_name = "dmd-%s-%d.txt.gz" % (proc_name, pid) else: proc_name = None outfile_name = "dmd-%d.txt.gz" % pid else: pid = None creation_time = None outfile_name = "processed-" + basename outfile = GzipFile(os.path.join(out_dir, outfile_name), "w") def write(str): print(str, file=outfile) write("# Processed DMD output") if creation_time: write("# Created on %s, device time (may be unreliable)." % creation_time.strftime("%c")) write("# Processed on %s, host machine time." % datetime.now().strftime("%c")) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write("# Corresponds to unknown app, pid %d" % pid) else: write("# Corresponds to unknown app, unknown pid.") write("#\n# Contents of b2g-procrank:\n#") for line in procrank: write("# " + line.strip()) write("\n") fix_b2g_stack.fix_b2g_stacks_in_file(GzipFile(f, "r"), outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) proc_names, procrank = get_proc_names(out_dir) get_objdir_and_product(args) for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) and the file # kind ('txt' or 'json', depending on the version) from the name # of the dmd file (e.g. dmd-9999999-111.json.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).(txt|json)', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp( int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) kind = dmd_filename_match.group(3) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.%s' % (proc_name, pid, kind) else: proc_name = None outfile_name = 'dmd-%d.%s' % (pid, kind) else: pid = None creation_time = None outfile_name = 'processed-' + basename if outfile_name.endswith(".gz"): outfile_name = outfile_name[:-3] outfile_path = os.path.join(out_dir, outfile_name) with GzipFile(outfile_path + '.gz', 'w') if args.compress_dmd_logs else \ open(outfile_path, 'w') as outfile: def write(s): print(s, file=outfile) write('# Processed DMD output') if creation_time: write('# Created on %s, device time (may be unreliable).' % creation_time.strftime('%c')) write('# Processed on %s, host machine time.' % datetime.now().strftime('%c')) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write('# Corresponds to unknown app, pid %d' % pid) else: write('# Corresponds to unknown app, unknown pid.') write('#\n# Contents of b2g-procrank:\n#') for line in procrank: write('# ' + line.strip()) write('\n') with GzipFile(f, 'r') as infile: fix_b2g_stack.fix_b2g_stacks_in_file(infile, outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) proc_names, procrank = get_proc_names(out_dir) get_objdir_and_product(args) for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) and the file # kind ('txt' or 'json', depending on the version) from the name # of the dmd file (e.g. dmd-9999999-111.json.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).(txt|json)', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp(int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) kind = dmd_filename_match.group(3) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.%s' % (proc_name, pid, kind) else: proc_name = None outfile_name = 'dmd-%d.%s' % (pid, kind) else: pid = None creation_time = None outfile_name = 'processed-' + basename if outfile_name.endswith(".gz"): outfile_name = outfile_name[:-3] outfile_path = os.path.join(out_dir, outfile_name) with GzipFile(outfile_path + '.gz', 'w') if args.compress_dmd_logs else \ open(outfile_path, 'w') as outfile: def write(s): print(s, file=outfile) write('# Processed DMD output') if creation_time: write('# Created on %s, device time (may be unreliable).' % creation_time.strftime('%c')) write('# Processed on %s, host machine time.' % datetime.now().strftime('%c')) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write('# Corresponds to unknown app, pid %d' % pid) else: write('# Corresponds to unknown app, unknown pid.') write('#\n# Contents of b2g-procrank:\n#') for line in procrank: write('# ' + line.strip()) write('\n') with GzipFile(f, 'r') as infile: fix_b2g_stack.fix_b2g_stacks_in_file(infile, outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) proc_names, procrank = get_proc_names(out_dir) for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) from the name # of the dmd file (e.g. dmd-9999999-111.txt.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp( int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.txt.gz' % (proc_name, pid) else: proc_name = None outfile_name = 'dmd-%d.txt.gz' % pid else: pid = None creation_time = None outfile_name = 'processed-' + basename outfile = GzipFile(os.path.join(out_dir, outfile_name), 'w') def write(str): print(str, file=outfile) write('# Processed DMD output') if creation_time: write('# Created on %s, device time (may be unreliable).' % creation_time.strftime('%c')) write('# Processed on %s, host machine time.' % datetime.now().strftime('%c')) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write('# Corresponds to unknown app, pid %d' % pid) else: write('# Corresponds to unknown app, unknown pid.') write('#\n# Contents of b2g-procrank:\n#') for line in procrank: write('# ' + line.strip()) write('\n') fix_b2g_stack.fix_b2g_stacks_in_file(GzipFile(f, 'r'), outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) proc_names, procrank = get_proc_names(out_dir) for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) from the name # of the dmd file (e.g. dmd-9999999-111.txt.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp(int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.txt.gz' % (proc_name, pid) else: proc_name = None outfile_name = 'dmd-%d.txt.gz' % pid else: pid = None creation_time = None outfile_name = 'processed-' + basename outfile = GzipFile(os.path.join(out_dir, outfile_name), 'w') def write(s): print(s, file=outfile) write('# Processed DMD output') if creation_time: write('# Created on %s, device time (may be unreliable).' % creation_time.strftime('%c')) write('# Processed on %s, host machine time.' % datetime.now().strftime('%c')) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write('# Corresponds to unknown app, pid %d' % pid) else: write('# Corresponds to unknown app, unknown pid.') write('#\n# Contents of b2g-procrank:\n#') for line in procrank: write('# ' + line.strip()) write('\n') fix_b2g_stack.fix_b2g_stacks_in_file(GzipFile(f, 'r'), outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) proc_names, procrank = get_proc_names(out_dir) get_objdir_and_product(args) for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) and the file # kind ('txt' or 'json', depending on the version) from the name # of the dmd file (e.g. dmd-9999999-111.json.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).(txt|json)', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp(int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) kind = dmd_filename_match.group(3) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.%s' % (proc_name, pid, kind) else: proc_name = None outfile_name = 'dmd-%d.%s' % (pid, kind) else: pid = None creation_time = None outfile_name = 'processed-' + basename if outfile_name.endswith(".gz"): outfile_name = outfile_name[:-3] outfile_path = os.path.join(out_dir, outfile_name) with GzipFile(outfile_path + '.gz', 'w') if args.compress_dmd_logs else \ open(outfile_path, 'w') as outfile: with GzipFile(f, 'r') as infile: fix_b2g_stack.fix_b2g_stacks_in_file(infile, outfile, args) if not args.keep_individual_reports: os.remove(f)
def process_dmd_files_impl(dmd_files, args): out_dir = os.path.dirname(dmd_files[0]) procrank = open(os.path.join(out_dir, 'b2g-procrank'), 'r').read().split('\n') proc_names = {} for line in procrank: # App names may contain spaces and special characters (e.g. # '(Preallocated app)'). But for our purposes here, it's easier to # look at only the first word, and to strip off any special characters. # # We also assume that if an app name contains numbers, it contains them # only in the first word. match = re.match(r'^(\S+)\s+\D*(\d+)', line) if not match: continue proc_names[int(match.group(2))] = re.sub('\W', '', match.group(1)).lower() for f in dmd_files: # Extract the PID (e.g. 111) and UNIX time (e.g. 9999999) from the name # of the dmd file (e.g. dmd-9999999-111.txt.gz). basename = os.path.basename(f) dmd_filename_match = re.match(r'^dmd-(\d+)-(\d+).', basename) if dmd_filename_match: creation_time = datetime.fromtimestamp( int(dmd_filename_match.group(1))) pid = int(dmd_filename_match.group(2)) if pid in proc_names: proc_name = proc_names[pid] outfile_name = 'dmd-%s-%d.txt.gz' % (proc_name, pid) else: proc_name = None outfile_name = 'dmd-%d.txt.gz' % pid else: pid = None creation_time = None outfile_name = 'processed-' + basename outfile = GzipFile(os.path.join(out_dir, outfile_name), 'w') def write(str): print(str, file=outfile) write('# Processed DMD output') if creation_time: write('# Created on %s, device time (may be unreliable).' % creation_time.strftime('%c')) write('# Processed on %s, host machine time.' % datetime.now().strftime('%c')) if proc_name: write('# Corresponds to "%s" app, pid %d' % (proc_name, pid)) elif pid: write('# Corresponds to unknown app, pid %d' % pid) else: write('# Corresponds to unknown app, unknown pid.') write('#\n# Contents of b2g-procrank:\n#') for line in procrank: write('# ' + line.strip()) write('\n') fix_b2g_stack.fix_b2g_stacks_in_file(GzipFile(f, 'r'), outfile, args) if not args.keep_individual_reports: os.remove(f)