{"id":32127817,"url":"https://github.com/rafaelha/vscode-flamegraph","last_synced_at":"2025-10-21T00:36:44.402Z","repository":{"id":262540988,"uuid":"886937739","full_name":"rafaelha/vscode-flamegraph","owner":"rafaelha","description":"py-spy and memray profiler integration for VS Code","archived":false,"fork":false,"pushed_at":"2025-09-26T21:39:09.000Z","size":44407,"stargazers_count":26,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-26T23:28:53.870Z","etag":null,"topics":["flamegraph","jupyer-notebook","line-profiler","memory","memray","performance-analysis","profiling","py-spy","python","vscode-extension"],"latest_commit_sha":null,"homepage":"https://marketplace.visualstudio.com/items?itemName=rafaelha.vscode-flamegraph","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafaelha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-11T22:02:42.000Z","updated_at":"2025-09-26T21:39:13.000Z","dependencies_parsed_at":"2024-12-18T09:22:49.086Z","dependency_job_id":"057177bd-949f-4c38-9625-ffb68eccde5c","html_url":"https://github.com/rafaelha/vscode-flamegraph","commit_stats":null,"previous_names":["rafaelha/vscode-flamegraph"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rafaelha/vscode-flamegraph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelha%2Fvscode-flamegraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelha%2Fvscode-flamegraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelha%2Fvscode-flamegraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelha%2Fvscode-flamegraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaelha","download_url":"https://codeload.github.com/rafaelha/vscode-flamegraph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelha%2Fvscode-flamegraph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280184439,"owners_count":26286833,"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","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["flamegraph","jupyer-notebook","line-profiler","memory","memray","performance-analysis","profiling","py-spy","python","vscode-extension"],"created_at":"2025-10-21T00:36:42.828Z","updated_at":"2025-10-21T00:36:44.396Z","avatar_url":"https://github.com/rafaelha.png","language":"TypeScript","readme":"###  py-spy and memray integration for VS Code\n[![Like this? Leave a ⭐](https://img.shields.io/github/stars/rafaelha/vscode-flamegraph?style=flat\u0026label=Like%20this%3F%20Leave%20a%20%E2%AD%90\u0026color=yellow\u0026logo=github)](https://github.com/rafaelha/vscode-flamegraph)\n\n\nProfiling your code with *Flamegraph* is simple.\n\nIn Jupyter notebooks, click the 🔥 button above the cell you want to profile:\n\n![Profile jupyter notebook](https://github.com/rafaelha/vscode-flamegraph/blob/a0f7c296fa3d9fa55fba485436ed31573d02c86f/assets/screenshot-notebook.png?raw=true)\n\n\n\nFor Python scripts, select `Flamegraph: Profile file with py-spy` from the dropdown menu next to the ▶️ icon:\n\n\n![Profile python script](https://github.com/rafaelha/vscode-flamegraph/blob/a0f7c296fa3d9fa55fba485436ed31573d02c86f/assets/screenshot-python.png?raw=true)\n\nYour code will be profiled with [py-spy](https://github.com/benfred/py-spy). You can interrupt the profiling anytime with `Ctrl+C`. The profiling results are visualized next to your code and as a flamegraph in a new tab.\n\nTo hide the inline annotations, right-click anywhere in the editor and select `Flamegraph: Toggle Inline Profile`.\n\nAdditionally, on Linux, macOS, and within WSL or Docker containers, basic memory profiling is supported with [memray](https://github.com/bloomberg/memray). Use the command palette in VS Code (Cmd+Shift+P/Ctrl+Shift+P) to select `Flamegraph: Profile file with memray` or `Flamegraph: Profile cell with memray`. This will show memory allocations for the time snapshot where heap memory usage reached its maximum.\n\n![Profile python script with memray](https://github.com/rafaelha/vscode-flamegraph/blob/d65a08926137a2e7b8a01cd120f61482cc5c423d/assets/screenshot-memray.png?raw=true)\n\n## Usage\n\nThe extension visualizes profiling data in two ways:\n\n1. **Inline Code Annotations**: Shows timing or memory information for each function scope, with colors indicating the scope level.\n\n2. **Interactive Flamegraph**: Displays the complete call stack of your profiled code (see [this article](https://www.brendangregg.com/flamegraphs.html) about flamegraphs). You can:\n   - Click any element to zoom in\n   - Click parent elements to zoom out\n   - `Cmd+Click` (Mac) or `Ctrl+Click` (Windows/Linux) to jump into the code.\n   - Click legend elements to filter the flamegraph by module.\n   - Click the `\u003c/\u003e` button in the legend to toggle between code or function display.\n\nThe flamegraph and inline annotations are linked -\nwhen you select an element in the flamegraph, the corresponding inline annotations are filtered.\n\n![Interactive flamegraph demo](https://github.com/rafaelha/vscode-flamegraph/blob/main/assets/demo-interactive-flame-graph.gif?raw=true)\n\n## Useful Commands\n\nOpen the Command Palette (Command+Shift+P on Mac and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:\n\n| Command | Description |\n|---------|-------------|\n| `Flamegraph: Profile file with py-spy` | Profile the active file with py-spy and display the results |\n| `Flamegraph: Toggle Inline Profile` | Show or hide the inline annotations. This is also accessible via right-click on the editor. |\n| `Flamegraph: Show` | Open a new tab showing the flamegraph |\n| `Flamegraph: Attach py-spy to running process` | Attach py-spy to a running process and display the results. The extension will ask for a Process ID (PID) to attach to |\n| `Flamegraph: Profile all unit tests with pytest` | Run and profile the `pytest` command |\n| `Flamegraph: Profile unit tests in file with pytest` | Run and profile the `pytest` command on the active file |\n| `Flamegraph: Show py-spy top` | Displays a top like view of functions consuming CPU using py-spy |\n| `Flamegraph: Load Profile` | Load a profile from a file. You may also right-click on `.pyspy` or `.memray` files in the file explorer and select `Flamegraph: Load Profile`. |\n\n\nFor memory profiling with `memray`, use the following commands. Note that memray is [not supported](https://bloomberg.github.io/memray/supported_environments.html#supported-operating-systems) on Windows. On Windows, you can still use the extension within Windows Subsystem for Linux (WSL) or [Docker containers](https://bloomberg.github.io/memray/attach.html#debugger-privileges).\n\n| Command | Description |\n|---------|-------------|\n| `Flamegraph: Profile file with memray` | Profile the active file with memray and display the results |\n| `Flamegraph: Profile cell with memray` | Profile the active cell with memray and display the results |\n| `Flamegraph: Profile notebook with memray` | Profile the entire notebook with memray and display the results |\n| `Flamegraph: Attach memray to running process` | Attach memray to a running process and display the results. The extension will ask for a Process ID (PID) to attach to |\n| `Flamegraph: Attach memray live view to running process` | Attach memray live view to a running process for real-time memory profiling |\n\n## Using the Command Line\n\nYou can run py-spy directly from the command line. The extension will watch for changes to the files `profile.pyspy` and `profile.memray` in the current workspace and load the profile when it changes.\n\nTo profile a script, use the command:\n```bash\npy-spy record --output profile.pyspy --format raw --full-filenames -- python my_script.py\n```\nHere, it is important to specify the output file as `profile.pyspy` and the format as `raw`. For best results, use the `--full-filenames` flag to allow the extension to resolve file names in the flamegraph. For additional configuration options, see the [py-spy documentation](https://github.com/benfred/py-spy) or run `py-spy record --help`.\n\n\n## Using VS Code Tasks\n\nThe extension allows you to run the py-spy profiler from VS Code's task system. This makes it easy to integrate profiling into your workflow and configure custom tasks.\n\n### Using the Task Explorer\n\n1. Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS)\n2. Type \"Tasks: Run Task\" and select \"flamegraph\"\n3. Choose one of the available flamegraph tasks or click the gear icon to customize the task.\n\n### Creating a tasks.json File\n\nYou can also create a `tasks.json` file in your `.vscode` folder to customize the tasks. This is currently only supported for py-spy profiling. For example, the task\n\n\n\n```json\n{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"type\": \"flamegraph\",\n\t\t\t\"file\": \"${file}\",\n\t\t\t\"args\": [\n\t\t\t\t\"--my-custom-arg1\",\n\t\t\t\t\"value\",\n\t\t\t],\n\t\t\t\"label\": \"Flamegraph: My custom profile command\"\n\t\t}\n\t]\n}\n```\n\nwill execute the command\n\n```py-spy \u003cpy-spy-args\u003e -- python \u003ccurrent-file\u003e --my-custom-arg1 value```.\n\nOr, you can profile a specific unit test (via `pytest`) with the following task definition:\n\n\n```json\n{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"type\": \"flamegraph\",\n\t\t\t\"args\": [\n\t\t\t\t\"-m\",\n\t\t\t\t\"pytest\",\n\t\t\t\t\"path/to/my_test_file.py::test_my_function\",\n\t\t\t],\n\t\t\t\"subprocesses\": false,\n\t\t\t\"native\": true,\n\t\t\t\"subprocesses\": false,\n\t\t\t\"gil\": false,\n\t\t\t\"idle\": false,\n\t\t\t\"nonblocking\": false,\n\t\t\t\"label\": \"Flamegraph: Profile my_test_function\"\n\t\t}\n\t]\n}\n```\n\nNotice that we additionally enabled the py-spy native option. This will execute the command\n\n```py-spy \u003cpy-spy-args\u003e --native -- python -m pytest path/to/my_test_file.py::test_my_function```\n\n\n\n### Setting custom keyboard shortcuts\n\nYou can bind tasks to keyboard shortcuts by adding entries to your `keybindings.json` file:\n\n1. Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS)\n2. Type \"Preferences: Open Keyboard Shortcuts (JSON)\" and select it\n3. Add entries like the following:\n\n```json\n{\n    \"key\": \"ctrl+shift+enter\",\n    \"command\": \"workbench.action.tasks.runTask\",\n    \"args\": \"Flamegraph: My custom profile command\"\n}\n```\n\n## Contributing\n\n### Development\n1. Clone the repository\n```bash\ngit clone https://github.com/rafaelha/vscode-flamegraph.git\n```\n\n2. Install dependencies for both the extension and the flamegraph-react UI\n```bash\nnpm run install:all\n```\n3. Build webview UI source code, i.e. the flamegraph react component\n```bash\nnpm run build:webview\n```\n\n4. In VS Code, press `F5` to open a new Extension Development Host window.\n\n\n\n\n### TODO\n\n- [ ] Switch to `speedscope` format. Eventually, this extension should be refactored to be compatible with all profilers that output `speedscope` files. Currently, only left-heavy profile view is supported.\n- [ ] Unit tests\n- [x] Performance tests\n- [x] Option to filter the flamegraph by module.\n- [ ] Refactor flamegraph react component. Currently, the whole graph is recomputed on every mouse hover event. We could consider using `speedscope` npm package to render the flamegraph.\n- [x] Memray memory profiles\n- [ ] Select sampling interval\n- [x] Jupyter notebook profiling.\n- [ ] Inverted flamegraphs","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelha%2Fvscode-flamegraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaelha%2Fvscode-flamegraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelha%2Fvscode-flamegraph/lists"}