Module pajammin.util.profile
A simple but flexible high-level profiler, used to keep track of how
much time different tasks are taking. To profile a section of code,
simply surround it with calls to profile.start()
and profile.end()
, as follows:
>>> profile.start('name of this action')
>>> do_something()
>>> profile.end('name of this action')
Multiple names can be passed to start()
and
end{}
, to keep track of 'subsections' of code:
>>> profile.start('name of action')
>>> do_something()
>>> profile.start('name of subaction 2')
>>> do_something2()
>>> profile.end('name of subaction 2')
>>> profile.start('name of subaction 3')
>>> do_something3()
>>> profile.end('name of subaction 3')
>>> profile.end('name of action')
Finally, to keep track of how much time is taken per frame, call
start_frame()
and end_frame()
at the beginning
and end of each frame.
To display the profiling results, call profile.dump()
. Here's a sample of the
profiler's output:
Time spent on...
* display 59.16% 22.7 msec/tick
* draw widgets 27.80% 10.6 msec/tick
* Grass2Ground 12.37% 4.7 msec/tick
* DarkDirtPlatform 2.82% 1.0 msec/tick
[...]
* clear display 19.01% 7.2 msec/tick
* flip display 9.00% 3.4 msec/tick
* sort widgets 1.73% 0.7 msec/tick
* select widgets 1.14% 0.4 msec/tick
* screen widgets 0.19% 0.1 msec/tick
* physics 23.90% 9.1 msec/tick
* move bodies 13.65% 5.2 msec/tick
* BlueBird 2.54% 1.0 msec/tick
* BrownBird 2.36% 0.9 msec/tick
[...]
* entity update 9.31% 3.6 msec/tick
* ai 2.47% 0.9 msec/tick
* run scripts 2.14% 0.8 msec/tick
* check interrupts 0.22% 0.1 msec/tick
* map-set-viewport 0.30% 0.1 msec/tick
------
95.15%
FPS: 23.7
Function Summary |
|
dump ()
Display the profiling information that has been collected so far. |
|
end (*key)
Mark the end of a section of code that should be profiled. |
|
end_frame ()
Mark the end of a frame. |
|
start (*key)
Mark the beginning of a section of code that should be profiled. |
|
start_frame ()
Mark the beginning of a frame. |
|
_dump(times,
time,
key)
|
dump()
Display the profiling information that has been collected so
far.
-
|
end(*key)
Mark the end of a section of code that should be profiled.
-
- Parameters:
key -
The name of this section of code.
|
end_frame()
Mark the end of a frame.
-
|
start(*key)
Mark the beginning of a section of code that should be profiled.
-
- Parameters:
key -
The name of this section of code.
|
start_frame()
Mark the beginning of a frame.
-
|
frame_time
-
- Type:
-
float
- Value:
|
frames
-
- Type:
-
float
- Value:
|
profile_time
-
- Type:
-
dict
- Value:
|
total_time
-
- Type:
-
dict
- Value:
|