[Python-talk] Fw: cProfile
Kent Johnson
kent37 at tds.net
Thu Oct 15 09:20:17 EDT 2009
On Thu, Oct 15, 2009 at 9:09 AM, <bruce.labitt at autoliv.com> wrote:
>> > > I'd like to profile my whole routine. Say it is called
> fftclient.py, and we
>> > > are using ipython. At the command line would be
>> > >
>> > >>> import cProfile
>> > >>> cProfile.run(' ??? ','fftclientprof')
>> > >>> import pstats
>> > >>
>> > >> > p = pstats.Stats('fftclientprof')
>> > >> > p.sort_stats('time').print_stats(10)
>> > >
>> > > What would go in ??? __main__? I'm confused about this...
>> There isn't a main(). Just loads of functions, a couple of classes.
>> Last part of file is:
>>
>> if __name__=='__main__':
>> init stuff
>> while ii<problemsize:
>> build_waveform
>> commandsequencer
>> ii = ii + 1
OK, so make a main(), because when you import fftclient, the "if
__name__ == '__main__'" part won't run. Change the code to
def main(): # or whatever name is appropriate
init stuff
while ii<problemsize:
build_waveform
commandsequencer
ii = ii + 1
if __name__=='__main__':
main()
>> cProfile.run('fftclient.__main__','fftclientprof') ??? or ???
cProfile.run('main()', 'fftclientprof')
Kent
More information about the Python-talk
mailing list