Title: pygame Code Profiling class

Author: Kevin Turner (acapnotic at users.sourceforge.net)
Submission date: May 29, 2001

Description: profile.Profile sub-class using pygame.time.get_ticks.

Download: prof.py

pygame version required: Any
SDL version required: Any
Python version required: Any

Comments: Comments: The standard profile module uses the python timer; Kevin's code replaces it with the pygame.time timer. Note that, as with the standard profiler, machine-specific calibration may result in more accurate measurements - check the profile.py module documentation for more information.

Messages: 0

# profile.Profile sub-class using pygame.time.get_ticks.
# by Kevin.  Public domain.  Have fun.

import profile, pstats
import pygame

def f8_i(x):
    """using an integer clock, so lose the floating-point formatting."""

    return string.rjust(`x`,8)

pstats.f8 = f8_i

class PygameProfile(profile.Profile):
    """Profile sub-class using pygame.time.get_ticks.

    Seems to be pretty fast and precise.

    def __init__(self):
        profile.Profile.__init__(self, pygame.time.get_ticks)

    def trace_dispatch_i(self, frame, event, arg):
        t = self.timer() - self.t # - 0 # Calibration constant
        # (but this needs no calibration constant on my machine)

        if self.dispatch[event](frame,t):
            self.t = self.timer()
            self.t = self.timer() - t # put back unrecorded delta

def example():
    pr.run('function_to_profile(with, "args", as_needed)')

        # To display:

    # Also could be pstats.Stats(pr), if you still have the
    # Profile object around at this point.
    s = pstats.Stats('my_function.prof')


Main - Repository - Submit - News