Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-05 Thread Giampaolo Rodola'
Long ago I posted a patch for this (decorator + context manager) but I bumped into a weird error I wasn't able to fix (see last comment): http://bugs.python.org/issue9285 On Wed, Nov 2, 2016 at 10:45 PM, Tim Mitchell wrote: > Hi Ben, > > Mostly I just print to stdout, I imagine more flexibility

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Tim Mitchell
Hi Ben, Mostly I just print to stdout, I imagine more flexibility would be needed in general. This is for python 2.7 - don't know if it works for 3. def profile(sort='time', restriction=(), callers=None, callees=None, filename=None): def _profileDecorator(func): "print profile stats

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Ben Hoyt
Okay, got it, that sounds fair enough. With your @profile decorator how do you tell it when and where to print the output? Can you post the source for your decorator? On Wed, Nov 2, 2016 at 4:52 PM, Tim Mitchell wrote: > I use an @profile() decorator for almost all my profiling. If you want to

Re: [Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Tim Mitchell
I use an @profile() decorator for almost all my profiling. If you want to profile function foo you just decorate it and re-run the program. With a with block you have to find the places where foo is called and put with statements around the calls. I think both approaches are equally valid and usef

[Python-ideas] Small improvements to the profile/cProfile API

2016-11-02 Thread Ben Hoyt
Hi folks, Every time I do some Python profiling (with cProfile) the API feels kinda baroque, and I have to write ~10 line helper functions to do what I want. For example, if I want the return value of running some function and the profiling output as a string (e.g., to send as part of a web respon