# Decorator for pstats
```python
$pip install pstatsdecorator
from pstatsdecorator import pstats_check
# Valid parameters for sortby:
# 'calls'
# 'cumulative'
# 'cumtime'
# 'file'
# 'filename'
# 'module'
# 'ncalls'
# 'pcalls'
# 'line'
# 'name'
# 'nfl'
# 'stdname'
# 'time'
# 'tottime'
# if return_stats is enabled, the function will always return a tuple.
# The last element in the tuple is the pstats data
@pstats_check(print_stats=False, return_stats=True, sortby="filename")
def testest1():
print(isinstance("aaaaaaaaaa", str))
print("aaaaaaaaaaaaaaaaa")
x = 20 + 1
return x
@pstats_check(print_stats=True, return_stats=False, sortby="line")
def testest2():
import re
re.findall("b", "bbbbbbbbbbbbbbbbbbbbb")
print("bbbbbbbbbbbbbbbbbbbbb")
print("bbbbbbbbbbbbbbbbbbbbb")
x = 200 + 1
return x
@pstats_check(print_stats=True, return_stats=False, sortby="cumulative")
def testest3():
print("ccccccccccccccccccccccccc")
x = 2000 + 1
return x
print("k ----------------------------->")
k = testest1()
print(f"xxxxxxxxxxxxxxx\n{k=}")
print("<----------------------------- k")
print("k1 ----------------------------->")
k1 = testest2()
print(f"xxxxxxxxxxxxxxx\n{k1=}")
print("<----------------------------- k1")
print("k2 ----------------------------->")
k2 = testest3()
print(f"xxxxxxxxxxxxxxx\n{k2=}")
print("<----------------------------- k2")
Output:
k ----------------------------->
True
aaaaaaaaaaaaaaaaa
xxxxxxxxxxxxxxx
k=(21, " 7 function calls in 0.000 seconds\n\n Ordered by: file name\n\n ncalls tottime percall cumtime percall filename:lineno(function)\n 1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:21(testest1)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\cProfile.py:106(runcall)\n 1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}\n 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n 1 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n 2 0.000 0.000 0.000 0.000 {built-in method builtins.print}\n\n\n")
<----------------------------- k
k1 ----------------------------->
bbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbb
85 function calls (84 primitive calls) in 0.000 seconds
Ordered by: line number
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'findall' of 're.Pattern' objects}
1 0.000 0.000 0.000 0.000 {built-in method _sre.compile}
1 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}
13 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
2 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}
1 0.000 0.000 0.000 0.000 {built-in method builtins.__import__}
8 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}
13/12 0.000 0.000 0.000 0.000 {built-in method builtins.len}
3 0.000 0.000 0.000 0.000 {built-in method builtins.min}
1 0.000 0.000 0.000 0.000 {built-in method builtins.ord}
2 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.000 0.000 0.000 0.000 C:\Program Files\JetBrains\PyCharm Community Edition 2020.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py:16(do_import)
1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:36(testest2)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:76(__init__)
2 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:82(groups)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:87(_compile)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\cProfile.py:106(runcall)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:112(__init__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:161(__len__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:165(__getitem__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:173(append)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:175(getwidth)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:225(__init__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\re.py:233(findall)
2 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:234(__next)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:250(match)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:255(get)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:287(tell)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\re.py:289(_compile)
2 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:358(__call__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:436(_parse_sub)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:456(_generate_overlap_table)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:477(_get_iscased)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:485(_get_literal_prefix)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:494(_parse)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:560(_compile_info)
2 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:619(isstring)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:622(_code)
2 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:670(__new__)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:783(compile)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:928(fix_flags)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:944(parse)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:977(__and__)
xxxxxxxxxxxxxxx
k1=201
<----------------------------- k1
k2 ----------------------------->
ccccccccccccccccccccccccc
5 function calls in 0.000 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 C:\Users\Gamer\anaconda3\envs\dfdir\lib\cProfile.py:106(runcall)
1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:54(testest3)
1 0.000 0.000 0.000 0.000 {built-in method builtins.print}
1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
xxxxxxxxxxxxxxx
k2=2001
<----------------------------- k2
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/pstatsdecorator",
"name": "pstatsdecorator",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pstats",
"author": "Johannes Fischer",
"author_email": "<aulasparticularesdealemaosp@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/2b/ad/918b372e17ed7bab94d5292fbc1ac3e47ef57255ea983e485495af75f7df/pstatsdecorator-0.10.tar.gz",
"platform": null,
"description": "\n# Decorator for pstats\n\n```python\n$pip install pstatsdecorator\n\nfrom pstatsdecorator import pstats_check\n\n# Valid parameters for sortby:\n# 'calls'\n# 'cumulative'\n# 'cumtime'\n# 'file'\n# 'filename'\n# 'module'\n# 'ncalls'\n# 'pcalls'\n# 'line'\n# 'name'\n# 'nfl'\n# 'stdname'\n# 'time'\n# 'tottime'\n\n# if return_stats is enabled, the function will always return a tuple.\n# The last element in the tuple is the pstats data\n\n@pstats_check(print_stats=False, return_stats=True, sortby=\"filename\")\ndef testest1():\n print(isinstance(\"aaaaaaaaaa\", str))\n print(\"aaaaaaaaaaaaaaaaa\")\n x = 20 + 1\n return x\n\n\n\n@pstats_check(print_stats=True, return_stats=False, sortby=\"line\")\ndef testest2():\n import re\n\n re.findall(\"b\", \"bbbbbbbbbbbbbbbbbbbbb\")\n print(\"bbbbbbbbbbbbbbbbbbbbb\")\n print(\"bbbbbbbbbbbbbbbbbbbbb\")\n x = 200 + 1\n return x\n\t\n\n\n@pstats_check(print_stats=True, return_stats=False, sortby=\"cumulative\")\ndef testest3():\n print(\"ccccccccccccccccccccccccc\")\n x = 2000 + 1\n return x\n\t\n\t\nprint(\"k ----------------------------->\")\n\nk = testest1()\nprint(f\"xxxxxxxxxxxxxxx\\n{k=}\")\nprint(\"<----------------------------- k\")\n\n\n\n\nprint(\"k1 ----------------------------->\")\n\nk1 = testest2()\nprint(f\"xxxxxxxxxxxxxxx\\n{k1=}\")\nprint(\"<----------------------------- k1\")\n\n\n\n\n\nprint(\"k2 ----------------------------->\")\nk2 = testest3()\nprint(f\"xxxxxxxxxxxxxxx\\n{k2=}\")\nprint(\"<----------------------------- k2\")\n\n\n\nOutput:\n\nk ----------------------------->\nTrue\naaaaaaaaaaaaaaaaa\nxxxxxxxxxxxxxxx\nk=(21, \" 7 function calls in 0.000 seconds\\n\\n Ordered by: file name\\n\\n ncalls tottime percall cumtime percall filename:lineno(function)\\n 1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:21(testest1)\\n 1 0.000 0.000 0.000 0.000 C:\\\\Users\\\\Gamer\\\\anaconda3\\\\envs\\\\dfdir\\\\lib\\\\cProfile.py:106(runcall)\\n 1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}\\n 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\\n 1 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\\n 2 0.000 0.000 0.000 0.000 {built-in method builtins.print}\\n\\n\\n\")\n<----------------------------- k\nk1 ----------------------------->\nbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbb\n 85 function calls (84 primitive calls) in 0.000 seconds\n Ordered by: line number\n ncalls tottime percall cumtime percall filename:lineno(function)\n 1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}\n 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\n 1 0.000 0.000 0.000 0.000 {method 'findall' of 're.Pattern' objects}\n 1 0.000 0.000 0.000 0.000 {built-in method _sre.compile}\n 1 0.000 0.000 0.000 0.000 {method 'items' of 'dict' objects}\n 13 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}\n 2 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects}\n 1 0.000 0.000 0.000 0.000 {built-in method builtins.__import__}\n 8 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance}\n 13/12 0.000 0.000 0.000 0.000 {built-in method builtins.len}\n 3 0.000 0.000 0.000 0.000 {built-in method builtins.min}\n 1 0.000 0.000 0.000 0.000 {built-in method builtins.ord}\n 2 0.000 0.000 0.000 0.000 {built-in method builtins.print}\n 1 0.000 0.000 0.000 0.000 C:\\Program Files\\JetBrains\\PyCharm Community Edition 2020.3\\plugins\\python-ce\\helpers\\pydev\\_pydev_bundle\\pydev_import_hook.py:16(do_import)\n 1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:36(testest2)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:76(__init__)\n 2 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:82(groups)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:87(_compile)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\cProfile.py:106(runcall)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:112(__init__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:161(__len__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:165(__getitem__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:173(append)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:175(getwidth)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:225(__init__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\re.py:233(findall)\n 2 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:234(__next)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:250(match)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:255(get)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:287(tell)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\re.py:289(_compile)\n 2 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\enum.py:358(__call__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:436(_parse_sub)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:456(_generate_overlap_table)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:477(_get_iscased)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:485(_get_literal_prefix)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:494(_parse)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:560(_compile_info)\n 2 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:619(isstring)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:622(_code)\n 2 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\enum.py:670(__new__)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_compile.py:783(compile)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:928(fix_flags)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\sre_parse.py:944(parse)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\enum.py:977(__and__)\nxxxxxxxxxxxxxxx\nk1=201\n<----------------------------- k1\nk2 ----------------------------->\nccccccccccccccccccccccccc\n 5 function calls in 0.000 seconds\n Ordered by: cumulative time\n ncalls tottime percall cumtime percall filename:lineno(function)\n 1 0.000 0.000 0.000 0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\cProfile.py:106(runcall)\n 1 0.000 0.000 0.000 0.000 <ipython-input-2-be27ae79f5ac>:54(testest3)\n 1 0.000 0.000 0.000 0.000 {built-in method builtins.print}\n 1 0.000 0.000 0.000 0.000 {method 'enable' of '_lsprof.Profiler' objects}\n 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}\nxxxxxxxxxxxxxxx\nk2=2001\n<----------------------------- k2\n\n\n```\n\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Decorator for pstats",
"version": "0.10",
"split_keywords": [
"pstats"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ebf0f2e8b35fdaac42700b2be3d63dfa",
"sha256": "eab126f948b5f568106c8f7af8415a8b11150ce1115b725ea890897afb0df34d"
},
"downloads": -1,
"filename": "pstatsdecorator-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebf0f2e8b35fdaac42700b2be3d63dfa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6951,
"upload_time": "2022-12-29T08:51:14",
"upload_time_iso_8601": "2022-12-29T08:51:14.473747Z",
"url": "https://files.pythonhosted.org/packages/50/06/ee08fc7a0543460fd845be2d58fe3c4d0480f8504651e420374c735d6a73/pstatsdecorator-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "fb487ad68454e23b05896b2b1ff994a3",
"sha256": "4104c6fd57087e85b12d5979bf3e909c48b1f798dc2277f7adec7853654a6498"
},
"downloads": -1,
"filename": "pstatsdecorator-0.10.tar.gz",
"has_sig": false,
"md5_digest": "fb487ad68454e23b05896b2b1ff994a3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5912,
"upload_time": "2022-12-29T08:51:15",
"upload_time_iso_8601": "2022-12-29T08:51:15.898344Z",
"url": "https://files.pythonhosted.org/packages/2b/ad/918b372e17ed7bab94d5292fbc1ac3e47ef57255ea983e485495af75f7df/pstatsdecorator-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-29 08:51:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "hansalemaos",
"github_project": "pstatsdecorator",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pstatsdecorator"
}