summaryrefslogtreecommitdiffstats
path: root/Lib/pstats.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-45975: Simplify some while-loops with walrus operator (GH-29347)Nick Drozd2022-11-261-2/+0
|
* Fix type annotation of `pstats.FunctionProfile.ncalls` (#96741)Ruan Comelli2022-09-151-1/+1
| | | | | | * fix: annotate `pstats.FunctionProfile.ncalls` as `str` This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.
* Fix typos in multiple files (GH-26689)Binbin2021-06-131-1/+1
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: * `_simple_enum` decorator to transform a normal class into an enum * `_test_simple_enum` function to compare * `_old_convert_` to enable checking `_convert_` generated enums `_simple_enum` takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 `_old_convert_` works much like` _convert_` does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) `_test_simple_enum` takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)Ethan Furman2021-04-201-3/+2
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: _simple_enum decorator to transform a normal class into an enum _test_simple_enum function to compare _old_convert_ to enable checking _convert_ generated enums _simple_enum takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 _old_convert_ works much like _convert_ does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) test_simple_enum takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* bpo-41811: create SortKey members using first given value (GH-22316)Ethan Furman2020-09-191-3/+3
|
* bpo-37958: Adding get_profile_dict to pstats (GH-15495)Daniel Olshansky2020-01-151-2/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pstats is really useful or profiling and printing the output of the execution of some block of code, but I've found on multiple occasions when I'd like to access this output directly in an easily usable dictionary on which I can further analyze or manipulate. The proposal is to add a function called get_profile_dict inside of pstats that'll automatically return this data the data in an easily accessible dict. The output of the following script: ``` import cProfile, pstats import pprint from pstats import func_std_string, f8 def fib(n): if n == 0: return 0 if n == 1: return 1 return fib(n-1) + fib(n-2) pr = cProfile.Profile() pr.enable() fib(5) pr.create_stats() ps = pstats.Stats(pr).sort_stats('tottime', 'cumtime') def get_profile_dict(self, keys_filter=None): """ Returns a dict where the key is a function name and the value is a dict with the following keys: - ncalls - tottime - percall_tottime - cumtime - percall_cumtime - file_name - line_number keys_filter can be optionally set to limit the key-value pairs in the retrieved dict. """ pstats_dict = {} func_list = self.fcn_list[:] if self.fcn_list else list(self.stats.keys()) if not func_list: return pstats_dict pstats_dict["total_tt"] = float(f8(self.total_tt)) for func in func_list: cc, nc, tt, ct, callers = self.stats[func] file, line, func_name = func ncalls = str(nc) if nc == cc else (str(nc) + '/' + str(cc)) tottime = float(f8(tt)) percall_tottime = -1 if nc == 0 else float(f8(tt/nc)) cumtime = float(f8(ct)) percall_cumtime = -1 if cc == 0 else float(f8(ct/cc)) func_dict = { "ncalls": ncalls, "tottime": tottime, # time spent in this function alone "percall_tottime": percall_tottime, "cumtime": cumtime, # time spent in the function plus all functions that this function called, "percall_cumtime": percall_cumtime, "file_name": file, "line_number": line } func_dict_filtered = func_dict if not keys_filter else { key: func_dict[key] for key in keys_filter } pstats_dict[func_name] = func_dict_filtered return pstats_dict pp = pprint.PrettyPrinter(depth=6) pp.pprint(get_profile_dict(ps)) ``` will produce: ``` {"<method 'disable' of '_lsprof.Profiler' objects>": {'cumtime': 0.0, 'file_name': '~', 'line_number': 0, 'ncalls': '1', 'percall_cumtime': 0.0, 'percall_tottime': 0.0, 'tottime': 0.0}, 'create_stats': {'cumtime': 0.0, 'file_name': '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cProfile.py', 'line_number': 50, 'ncalls': '1', 'percall_cumtime': 0.0, 'percall_tottime': 0.0, 'tottime': 0.0}, 'fib': {'cumtime': 0.0, 'file_name': 'get_profile_dict.py', 'line_number': 5, 'ncalls': '15/1', 'percall_cumtime': 0.0, 'percall_tottime': 0.0, 'tottime': 0.0}, 'total_tt': 0.0} ``` As an example, this can be used to generate a stacked column chart using various visualization tools which will assist in easily identifying program bottlenecks. https://bugs.python.org/issue37958 Automerge-Triggered-By: @gpshead
* Fix typos in docs and docstrings (GH-13745)Xtreak2019-06-021-2/+2
|
* bpo-36766: Typos in docs and code comments (GH-13116)penguindustin2019-05-061-1/+1
|
* Revert unneccessary changes made in bpo-30296 and apply other improvements. ↵Serhiy Storchaka2018-02-261-1/+1
| | | | (GH-2624)
* bpo-29237: Create enum for pstats sorting options (GH-5103)mwidjaja2018-01-261-8/+38
|
* bpo-30296 Remove unnecessary tuples, lists, sets, and dicts (#1489)Jon Dufresne2017-05-181-2/+1
| | | | | | | | * Replaced list(<generator expression>) with list comprehension * Replaced dict(<generator expression>) with dict comprehension * Replaced set(<list literal>) with set literal * Replaced builtin func(<list comprehension>) with func(<generator expression>) when supported (e.g. any(), all(), tuple(), min(), & max())
* bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)Serhiy Storchaka2017-04-161-1/+1
|
* bpo-29554: Improve docs for pstat module and profile. (#88)Matthias Bussonnier2017-02-211-5/+8
| | | | | | | Clarify that methods take a string which is interpreted as a regex, not a regex object. Also clarify what the old `-1`, `0`, `1` and `2` options were.
* Issue #27241: Catch exception when running pstats as main.Stefan Krah2016-08-021-1/+4
|
* Issue #18200: Back out usage of ModuleNotFoundError (8d28d44f3a9a)Brett Cannon2013-07-041-1/+1
|
* Issue #18200: Update the stdlib (except tests) to useBrett Cannon2013-06-141-1/+1
| | | | ModuleNotFoundError.
* modernize some modules' code by using with statement around open()Giampaolo Rodola'2013-02-121-7/+3
|
* Replace IOError with OSError (#16715)Andrew Svetlov2012-12-251-1/+1
|
* Merge issue #14900: Add aliases for sorting params for pstat to follow ↵Andrew Svetlov2012-10-071-0/+4
|\ | | | | | | | | | | column names from pstat output. Patch by Arne Babenhauserheide.
| * Issue #14900: Add aliases for sorting params for pstat to follow column ↵Andrew Svetlov2012-10-071-0/+4
| | | | | | | | | | | | names from pstat output. Patch by Arne Babenhauserheide.
* | Merge issue #14900: Distuguish call count and primitive call count in pstat ↵Andrew Svetlov2012-10-071-1/+1
|\ \ | |/ | | | | | | | | output. Patch by Arne Babenhauserheide.
| * Issue #14900: Distuguish call count and primitive call count in pstat output.Andrew Svetlov2012-10-071-1/+1
| | | | | | | | Patch by Arne Babenhauserheide.
* | Issue #13839: When invoked on the command-line, the pstats module now ↵Antoine Pitrou2012-03-141-0/+2
| | | | | | | | | | | | accepts several filenames of profile stat files and merges them all. Patch by Matt Joiner.
* | Remove redundant imports.Florent Xicluna2011-11-041-1/+0
|/
* Merge profile docs followup (#12417) from 3.1Éric Araujo2011-07-281-4/+0
|\
| * Remove mentions of previous license in profile module docs (#12417 followup).Éric Araujo2011-07-281-4/+0
| | | | | | | | Also remove an extra docstring.
| * update profile license (closes #12417)Benjamin Peterson2011-06-271-25/+17
| |
| * #11565: Fix several typos. Patch by Piotr Kasprzyk.Ezio Melotti2011-03-161-1/+1
| |
| * Merged revisions 86580 via svnmerge fromSenthil Kumaran2010-11-201-1/+1
| | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86580 | senthil.kumaran | 2010-11-21 01:02:50 +0800 (Sun, 21 Nov 2010) | 3 lines Fix issue10377 - Output from pstats - it is just secs (i.e, wallclock time) and not CPU time. ........
| * Merged revisions ↵Georg Brandl2010-10-061-26/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 82805-82806,83523-83527,83536,83538,83542,83546-83548,83550-83555,83558,83560 via svnmerge from svn+ssh://svn.python.org/python/branches/py3k ........ r82805 | georg.brandl | 2010-07-11 11:42:10 +0200 (So, 11 Jul 2010) | 1 line #7935: cross-reference to ast.literal_eval() from eval() docs. ........ r82806 | georg.brandl | 2010-07-11 12:22:44 +0200 (So, 11 Jul 2010) | 1 line #9223: link to Command class reference, and move Command interface docs nearer to class docs. ........ r83523 | georg.brandl | 2010-08-02 14:06:18 +0200 (Mo, 02 Aug 2010) | 1 line #9209 and #7781: fix two crashes in pstats interactive browser. ........ r83524 | georg.brandl | 2010-08-02 14:20:23 +0200 (Mo, 02 Aug 2010) | 1 line #9428: fix running scripts from profile/cProfile with their own name and the right namespace. Same fix as for trace.py in #1690103. ........ r83525 | georg.brandl | 2010-08-02 14:36:24 +0200 (Mo, 02 Aug 2010) | 1 line Get rid of spurious "threading" entries in trace output. ........ r83526 | georg.brandl | 2010-08-02 14:40:22 +0200 (Mo, 02 Aug 2010) | 1 line Fix softspace relic. ........ r83527 | georg.brandl | 2010-08-02 14:48:46 +0200 (Mo, 02 Aug 2010) | 1 line #3821: beginnings of a trace.py unittest. ........ r83536 | georg.brandl | 2010-08-02 19:49:25 +0200 (Mo, 02 Aug 2010) | 1 line #8578: mention danger of not incref'ing weak referenced object. ........ r83538 | georg.brandl | 2010-08-02 20:10:13 +0200 (Mo, 02 Aug 2010) | 1 line #6928: fix class docs w.r.t. new metaclasses. ........ r83542 | georg.brandl | 2010-08-02 20:56:54 +0200 (Mo, 02 Aug 2010) | 1 line Move test_SimpleHTTPServer into test_httpservers. ........ r83546 | georg.brandl | 2010-08-02 21:16:34 +0200 (Mo, 02 Aug 2010) | 1 line #7973: Fix distutils options spelling. ........ r83547 | georg.brandl | 2010-08-02 21:19:26 +0200 (Mo, 02 Aug 2010) | 1 line #7386: add example that shows that trailing path separators are stripped. ........ r83548 | georg.brandl | 2010-08-02 21:23:34 +0200 (Mo, 02 Aug 2010) | 1 line #8172: how does one use a property? ........ r83550 | georg.brandl | 2010-08-02 21:32:43 +0200 (Mo, 02 Aug 2010) | 1 line #9451: strengthen warning about __*__ special name usage. ........ r83551 | georg.brandl | 2010-08-02 21:35:06 +0200 (Mo, 02 Aug 2010) | 1 line Remove XXX comment that was displayed. ........ r83552 | georg.brandl | 2010-08-02 21:36:36 +0200 (Mo, 02 Aug 2010) | 1 line #9438: clarify that constant names also cannot be assigned as attributes. ........ r83553 | georg.brandl | 2010-08-02 21:39:17 +0200 (Mo, 02 Aug 2010) | 1 line Remove redundant information. ........ r83554 | georg.brandl | 2010-08-02 21:43:05 +0200 (Mo, 02 Aug 2010) | 1 line #7280: note about nasmw.exe. ........ r83555 | georg.brandl | 2010-08-02 21:44:48 +0200 (Mo, 02 Aug 2010) | 1 line #8861: remove unused variable. ........ r83558 | georg.brandl | 2010-08-02 22:05:19 +0200 (Mo, 02 Aug 2010) | 1 line #8648: document UTF-7 codec functions. ........ r83560 | georg.brandl | 2010-08-02 22:16:18 +0200 (Mo, 02 Aug 2010) | 1 line #9087: update json docstrings -- unicode and long do not exist anymore. ........
| * Merged revisions 83531 via svnmerge fromGeorg Brandl2010-08-021-2/+7
| | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83531 | georg.brandl | 2010-08-02 19:24:49 +0200 (Mo, 02 Aug 2010) | 1 line #7372: fix regression in pstats: a previous fix to handle cProfile data in add_callers broke handling of profile data. ........
| * Merged revisions 83385-83389,83391 via svnmerge fromGeorg Brandl2010-08-011-5/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://svn.python.org/python/branches/py3k ........ r83385 | georg.brandl | 2010-08-01 08:42:45 +0200 (So, 01 Aug 2010) | 1 line #8773: mailbox.py does not need to be executable. ........ r83386 | georg.brandl | 2010-08-01 08:44:46 +0200 (So, 01 Aug 2010) | 1 line #8768: name test method properly so that it gets executed. ........ r83387 | georg.brandl | 2010-08-01 08:53:28 +0200 (So, 01 Aug 2010) | 1 line #8735: better explain semantics of *values* argument for parse(). ........ r83388 | georg.brandl | 2010-08-01 09:48:43 +0200 (So, 01 Aug 2010) | 1 line #7395: fix traceback in do_add() when no stats are loaded. Apply same fix for do_sort() and do_reverse(). ........ r83389 | georg.brandl | 2010-08-01 09:57:47 +0200 (So, 01 Aug 2010) | 1 line Small improvements to pstats browser: do not crash on reading invalid file, and actually do a reload when executing "read" as intended. ........ r83391 | georg.brandl | 2010-08-01 10:10:08 +0200 (So, 01 Aug 2010) | 1 line Add another news entry. ........
* | strip trailing wsBenjamin Peterson2011-06-271-3/+3
| |
* | update profile license (closes #12417)Benjamin Peterson2011-06-271-25/+17
| |
* | Fix issue10377 - Output from pstats - it is just secs (i.e, wallclock time) ↵Senthil Kumaran2010-11-201-1/+1
| | | | | | | | and not CPU time.
* | Refactor interesting use of try-finally.Georg Brandl2010-10-221-10/+9
| |
* | Make top_level attribute a set instead of a dict with None values.Georg Brandl2010-10-221-5/+5
| |
* | #10166: rewrite self-recursion to iteration in pstats.Stats.add(). Also add ↵Georg Brandl2010-10-221-24/+26
| | | | | | | | a unittest and a stats test file.
* | #7372: fix regression in pstats: a previous fix to handle cProfile data in ↵Georg Brandl2010-08-021-2/+7
| | | | | | | | add_callers broke handling of profile data.
* | #9209 and #7781: fix two crashes in pstats interactive browser.Georg Brandl2010-08-021-26/+29
| |
* | Small improvements to pstats browser: do not crash on reading invalid file, ↵Georg Brandl2010-08-011-1/+9
| | | | | | | | and actually do a reload when executing "read" as intended.
* | #7395: fix traceback in do_add() when no stats are loaded. Apply same fix ↵Georg Brandl2010-08-011-4/+15
| | | | | | | | for do_sort() and do_reverse().
* | Forward port total_ordering() and cmp_to_key().Raymond Hettinger2010-04-051-10/+2
| |
* | Merged revisions 79603 via svnmerge fromAndrew M. Kuchling2010-04-021-1/+1
| | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r79603 | andrew.kuchling | 2010-04-02 12:59:16 -0400 (Fri, 02 Apr 2010) | 1 line #4440: modernize a use of filter(), making it compatible with 3.x ........
* | Use true kwonly arg instead of **kwds hackaround.Georg Brandl2009-09-021-14/+2
|/
* Issue #1771: Remove cmp parameter from list.sort() and builtin.sorted().Raymond Hettinger2008-01-301-1/+11
|
* Merged revisions 60143-60149 via svnmerge fromChristian Heimes2008-01-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r60143 | georg.brandl | 2008-01-20 15:50:05 +0100 (Sun, 20 Jan 2008) | 3 lines Switch mmap from old Py_FindMethod to new PyObject_GenericGetAttr attribute access. Fixes #1087735. ........ r60145 | georg.brandl | 2008-01-20 20:40:58 +0100 (Sun, 20 Jan 2008) | 2 lines Add blurb about executable scripts on Windows. #760657. ........ r60146 | georg.brandl | 2008-01-20 20:48:40 +0100 (Sun, 20 Jan 2008) | 2 lines #1219903: fix tp_richcompare docs. ........ r60147 | georg.brandl | 2008-01-20 22:10:08 +0100 (Sun, 20 Jan 2008) | 2 lines Fix markup. ........ r60148 | gregory.p.smith | 2008-01-21 08:11:11 +0100 (Mon, 21 Jan 2008) | 14 lines Provide a sanity check during PyThreadState_DeleteCurrent() and PyThreadState_Delete() to avoid an infinite loop when the tstate list is messed up and has somehow becomes circular and does not contain the current thread. I don't know how this happens but it does, *very* rarely. On more than one hardware platform. I have not been able to reproduce it manually. Attaching to a process where its happening: it has always been in an infinite loop over a single element tstate list that is not the tstate we're looking to delete. It has been in t_bootstrap()'s call to PyThreadState_DeleteCurrent() as a pthread is exiting. ........ r60149 | georg.brandl | 2008-01-21 11:24:59 +0100 (Mon, 21 Jan 2008) | 2 lines #1269: fix a bug in pstats.add_callers() and add a unit test file for pstats. ........
* The final occurrences of exception slicing.Georg Brandl2008-01-061-2/+2
|