{"library":"pyprof2calltree","title":"pyprof2calltree","description":"pyprof2calltree is a Python utility that facilitates the visualization of profiling data collected with Python's standard `cProfile` module. It converts `cProfile` output into the calltree format, which can then be graphically analyzed using tools like KCachegrind or QCachegrind. The library, currently at version 1.4.5, is actively maintained with updates primarily focusing on Python version compatibility and minor improvements.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pyprof2calltree"],"cli":{"name":"pyprof2calltree","version":"usage: pyprof2calltree [-h] [-o output_file_path] [-i input_file_path] [-k]"}},"imports":["from pyprof2calltree import convert","from pyprof2calltree import visualize"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import cProfile\nimport os\nfrom pyprof2calltree import convert, visualize\n\ndef my_expensive_function():\n    total = 0\n    for i in range(1_000_000):\n        total += i * i\n    return total\n\ndef main_app_logic():\n    _ = my_expensive_function()\n    return \"Done profiling.\"\n\nprofiler = cProfile.Profile()\nprofiler.enable()\nmain_app_logic()\nprofiler.disable()\n\n# Option 1: Save to a file for later viewing\noutput_filename = 'profiling_results.kgrind'\nwith open(output_filename, 'w') as f:\n    convert(profiler.getstats(), f)\nprint(f\"Profiling data saved to {output_filename}. Open with kcachegrind {output_filename}\")\n\n# Option 2: Directly visualize (requires kcachegrind in PATH)\n# try:\n#     visualize(profiler.getstats())\n#     print(\"KCachegrind launched with profiling data.\")\n# except Exception as e:\n#     print(f\"Could not launch KCachegrind directly: {e}. Ensure it's installed and in your PATH.\")\n\n# Example of running a script directly and converting via command line:\n# 1. python -m cProfile -o my_app.prof your_script.py\n# 2. pyprof2calltree -i my_app.prof -o callgrind.out","lang":"python","description":"This quickstart demonstrates how to profile a Python function using `cProfile`, then convert the profiling data to the KCachegrind-compatible calltree format using `pyprof2calltree.convert`. The resulting file can be opened with KCachegrind or QCachegrind for interactive visualization. An alternative `visualize()` function can attempt to launch KCachegrind directly if it's in your system's PATH.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}