Skip to main content

xunter is to profiling xonsh shell using hunter. Time tracking is on board.

If you like the idea click ⭐ on the repo and tweet.

Install

Install xunter into the environment where xonsh you want to trace resides.

pip install xunter
# or: pip install git+https://github.com/anki-code/xunter

Usage

Xunter is working as drop-in replacement of xonsh with additional arguments:

xonsh  --no-rc -c "2+2"
xunter --no-rc -c "2+2" ++depth-lt 5
#      ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
#            xonsh         xunter

Simple examples:

xunter --no-rc -c "2+2" ++depth-lt 10
xunter --no-rc ++depth-lt 5 ++output /tmp/22.xun
xunter --no-rc -c '2+2' ++filter 'Q(filename_endswith="main.py")'

To set ++filter read about filters and take a look into the cookbook. Use ./playground/trace.py to experiment with the tracing filters and understand how it works.

Trace xonsh in the current directory

mkdir -p ~/git/ && cd ~/git/
git clone git+https://github.com/xonsh/xonsh
cd xonsh
xunter --no-rc -c '1+1' ++cwd ++filter 'Q(filename_has="procs/")' ++output /tmp/out.xun
# Trace ./xonsh
# In another terminal:
tail -f /tmp/out.xun

Find function calls

xunter --no-rc -c 'echo 1' ++filter 'Q(filename_has="specs.py")' ++output /tmp/specs.xun
cat /tmp/specs.xun | grep run_subproc
# [...]/site-packages/xonsh/procs/specs.py:910:run_subproc 
#   <= xonsh/built_ins.py:206:subproc_captured_hiddenobject 
#   <= <string>:1:<module> <= xonsh/codecache.py:64:run_compiled_code 
#   <= xonsh/codecache.py:218:run_code_with_cache
#   <= xonsh/main.py:519:main_xonsh 
#   <= xonsh/main.py:470:main 
#   <= xunter/xunter:91:<module>
#   - time_sec=[0.1505]

# Don't forget about xonsh`s awesome macro call:
xunter --no-rc -c 'echo 1' ++printer call ++filter! Q(filename_has="specs.py"),Q(function="run_subproc")

Filter code from prompt-toolkit and unwanted libs

# These `filename` filters will be applied to the code that executed at the end.
# i.e. `filename="a.py"` will filter `a.py:func <= b.py:func <= c.py:func`
# but `c.py:func <= a.py:func <= b.py:func` case (`a.py` in the middle) wont be filtered.
filters = [
    '~Q(filename_has="prompt_toolkit/")',
    '~Q(filename_has="prompt/")',
    '~Q(filename_has="ptk_shell/")',
    '~Q(filename_has="pygments")',
    
    '~Q(filename_has="_distutils_hack")',
    '~Q(filename_has="lazyasd")',
    '~Q(filename_has="environ")',
    '~Q(filename_has="layout")',
]

xunter --no-rc  ++filter @(','.join(filters)) ++output /tmp/1.xun
# Run in another terminal to monitor the activity:
tail -f /tmp/1.xun  # | grep -i func

Time profiling

xunter --no-rc -c 'echo 1' ++time-sec-gt 0.1 ++depth-lt 2
# ... - time_sec=[1.3710]

Convert log to table

xunter --no-rc -c "2+2" ++depth-lt 10 ++printer stack ++output /tmp/22.xun
xunter2excel /tmp/22.xun

Known issues

If you see the unexpected exceptions try to install xonsh from the main branch first.

See also

Metadata

Release files for xunter 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xunter 0.2.3
File Size Uploaded Provenance Actions
xunter-0.2.3.tar.gz 7.2 kB Without provenance Details for xunter-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xunter 0.2.3
File Interpreter ABI Platform Actions
xunter-0.2.3-py3-none-any.whl Python 3 none any Details for xunter-0.2.3-py3-none-any.whl

Total release size: 15.1 kB

Release files / xunter-0.2.3.tar.gz

Download URL xunter-0.2.3.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6f4a926104ea1a5e26b00d3bdf3cff6dbd8e1bb38cd0cc2d0ac975eec06aa091
BLAKE2b-256 checksum
How to use checksums
edb0bf70dbf24bf1ed1efc36e2222e2a5be6f2bafc90db4cd23dd2bff9d8989d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / xunter-0.2.3-py3-none-any.whl

Download URL xunter-0.2.3-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89fd28d7fe39b02b3477bbb10ecf40cf0d91d6130334959a4994e79b2d244fae
BLAKE2b-256 checksum
How to use checksums
d1fe82179e19cdb4db882b0f2043edbb4b63a79f62801f12133f2640633237f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for xunter 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page