cProfile doesn't work?

Hi I’m new.

I tried to run cProfile on some code, but I kept getting NameErrors. I couldn’t figure out what was wrong so I tried to use it in the console but managed to get the error again even for something ridiculously simple.

Am I missing something here? Or does cProfile not work in Blender? If so, what tools can I use to profile my code?

>>> import math
>>> math.sqrt(64)

>>> import cProfile
>>> cProfile.run(‘math.sqrt(64)’)
3 function calls in 0.000 CPU seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {built-in method exec}
1 0.000 0.000 0.000 0.000 {method ‘disable’ of ‘_lsprof.Profiler’ objects}

Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “C:\PROGRA~1\UTILIT~1\BLENDE~1\Blender\2.53\python\lib\cProfile.py”, line 29, in run
prof = prof.run(statement)
File “C:\PROGRA~1\UTILIT~1\BLENDE~1\Blender\2.53\python\lib\cProfile.py”, line 135, in run
return self.runctx(cmd, dict, dict)
File “C:\PROGRA~1\UTILIT~1\BLENDE~1\Blender\2.53\python\lib\cProfile.py”, line 140, in runctx
exec(cmd, globals, locals)
File “<string>”, line 1, in <module>
NameError: name ‘math’ is not defined

I managed to figure out how to get it to work

It seems I need to use this code instead

cProfile.runctx(‘functionname(args)’, globals(), locals())

No idea why though