{"id":13640026,"url":"https://github.com/anki-code/xunter","last_synced_at":"2025-03-21T08:31:20.315Z","repository":{"id":103643073,"uuid":"349765106","full_name":"anki-code/xunter","owner":"anki-code","description":"Tracing and profiling for the xonsh shell based on python-hunter.","archived":false,"fork":false,"pushed_at":"2025-02-21T09:30:23.000Z","size":72,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T04:24:07.610Z","etag":null,"topics":["debugger","python-hunter","tracer","xonsh","xonsh-dev"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anki-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"]}},"created_at":"2021-03-20T15:37:09.000Z","updated_at":"2025-02-21T09:30:27.000Z","dependencies_parsed_at":"2024-10-28T10:14:02.163Z","dependency_job_id":"8f631d4d-13cf-4aa4-9f2c-920ff08887b6","html_url":"https://github.com/anki-code/xunter","commit_stats":{"total_commits":11,"total_committers":2,"mean_commits":5.5,"dds":0.4545454545454546,"last_synced_commit":"4c89ccfa5a84cde52830235d5fb485c3c4c426c0"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxunter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxunter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxunter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anki-code%2Fxunter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anki-code","download_url":"https://codeload.github.com/anki-code/xunter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244122874,"owners_count":20401485,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugger","python-hunter","tracer","xonsh","xonsh-dev"],"created_at":"2024-08-02T01:01:07.141Z","updated_at":"2025-03-21T08:31:20.305Z","avatar_url":"https://github.com/anki-code.png","language":"Python","funding_links":["https://github.com/anki-code","https://www.buymeacoffee.com/xxh","https://github.com/xonsh/xonsh#the-xonsh-shell-community"],"categories":["See also"],"sub_categories":["pytest: xonsh not found"],"readme":"\u003cp align=\"center\"\u003e\n\u003cb\u003exunter\u003c/b\u003e is to tracing and profiling \u003ca href=\"https://xon.sh\"\u003exonsh shell\u003c/a\u003e using \u003ca href=\"https://github.com/ionelmc/python-hunter\"\u003ehunter\u003c/a\u003e. Time tracking is on board.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e  \nIf you like the idea click ⭐ on the repo and \u003ca href=\"https://twitter.com/intent/tweet?text=Trace%20xonsh%20shell%20code!\u0026url=https://github.com/anki-code/xunter\" target=\"_blank\"\u003etweet\u003c/a\u003e.\n\u003c/p\u003e\n\n## Install\n\nInstall xunter into the environment where xonsh you want to trace resides.\n\n```xsh\npip install xunter\n# or: pip install git+https://github.com/anki-code/xunter\n```\n\n## Usage\n\nXunter is working as drop-in replacement of `xonsh` with additional arguments:\n```xsh\nxonsh  --no-rc -c \"2+2\"\nxunter --no-rc -c \"2+2\" ++depth-lt 5\n#      ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^\n#            xonsh         xunter\n```\nSimple examples:\n```xsh\nxunter --no-rc -c \"2+2\" ++depth-lt 10\nxunter --no-rc ++depth-lt 5 ++output /tmp/22.xun\nxunter --no-rc -c '2+2' ++filter 'Q(filename_endswith=\"main.py\")'\n```\nTo set `++filter` read about [filters](https://python-hunter.readthedocs.io/en/latest/filtering.html) \nand take a look into the [cookbook](https://python-hunter.readthedocs.io/en/latest/cookbook.html).\nUse `./playground/trace.py` to experiment with the tracing filters and understand how it works.\n\n#### Trace xonsh in the current directory\n\n```xsh\nmkdir -p ~/git/ \u0026\u0026 cd ~/git/\ngit clone git+https://github.com/xonsh/xonsh\ncd xonsh\nxunter --no-rc -c '1+1' ++cwd ++filter 'Q(filename_has=\"procs/\")' ++output /tmp/out.xun\n# Trace ./xonsh\n# In another terminal:\ntail -f /tmp/out.xun\n```\n\n#### Find function calls\n\n```xsh\nxunter --no-rc -c 'echo 1' ++filter 'Q(filename_has=\"specs.py\")' ++output /tmp/specs.xun\ncat /tmp/specs.xun | grep run_subproc\n# [...]/site-packages/xonsh/procs/specs.py:910:run_subproc \n#   \u003c= xonsh/built_ins.py:206:subproc_captured_hiddenobject \n#   \u003c= \u003cstring\u003e:1:\u003cmodule\u003e \u003c= xonsh/codecache.py:64:run_compiled_code \n#   \u003c= xonsh/codecache.py:218:run_code_with_cache\n#   \u003c= xonsh/main.py:519:main_xonsh \n#   \u003c= xonsh/main.py:470:main \n#   \u003c= xunter/xunter:91:\u003cmodule\u003e\n#   - time_sec=[0.1505]\n\n# Don't forget about xonsh`s awesome macro call:\nxunter --no-rc -c 'echo 1' ++printer call ++filter! Q(filename_has=\"specs.py\"),Q(function=\"run_subproc\")\n```\n\n#### Filter code from prompt-toolkit and unwanted libs\n\n```xsh\n# These `filename` filters will be applied to the code that executed at the end.\n# i.e. `filename=\"a.py\"` will filter `a.py:func \u003c= b.py:func \u003c= c.py:func`\n# but `c.py:func \u003c= a.py:func \u003c= b.py:func` case (`a.py` in the middle) wont be filtered.\nfilters = [\n    '~Q(filename_has=\"prompt_toolkit/\")',\n    '~Q(filename_has=\"prompt/\")',\n    '~Q(filename_has=\"ptk_shell/\")',\n    '~Q(filename_has=\"pygments\")',\n    \n    '~Q(filename_has=\"_distutils_hack\")',\n    '~Q(filename_has=\"lazyasd\")',\n    '~Q(filename_has=\"environ\")',\n    '~Q(filename_has=\"layout\")',\n]\n\nxunter --no-rc  ++filter @(','.join(filters)) ++output /tmp/1.xun\n# Run in another terminal to monitor the activity:\ntail -f /tmp/1.xun  # | grep -i func\n```\n\n#### Time profiling\n\n```xsh\nxunter --no-rc -c 'echo 1' ++time-sec-gt 0.1 ++depth-lt 2\n# ... - time_sec=[1.3710]\n```\n\n#### Convert log to table\n\n```python\nxunter --no-rc -c \"2+2\" ++depth-lt 10 ++printer stack ++output /tmp/22.xun\nxunter2excel /tmp/22.xun\n```\n\n## Case studying\n\n* https://github.com/xonsh/xonsh/issues/5244#issuecomment-2183954013\n* https://github.com/xonsh/xonsh/pull/5361\n* https://github.com/xonsh/xonsh/issues/5317#issuecomment-2031846418\n\n## Known issues\n\nIf you see the unexpected exceptions try to install xonsh from the main branch first:\n```xsh\nxpip install -U --force-reinstall git+https://github.com/xonsh/xonsh\n# restart xonsh\nxunter ++output /tmp/xonsh.xun\n```\n\n## See also\n* [xonsh-cheatsheet](https://github.com/anki-code/xonsh-cheatsheet)\n* [xonsh-install](https://github.com/anki-code/xonsh-install)\n* [How to debug xonsh interactively in IDE PyCharm](https://github.com/xonsh/xonsh/issues/3090#issuecomment-2068043223)\n* By putting `import ipdb; ipdb.set_trace()` into any place of code you can investigate the environment interactively.\n* xonsh builtin [`trace`](https://xon.sh/aliases.html#trace)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxunter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanki-code%2Fxunter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanki-code%2Fxunter/lists"}