def gen(self): self.profile = profile_pb2.Profile() self.profile.string_table.append('') self.string_table = {} self.sample_types = {} self.sample_map = {} self.sample_list = [] self.location_map = {} self.location_list = [] self.mapping_map = {} self.mapping_list = [] self.function_map = {} self.function_list = [] # 1. Process all samples in perf.data, aggregate samples. while True: report_sample = self.lib.GetNextSample() if report_sample is None: self.lib.Close() break event = self.lib.GetEventOfCurrentSample() symbol = self.lib.GetSymbolOfCurrentSample() callchain = self.lib.GetCallChainOfCurrentSample() if not self._filter_report_sample(report_sample): continue sample_type_id = self.get_sample_type_id(event.name) sample = Sample() sample.add_value(sample_type_id, 1) sample.add_value(sample_type_id + 1, report_sample.period) if self._filter_symbol(symbol): location_id = self.get_location_id(symbol.vaddr_in_file, symbol) sample.add_location_id(location_id) for i in range(callchain.nr): entry = callchain.entries[i] if self._filter_symbol(symbol): location_id = self.get_location_id(entry.ip, entry.symbol) sample.add_location_id(location_id) if sample.location_ids: self.add_sample(sample) # 2. Generate line info for locations and functions. if self.config.get('binary_cache_dir'): self.gen_source_lines() # 3. Produce samples/locations/functions in profile for sample in self.sample_list: self.gen_profile_sample(sample) for mapping in self.mapping_list: self.gen_profile_mapping(mapping) for location in self.location_list: self.gen_profile_location(location) for function in self.function_list: self.gen_profile_function(function) return self.profile
def init_profile(profile_time, profile_period): ''' Creats profiles, fills in time, period, period type and string table default lines. ''' global string_table if string_table: raise Exception("Cannot process two profiles at the same time") profile = pb_profile.Profile() profile.TimeNanos = profile_time profile.Period = profile_period for item in ["", "tid", "timestamp"]: string_table[item] = len(string_table) add_period_type(profile) return profile
def __init__(self, config): self.config = config self.lib = ReportLib() config['binary_cache_dir'] = 'binary_cache' if not os.path.isdir(config['binary_cache_dir']): config['binary_cache_dir'] = None else: self.lib.SetSymfs(config['binary_cache_dir']) if config.get('perf_data_path'): self.lib.SetRecordFile(config['perf_data_path']) kallsyms = 'binary_cache/kallsyms' if os.path.isfile(kallsyms): self.lib.SetKallsymsFile(kallsyms) if config.get('show_art_frames'): self.lib.ShowArtFrames() self.comm_filter = set( config['comm_filters']) if config.get('comm_filters') else None if config.get('pid_filters'): self.pid_filter = {int(x) for x in config['pid_filters']} else: self.pid_filter = None if config.get('tid_filters'): self.tid_filter = {int(x) for x in config['tid_filters']} else: self.tid_filter = None self.dso_filter = set( config['dso_filters']) if config.get('dso_filters') else None self.max_chain_length = config['max_chain_length'] self.profile = profile_pb2.Profile() self.profile.string_table.append('') self.string_table = {} self.sample_types = {} self.sample_map = {} self.sample_list = [] self.location_map = {} self.location_list = [] self.mapping_map = {} self.mapping_list = [] self.function_map = {} self.function_list = [] # Map from dso_name in perf.data to (binary path, build_id). self.binary_map = {} self.read_elf = ReadElf(self.config['ndk_path'])
def __init__(self, config): self.config = config self.lib = ReportLib() config['binary_cache_dir'] = 'binary_cache' if not os.path.isdir(config['binary_cache_dir']): config['binary_cache_dir'] = None else: self.lib.SetSymfs(config['binary_cache_dir']) if config.get('perf_data_path'): self.lib.SetRecordFile(config['perf_data_path']) kallsyms = 'binary_cache/kallsyms' if os.path.isfile(kallsyms): self.lib.SetKallsymsFile(kallsyms) self.comm_filter = set(config['comm_filters']) if config.get('comm_filters') else None if config.get('pid_filters'): self.pid_filter = {int(x) for x in config['pid_filters']} else: self.pid_filter = None if config.get('tid_filters'): self.tid_filter = {int(x) for x in config['tid_filters']} else: self.tid_filter = None self.dso_filter = set(config['dso_filters']) if config.get('dso_filters') else None self.profile = profile_pb2.Profile() self.profile.string_table.append('') self.string_table = {} self.sample_types = {} self.sample_map = {} self.sample_list = [] self.location_map = {} self.location_list = [] self.mapping_map = {} self.mapping_list = [] self.function_map = {} self.function_list = []
def __init__(self, config): self.config = config self.lib = None config['binary_cache_dir'] = 'binary_cache' if not os.path.isdir(config['binary_cache_dir']): config['binary_cache_dir'] = None self.comm_filter = set( config['comm_filters']) if config.get('comm_filters') else None if config.get('pid_filters'): self.pid_filter = {int(x) for x in config['pid_filters']} else: self.pid_filter = None if config.get('tid_filters'): self.tid_filter = {int(x) for x in config['tid_filters']} else: self.tid_filter = None self.dso_filter = set( config['dso_filters']) if config.get('dso_filters') else None self.max_chain_length = config['max_chain_length'] self.profile = profile_pb2.Profile() self.profile.string_table.append('') self.string_table = {} self.sample_types = {} self.sample_map = {} self.sample_list = [] self.location_map = {} self.location_list = [] self.mapping_map = {} self.mapping_list = [] self.function_map = {} self.function_list = [] # Map from dso_name in perf.data to (binary path, build_id). self.binary_map = {} self.read_elf = ReadElf(self.config['ndk_path'])
from google.protobuf import text_format from pathlib import Path import profile_pb2 out_path = Path('../profiles') in_files = Path('text_profiles').rglob('*.textpb') for f_in_name in in_files: f_in = open(f_in_name, 'rb') buf = f_in.read() f_in.close() profile = profile_pb2.Profile() text_format.Parse(buf, profile) f_out_name = out_path.joinpath(f_in_name.stem) f_out = open(f_out_name, 'wb') f_out.write(profile.SerializeToString()) f_out.close()
def load_pprof_profile(filename): profile = profile_pb2.Profile() with open(filename, "rb") as f: profile.ParseFromString(f.read()) return profile