classification
Title: c/profile refactoring
Type: Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: georg.brandl, giampaolo.rodola, pitrou, python-dev
Priority: normal Keywords: easy, patch

Created on 2013-02-12 22:40 by giampaolo.rodola, last changed 2013-02-25 10:43 by giampaolo.rodola. This issue is now closed.

Files
File name Uploaded Description Edit
profile-refactoring.diff giampaolo.rodola, 2013-02-12 22:40 review
profile-refactoring.diff giampaolo.rodola, 2013-02-17 18:50 review
Messages (6)
msg181980 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-02-12 22:40
profile and cProfile modules define the same utility functions (run() and runctx()) which use the same code except the profiler class.
Considering that we're going to add 2 new utility functions (runcall() and runblock(), see issue9285 and issue17130) I think we should refactor the code in order to avoid this code duplication.
Patch in attachment does that.
The approach I came up with looks a bit hackish though so I'd like to get some feedback. Is it acceptable?
msg182008 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-13 10:09
The patch doesn't look right to me. If you import cProfile, profile will always invoke the cProfile profiler.
msg182010 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-02-13 10:10
No, it's the other way around. It's from cProfile which I import profile.

diff --git a/Lib/cProfile.py b/Lib/cProfile.py
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
...
+import profile as _pyprofile
msg182026 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-13 12:08
> No, it's the other way around. It's from cProfile which I import
> profile.
> 
> diff --git a/Lib/cProfile.py b/Lib/cProfile.py
> --- a/Lib/cProfile.py
> +++ b/Lib/cProfile.py
> ...
> +import profile as _pyprofile

That's exactly what I'm saying. Once you import cProfile, the attributes
on the profile functions are overriden.
Either way, a module shouldn't mutate another module's functions.
msg182281 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-02-17 18:50
Of course you're right. I didn't realize that.
How about this (in attachment)?
msg182928 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-25 10:38
New changeset 422169310b7c by Giampaolo Rodola' in branch 'default':
Fix #17197: profile/cProfile modules refactored so that code of run() and runctx() utility functions is not duplicated in both modules.
http://hg.python.org/cpython/rev/422169310b7c
History
Date User Action Args
2013-02-25 10:43:23giampaolo.rodolasetstatus: open -> closed
assignee: giampaolo.rodola
resolution: fixed
2013-02-25 10:38:38python-devsetnosy: + python-dev
messages: + msg182928
2013-02-17 18:50:04giampaolo.rodolasetfiles: + profile-refactoring.diff
keywords: + patch
messages: + msg182281
2013-02-13 12:08:04pitrousetmessages: + msg182026
2013-02-13 10:10:58giampaolo.rodolasetmessages: + msg182010
2013-02-13 10:09:09pitrousetmessages: + msg182008
2013-02-12 22:40:35giampaolo.rodolasetkeywords: + easy, - patch
components: + Library (Lib)
versions: + Python 3.4
2013-02-12 22:40:09giampaolo.rodolacreate