cProfile Integration
cProfile integration for QGIS profiling.
Contains QCProfiler, a cProfile.Profile subclass that can merge
QgsRuntimeProfiler data with standard cProfile statistics, and ProfilerEntry,
a dataclass for representing individual profiling entries.
- class qgis_profiler.cprofiler.ProfilerEntry(code, callcount=1, inlinetime=0.0, reccallcount=0, totaltime=0.0, calls=<factory>)[source]
Bases:
objectClass representing a single profiling entry.
Inspired by _lsprof.profiler_entry and _lsprof.profiler_subentry but made more flexible and easier to work with.
- Parameters:
code (str)
callcount (int)
inlinetime (float)
reccallcount (int)
totaltime (float)
calls (list[ProfilerEntry])
- code: str
- callcount: int = 1
- inlinetime: float = 0.0
- reccallcount: int = 0
- totaltime: float = 0.0
- calls: list[ProfilerEntry]
- static from_cprofiler(cprofiler)[source]
Turn cProfile.Profile stats into a list of ProfilerEntry objects.
- Parameters:
cprofiler (Profile)
- Return type:
list[ProfilerEntry]
- static from_stat(stat)[source]
Convert a profiler_entry stat into a ProfilerEntry.
- Parameters:
stat (profiler_entry)
- Return type:
- static parse_from_qgis_profiler_text(text)[source]
Parse a given profiler text into a list of ProfilerEntry objects.
Process hierarchical structure based on indentation and generate profiling entries.
- Parameters:
text (str)
- Return type:
list[ProfilerEntry]
- class qgis_profiler.cprofiler.QCProfiler[source]
Bases:
ProfileExtend cProfile.Profile with QGIS-specific functionality and extra utilities.
- qgis_profiler_data(profiler_text)[source]
Temporarily set QGIS profiler stats from the given text.
- Parameters:
profiler_text (str)
- Return type:
Generator[None, Any, None]
- enable(subcalls=True, builtins=True)[source]
Enable profiling.
- Parameters:
subcalls (bool)
builtins (bool)
- Return type:
None
- getstats()[source]
Return QGIS stats if available, otherwise standard cProfile stats.
- Return type:
Sequence[ProfilerEntry | profiler_entry]
- get_stat_report(sort=-1, max_line_count=1000, trim_zeros=False)[source]
Get the profile report as a string.
- Parameters:
sort (str | tuple[str, ...] | int) – Sort method. Can be a string or a tuple of strings.
max_line_count (int) – Maximum number of lines to return.
trim_zeros (bool) – Trim lines with zero times from the report.
- Returns:
The profile report as a string.
- Return type:
str