{"id":5229,"library":"flameprof","title":"Flameprof","description":"Flameprof is a Python library and command-line tool that generates interactive SVG flame graphs from `cProfile` statistics. It visualizes function call hierarchies and their CPU time consumption, offering a compact and understandable alternative to raw `cProfile` output or tools like `gprof2dot`. The current version is 0.4. Releases are sporadic, with major updates occurring infrequently.","status":"active","version":"0.4","language":"en","source_language":"en","source_url":"https://github.com/baverman/flameprof/","tags":["profiling","flamegraph","cprofile","performance","visualization"],"install":[{"cmd":"pip install flameprof","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Flameprof is primarily used as a command-line tool to process cProfile output files, rather than through direct Python imports for its core functionality.","symbol":"flameprof CLI","correct":"flameprof input.prof > output.svg"}],"quickstart":{"code":"# my_app.py\nimport cProfile\nimport time\n\ndef func_a():\n    time.sleep(0.1)\n\ndef func_b():\n    time.sleep(0.05)\n    func_a()\n\ndef main():\n    for _ in range(3):\n        func_b()\n    func_a()\n\n# Profile the application\nprofile_file = 'my_app.prof'\ncProfile.run('main()', profile_file)\n\n# To generate the flame graph, run in your terminal:\n# flameprof my_app.prof > my_app_flamegraph.svg\n# Then open my_app_flamegraph.svg in a web browser.","lang":"python","description":"First, create a Python script (`my_app.py`) that you wish to profile. Use Python's built-in `cProfile` module to run your application and save the profiling data to a `.prof` file. Then, use the `flameprof` command-line tool to convert this `.prof` file into an interactive SVG flame graph. Open the generated SVG file in a web browser to view the visualization."},"warnings":[{"fix":"Always invoke `flameprof` from your terminal or shell scripts after generating a cProfile output file.","message":"Flameprof is primarily a command-line utility. While it is a Python package, its main functionality is exposed via the `flameprof` executable after installation, not typically through direct Python `import` statements for generating flame graphs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your profiling data is in the `cProfile` format. If you need to profile other sources, consider converting their output to a compatible format or using different flame graph generators.","message":"The input file for `flameprof` must be a statistics file generated by Python's `cProfile` module (e.g., created with `cProfile.run('my_func()', 'output.prof')` or `python -m cProfile -o output.prof myscript.py`). It does not natively support output from other profiling tools like `perf` or `py-spy` without prior conversion.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If encountering these errors, try simplifying the profiled code or updating to the latest `flameprof` version. For critical debugging, consider alternative profiling visualization tools if the issue persists.","message":"Users have reported instances where `flameprof` can produce 'impossible stacks' or `ZeroDivisionError: float division by zero` when processing certain `cProfile` data, especially with unusual call patterns or highly optimized code.","severity":"gotcha","affected_versions":"0.3, 0.4"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}