An answer for QGIS 3.16 (did not test on previous versions)
You have 3 possibles groups in profiler at the moment in QGIS (startup, projectload, render). You should be aware now, there is a widget with the profiler content (cf screenshot)

To get current used list of group, do QgsApplication.profiler().groups()
To get time for all existing measurements (default or your own)
profiler = QgsApplication.profiler()
for group in profiler.groups():
translatedGroupName = profiler.translateGroupName(group)
for child in profiler.childGroups('', group):
value = profiler.profileTime(child, group)
childGroup = profiler.childGroups(child, group)
# group = name in the GUI combobox but human friendly
# child = name of the first column
# Time for execution
print(translatedGroupName, child, value)
if len(childGroup) > 0:
for subGroup in childGroup:
print(subGroup, profiler.profileTime(subGroup, group))
Weird thing here = order when looping differs from the one in the GUI...
For global time per group, in theory, you should do the following
but does not work (return 0.0)
Instead, you may sum values in the loop above to get "right" total time
for group in profiler.groups():
print(group, profiler.totalTime(group))
If you want your own measures with your own group
from time import sleep
profiler = QgsApplication.profiler()
profiler.start('your task name 1', 'your new group name')
To simulate waiting time but normally, you run your custom code
sleep(11.0)
profiler.end('your new group name')
profiler.start('your task name 2', 'your new group name')
To simulate waiting time but normally, you run your custom code
sleep(8.0)
profiler.end('your new group name')
Alternate way to avoid start and end using Python context
Drawback: you can't log in your own group but only in startup group (default)
with QgsRuntimeProfiler.profile('qwerty'):
sleep(2)
# Do something
.qgz. – J. Monticolo Dec 11 '19 at 10:08QgsApplication.instance().profiler().profileTime(name)with name being those who can be seen in qgsproject.cpp such as "Reading project file", "Updating project file", "Creating auxiliary storage", ... – Kalak Aug 21 '20 at 12:39