Profiling Embedded Code

Andrew Wilkinson ajw126NO at
Fri Mar 28 22:31:18 CET 2003


I've got some Python code that is embedded into a C application, and I'd
like to profile it. Unfortunatly I can't get the standard profile module to

My C code imports a module, and then at the appropriate time calls the
UpdateGameData function. When the module is imported I'd like to do a 'test'
run of the function, with the profiler on to perform a simple check on it.
(I know this is not a particually good way to profile the code, but I'd like
to get it working and then move on...)

The module is given (slightly trimmed) here...
def UpdateGameData(time):

import profile
p = profile.Profile()'UpdateGameData(0)')

With this code I get the following exception...
Traceback (most recent call last):
  File "./python/", line 28, in ?'UpdateGameData(0)')
  File "c:/programming/python/lib/", line 403, in run
    return self.runctx(cmd, dict, dict)
  File "c:/programming/python/lib/", line 409, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in ?
NameError: name 'UpdateGameData' is not defined

Now this seems very silly to me as 'UpdateGameData' obviously is defined. I
had a look in the code for profile and it seems to mess around with
__main__, but I'm not sure that it's pointing at the right place.

Any suggestions for how to get this to work would be much appreciated,
Andrew Wilkinson

More information about the Python-list mailing list