Profiler¶
Module for profiling executables within a project.
- class Profiler(project: Project, build: Build, ui: IUI = NullUI())¶
Bases:
objectClass for profiling a build within a project.
- class CustomLogger(logger, extra=None, merge_extra=False)¶
Bases:
LoggerAdapterCustom logger to add build and executable prefixes to log messages.
- process(msg, kwargs)¶
Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.
Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.
- cleanup()¶
Cleanup generated files from profiling.
- profile_all(working_directory: str = '', test_executable: bool = True, execution_time: bool = True, stat_collect: bool = True, record_collect: bool = True, max_number_of_executables=1, events: list[str] | None = None) list[str]¶
Run profiling on every executable.
If build.executables is empty, finds executables in build.build_path.
- Parameters:
working_directory (str) – absolute path to set working directory.
test_executable (bool) – Run an executable smoke test if True. Saves result in self.stats[EXECUTABLE][Stats.EXECUTABLE_RUN_SUCCESS].
execution_time (bool) – run an executable time measurement if True. Saves result in self.stats[EXECUTABLE] dictionary with keys Stats.REAL_TIME, Stats.USER_TIME, Stats.KERNEL_TIME.
stat_collect (bool) – collect perfomance counters if True. Saves result in self.stats[EXECUTABLE][Stats.PERF_STAT].
record_collect (bool) – collect counters using sampling if True. Saves perf.data into self.get_record_filename() file in the working directory.
- Returns:
List of executables for which all profiler steps were completed successfully.
- Return type:
- execution_time(executable: str, working_directory: str) bool¶
Measure execution time: real, user, kernel
- test_executable(executable: str, working_directory: str) bool¶
Checks if executable runs and returns no errors.
Updates self.stats[EXECUTABLE] dictionary with Stats.EXECUTABLE_RUN_SUCCESS key
- perf_stat_collect(executable: str, working_directory: str, options: str = '-ddd') bool¶
Collect performance statistics using perf stat.
Updates self.stats[EXECUTABLE] dictionary with Stats.PERF_STAT key
- perf_record_collect(executable: str, working_directory: str, options: str = '-g -F 1000', events: list[str] | None = None) bool¶
Collect performance records using perf record.
Saves perf.data with archive of object files into self.get_record_filename() and self.get_record_filename().tar.bz2 file in the working directory.
- Parameters:
- Returns:
False if can’t collect samples. Otherwise True
- Return type:
- perf_script(filename: str, working_directory: str) tuple[bool, str]¶
Runs perf script on the provided perf data file and saves to filename.txt
- Parameters:
- Return type:
Should contain perf record file. :type working_directory: str
- save_stats()¶
Save collected statistics to a file. Merges with previous build statistics.
Structure: {“build1”:{“executable1”: ProfileStats, “executable2”: …}, “build2”: …}