profiler
FreeBodyEngine.core.profiler
#
Profiler()
#
A crude call-time profiler built on sys.setprofile - installed for
the whole process as soon as a Profiler is constructed, but only
actually records timings while active (between start() and stop()).
Installs this instance as the process's global profile function.
Nothing is recorded until start() is called, even though the hook
is live immediately.
calls = {}
instance-attribute
#
frame_calls = {}
instance-attribute
#
close()
#
Deactivates the profiler. Does not uninstall the sys.setprofile
hook itself - profile() keeps running on every call/return event
process-wide, just without recording anything.
profile(frame, event, args)
#
The sys.setprofile callback: on a "call" event, stashes a start
timestamp on the frame's locals; on the matching "return" event,
adds the elapsed time to self.calls[function_name]. A no-op while
self._active is False.
start()
#
Begins recording call timings.
stop()
#
Stops recording, prints the accumulated per-function call times
(sorted by function name; entries under 1ms are omitted), and
resets self.calls for the next run.
Note: self.frame_calls is printed alongside self.calls but is
never actually populated by profile() - it's always empty.