[issue18033] Example for Profile Module shows incorrect method
New submission from Jough Dempsey: The example on this page: http://docs.python.org/2/library/profile.html?highlight=pstats#profile.Profi... Shows: import cProfile, pstats, io pr = cProfile.Profile() pr.enable() ... do something ... pr.disable() s = io.StringIO() ps = pstats.Stats(pr, stream=s) ps.print_results() Where "ps.print_results()" should be "ps.print_stats()" ---------- assignee: docs@python components: Documentation messages: 189823 nosy: docs@python, jough priority: normal severity: normal status: open title: Example for Profile Module shows incorrect method type: enhancement versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Changes by Phil Connell <pconnell@gmail.com>: ---------- nosy: +pconnell _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- keywords: +easy nosy: +ezio.melotti stage: -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Dmi Baranov added the comment: Added py3 patch ---------- keywords: +patch nosy: +dmi.baranov versions: +Python 3.4 Added file: http://bugs.python.org/file30390/issue18033_py3.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Dmi Baranov added the comment: py2 ---------- Added file: http://bugs.python.org/file30391/issue18033_py2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Ezio Melotti added the comment: Thanks for the patches, however the Python 2 example doesn't work. I think a BytesIO should be used instead of a StringIO, and print_stats() only returns a pstats.Stats instance, without actually printing any result. I wonder if print_results was an old method that has been removed and if now there's another way to print the results. I haven't tried on Python 3 yet, but the same comment might apply there too. ---------- stage: needs patch -> patch review versions: +Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Armin Rigo added the comment: A slightly more complete example that I tested: http://stackoverflow.com/a/16077568/1556290 ---------- nosy: +arigo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Olivier Hervieu added the comment: Here is a fixed version for python2.7. Using StringIO instead of io module fixes the problem pointed by Ezio. The print_stats method dumps the stats either on sys.stdout if `Stats` class is declared without a stream specification or in the given stream parameter (the name print_stats may be a bit misleading). ---------- nosy: +ohe Added file: http://bugs.python.org/file30760/issue18033_py2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Roundup Robot added the comment: New changeset 93018d47793f by Senthil Kumaran in branch '2.7': Correct Profile class usage example. Addresses issue #18033 . http://hg.python.org/cpython/rev/93018d47793f New changeset ab4d3ccb92e6 by Senthil Kumaran in branch '3.3': Correct Profile class usage example. Addresses issue #18033. http://hg.python.org/cpython/rev/ab4d3ccb92e6 New changeset 88182b388bae by Senthil Kumaran in branch 'default': merge from 3.3 http://hg.python.org/cpython/rev/88182b388bae ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
Senthil Kumaran added the comment: I consolidated the patches and example and have committed them to 2.7, 3.3 and 3.4. Thanks for your contributions. ---------- nosy: +orsenthil resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18033> _______________________________________
participants (8)
-
Armin Rigo
-
Dmi Baranov
-
Ezio Melotti
-
Jough Dempsey
-
Olivier Hervieu
-
Phil Connell
-
Roundup Robot
-
Senthil Kumaran