Profiling Embedded Code

Andrew Wilkinson ajw126NO at SPAMyork.ac.uk
Fri Mar 28 22:31:18 CET 2003


Hi,

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
work.

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()
p.run('UpdateGameData(0)')
--

With this code I get the following exception...
Traceback (most recent call last):
  File "./python/core.py", line 28, in ?
    p.run('UpdateGameData(0)')
  File "c:/programming/python/lib/profile.py", line 403, in run
    return self.runctx(cmd, dict, dict)
  File "c:/programming/python/lib/profile.py", 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,
Regards,
Andrew Wilkinson






More information about the Python-list mailing list