This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年02月05日 00:55 by gvanrossum, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue17130.patch | bjorns, 2013年02月23日 16:56 | Adding convenience method profile.runcall() | review | |
| Messages (13) | |||
|---|---|---|---|
| msg181403 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2013年02月05日 00:55 | |
The profile module exports convenience functions for run() and runctx(), which wrap the corresponding methods of the Profile object. But perhaps the most useful method, runcall(), is not wrapped. :-( |
|||
| msg181707 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2013年02月09日 00:16 | |
While we're on profile convenience features, how about adding two context managers: - one that just profiles a block and prints the profile (or dumps the data to a file) - one that takes a Profile instance and enables profiling to that instance E.g. (1) with cProfile.runblock([file]): <your code here> or (2) p = cProfile.Profile() with p: <your code here> Also a decorator corresponding to (1): @cProfile.runfunc([filename]) def myfunc(args): <stuff> |
|||
| msg181825 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年02月10日 18:14 | |
+1 for runcall() and the context manager. |
|||
| msg181911 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2013年02月11日 16:59 | |
Antoine, what about the decorator? I've come across a few use cases. --Guido van Rossum (sent from Android phone) On Feb 10, 2013 10:14 AM, "Antoine Pitrou" <report@bugs.python.org> wrote: > > Antoine Pitrou added the comment: > > +1 for runcall() and the context manager. > > ---------- > nosy: +pitrou > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue17130> > _______________________________________ > |
|||
| msg181913 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2013年02月11日 17:29 | |
See issue 9285 in which I wrote a decorator for profile/cProfile. That can be modified to work both as a decorator or a context manager by using contextlib.contextmanager. Shall I continue in issue 9285 and rewrite that patch? |
|||
| msg181916 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2013年02月11日 17:49 | |
Sure, I will comment on that issue. |
|||
| msg181921 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年02月11日 19:09 | |
> Antoine, what about the decorator? I've come across a few use cases. I don't know, I'm thinking that "there should be one obvious way to do it" :-) By that I mean that the context manager is more generic than the decorator. Or do you want to decorate functions from an external library? |
|||
| msg181924 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2013年02月11日 19:17 | |
If I quickly want to profile one function, with the decorator I have to insert a with-statement in its body and mess with the indentation of the entire body. With a decorator it's just a one-line insertion. |
|||
| msg181925 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年02月11日 19:17 | |
Ah, fair enough. |
|||
| msg181929 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2013年02月11日 19:57 | |
As for runcall() we haven't the ability to freely support kwargs *and* filename. I see two possibilities. Kill kwargs, as such: +def runcall(func, *args, filename=None, sort=-1): + """Run func(*args) under profiler, optionally saving results in + filename. + """ ...or make 'filename_' and 'sort_' two special name kwargs to be used as in: >>> runcall(fun, foo=1, bar=2, filename_='...') Also, there might be some value in adding 'strip_dirs' argument to those functions (run/runctx/runcall). |
|||
| msg182762 - (view) | Author: Björn Skoglund (bjorns) * | Date: 2013年02月23日 16:56 | |
Hello, first patch, be kind. I opted for option 2 so there is top keywords filename_ and sort_ filtered out before calling func. The test in test_profile seems to call runctx but runcall and run are never tested. Not sure if this is missing or intended. |
|||
| msg182798 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2013年02月23日 19:20 | |
I already posted a patch in issue 9285. Maybe we should close this one as a duplicate. |
|||
| msg182802 - (view) | Author: Björn Skoglund (bjorns) * | Date: 2013年02月23日 19:38 | |
Look at that. Sorry, totally missed it. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:41 | admin | set | github: 61332 |
| 2013年02月25日 15:59:18 | eric.araujo | set | status: open -> closed superseder: Add a profile decorator to profile and cProfile resolution: duplicate stage: needs patch -> resolved |
| 2013年02月23日 19:38:54 | bjorns | set | messages: + msg182802 |
| 2013年02月23日 19:20:18 | giampaolo.rodola | set | messages: + msg182798 |
| 2013年02月23日 16:56:54 | bjorns | set | files:
+ issue17130.patch nosy: + bjorns messages: + msg182762 keywords: + patch |
| 2013年02月12日 12:47:48 | giampaolo.rodola | set | nosy:
+ georg.brandl |
| 2013年02月11日 19:57:16 | giampaolo.rodola | set | messages: + msg181929 |
| 2013年02月11日 19:17:41 | pitrou | set | messages: + msg181925 |
| 2013年02月11日 19:17:00 | gvanrossum | set | messages: + msg181924 |
| 2013年02月11日 19:09:43 | pitrou | set | messages: + msg181921 |
| 2013年02月11日 17:49:19 | gvanrossum | set | messages: + msg181916 |
| 2013年02月11日 17:29:00 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola messages: + msg181913 |
| 2013年02月11日 16:59:06 | gvanrossum | set | messages: + msg181911 |
| 2013年02月10日 18:14:20 | pitrou | set | nosy:
+ pitrou messages: + msg181825 |
| 2013年02月09日 00:16:18 | gvanrossum | set | messages: + msg181707 |
| 2013年02月08日 20:52:42 | eric.araujo | set | keywords:
+ easy nosy: + eric.araujo |
| 2013年02月05日 00:55:00 | gvanrossum | create | |