def setup(self): if self.names is None: self.names = [] self.add_all = 'all' in self.names self.enabled = True log_prof.debug("libs: names=%s, all=%s, add_calls=%s", self.names, self.add_all, self.add_calls)
def _save_data(self): log_prof.debug("saving profile data to '%s'", self.file) df = ProfDataFile() # run through profilers and get data for name in self.profilers: prof = self.profilers[name] data = prof.get_data() if data: df.set_prof_data(name, data) df.save_json_file(self.file) log_prof.debug("done saving.")
def _try_load_data(self): if os.path.exists(self.file): log_prof.debug("loading profile data from '%s'", self.file) df = ProfDataFile() df.load_json_file(self.file) # run through profilers and set data for name in self.profilers: prof = self.profilers[name] data = df.get_prof_data(name) if data: prof.set_data(ConfigDict(data)) log_prof.debug("done loading.")
def add_profiler(self, prof): """add profiler and return if it was activated""" # a profile is always disabled if profiling itself is disabled if not self.enabled: return False # get and check name for duplicates name = prof.get_name() if name in self.profilers: raise ValueError("profiler '%s' already exists!" % name) # setup config of profiler (if any) if self.cfg and name in self.cfg: sub_cfg = self.cfg[name] if not prof.parse_config(sub_cfg): log_prof.warning("skipped profiler '%s'", name) return False log_prof.debug("added profiler '%s'", name) self.profilers[name] = prof return True
def add_profiler(self, prof): """add profiler and return if it was activated""" # a profile is always disabled if profiling itself is disabled if not self.enabled: return False # get and check name for duplicates name = prof.get_name() if name in self.profilers: raise ValueError("profiler '%s' already exists!" % name) # setup config of profiler (if any) if self.cfg and name in self.cfg: sub_cfg = self.cfg[name] if not prof.parse_config(sub_cfg): log_prof.warn("skipped profiler '%s'", name) return False log_prof.debug("added profiler '%s'", name) self.profilers[name] = prof return True
def create_profile(self, lib_name, fd, func_tags=None): """get or create a new profile for a library""" # profiling disabled if not self.enabled: log_prof.debug("libs: create '%s' -> disabled", lib_name) return None # already created profile if lib_name in self.lib_profiles: log_prof.debug("libs: create '%s' -> reuse", lib_name) prof = self.lib_profiles[lib_name] prof.setup_func_table(fd, func_tags) return prof elif self.add_all or lib_name in self.names: # shall we create a profile for this lib? log_prof.debug("libs: create '%s' -> NEW", lib_name) prof = LibProfileData(fd, self.add_calls) self.lib_profiles[lib_name] = prof return prof else: log_prof.debug("libs: create '%s' -> not found", lib_name)