<feed xmlns='http://www.w3.org/2005/Atom'>
<title>python.git/Lib/pstats.py, branch 3.10</title>
<subtitle>Python interpreter</subtitle>
<id>http://dangofactory.net/cgit/cgit.cgi/Server/python.git/atom/Lib/pstats.py?h=3.10</id>
<link rel='self' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/atom/Lib/pstats.py?h=3.10'/>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/'/>
<updated>2022-10-05T21:57:26Z</updated>
<entry>
<title>[3.10] Fix type annotation of `pstats.FunctionProfile.ncalls` (GH-96741) (#96836)</title>
<updated>2022-10-05T21:57:26Z</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2022-10-05T21:57:26Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=6f23472345aedbba414620561ba89fa3cf6eda24'/>
<id>urn:sha1:6f23472345aedbba414620561ba89fa3cf6eda24</id>
<content type='text'>
This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.
(cherry picked from commit 8e9a37dde44c9fa0b961cb2db5dc8266e1f85d11)

Co-authored-by: Ruan Comelli &lt;ruancomelli@gmail.com&gt;</content>
</entry>
<entry>
<title>[3.10] bpo-44559: [Enum] revert enum module to 3.9 (GH-27010)</title>
<updated>2021-07-04T04:08:42Z</updated>
<author>
<name>Ethan Furman</name>
<email>ethan@stoneleaf.us</email>
</author>
<published>2021-07-04T04:08:42Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=9bf7c2d638a582af2444bc864feba13ab8957b68'/>
<id>urn:sha1:9bf7c2d638a582af2444bc864feba13ab8957b68</id>
<content type='text'>
* [Enum] revert enum module to 3.9</content>
</entry>
<entry>
<title>bpo-38659: [Enum] add _simple_enum decorator (GH-25497)</title>
<updated>2021-04-21T17:20:44Z</updated>
<author>
<name>Ethan Furman</name>
<email>ethan@stoneleaf.us</email>
</author>
<published>2021-04-21T17:20:44Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=a02cb474f9c097c83cd444a47e9fb5f99b4aaf45'/>
<id>urn:sha1:a02cb474f9c097c83cd444a47e9fb5f99b4aaf45</id>
<content type='text'>
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</content>
</entry>
<entry>
<title>Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)</title>
<updated>2021-04-20T02:12:24Z</updated>
<author>
<name>Ethan Furman</name>
<email>ethan@stoneleaf.us</email>
</author>
<published>2021-04-20T02:12:24Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=503cdc7c124cebbd777008bdf7bd9aa666b25f07'/>
<id>urn:sha1:503cdc7c124cebbd777008bdf7bd9aa666b25f07</id>
<content type='text'>
This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.</content>
</entry>
<entry>
<title>bpo-38659: [Enum] add _simple_enum decorator (GH-25285)</title>
<updated>2021-04-20T01:04:53Z</updated>
<author>
<name>Ethan Furman</name>
<email>ethan@stoneleaf.us</email>
</author>
<published>2021-04-20T01:04:53Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=dbac8f40e81eb0a29dc833e6409a1abf47467da6'/>
<id>urn:sha1:dbac8f40e81eb0a29dc833e6409a1abf47467da6</id>
<content type='text'>
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</content>
</entry>
<entry>
<title>bpo-41811: create SortKey members using first given value (GH-22316)</title>
<updated>2020-09-19T18:12:57Z</updated>
<author>
<name>Ethan Furman</name>
<email>ethan@stoneleaf.us</email>
</author>
<published>2020-09-19T18:12:57Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=ae0d2a33ec05aece939a959d36fcf1df1e210a08'/>
<id>urn:sha1:ae0d2a33ec05aece939a959d36fcf1df1e210a08</id>
<content type='text'>
</content>
</entry>
<entry>
<title>bpo-37958: Adding get_profile_dict to pstats (GH-15495)</title>
<updated>2020-01-15T22:51:54Z</updated>
<author>
<name>Daniel Olshansky</name>
<email>olshansky.daniel@gmail.com</email>
</author>
<published>2020-01-15T22:51:54Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=01602ae40321ecdb375ee6d44eaeac3255857879'/>
<id>urn:sha1:01602ae40321ecdb375ee6d44eaeac3255857879</id>
<content type='text'>
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:

```
{"&lt;method 'disable' of '_lsprof.Profiler' objects&gt;": {'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</content>
</entry>
<entry>
<title>Fix typos in docs and docstrings (GH-13745)</title>
<updated>2019-06-02T23:12:33Z</updated>
<author>
<name>Xtreak</name>
<email>tir.karthi@gmail.com</email>
</author>
<published>2019-06-02T23:12:33Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=0d70227e419ab78c44d81b4ea6ae8aaf769470e6'/>
<id>urn:sha1:0d70227e419ab78c44d81b4ea6ae8aaf769470e6</id>
<content type='text'>
</content>
</entry>
<entry>
<title>bpo-36766: Typos in docs and code comments (GH-13116)</title>
<updated>2019-05-06T18:57:17Z</updated>
<author>
<name>penguindustin</name>
<email>penguindustin@gmail.com</email>
</author>
<published>2019-05-06T18:57:17Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=964663089547ca110199e23867b46b07ff4be88c'/>
<id>urn:sha1:964663089547ca110199e23867b46b07ff4be88c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Revert unneccessary changes made in bpo-30296 and apply other improvements. (GH-2624)</title>
<updated>2018-02-26T14:50:11Z</updated>
<author>
<name>Serhiy Storchaka</name>
<email>storchaka@gmail.com</email>
</author>
<published>2018-02-26T14:50:11Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/python.git/commit/?id=3f2e6f15d64d81633b1fc0b308afc0d6e9026b61'/>
<id>urn:sha1:3f2e6f15d64d81633b1fc0b308afc0d6e9026b61</id>
<content type='text'>
</content>
</entry>
</feed>
