Skip to main content

Profiling for the xonsh shell based on hunter.

Project description

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.xunter
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.

Find function calls

xunter --no-rc -c 'echo 1' ++filter 'Q(filename_has="specs.py"),Q(function="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' ++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.xunter
# Run in another terminal to monitor the activity:
tail -f /tmp/1.xunter  # | 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.xunter
xunter2excel /tmp/22.xunter

Known issues

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

See also

  • xonsh-cheatsheet
  • xonsh-install
  • By putting import ipdb; ipdb.set_trace() into any place of code you can investigate the environment interactively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xunter-0.2.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

xunter-0.2.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file xunter-0.2.1.tar.gz.

File metadata

  • Download URL: xunter-0.2.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for xunter-0.2.1.tar.gz
Algorithm Hash digest
SHA256 665eb3ce3cd0bd17f787ba22c4f0bc7cd2979b38ad3b9679f21ce8251ecc72a4
MD5 541cf8c7e85476ac21e9fb14064a59f5
BLAKE2b-256 dcaa7bc9d021cfdbc1614ab35175911c7f4397495b0a70aa4876be8cd0ac31e7

See more details on using hashes here.

File details

Details for the file xunter-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: xunter-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for xunter-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b09289c6cba5c32c1bd1e6897e12043b85ae93c750bf4d216605e8bba408e942
MD5 2bcf76069676e70cda14eecea2f864d3
BLAKE2b-256 3e443d984cf18bba8dda10974305a36cb86524f71cf697c57af720ad8a08746a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page