[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-70751":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":40,"readmeContent":41,"aiSummary":42,"trendingCount":16,"starSnapshotCount":16,"syncStatus":43,"lastSyncTime":44,"discoverSource":45},70751,"scalene","plasma-umass\u002Fscalene","plasma-umass","Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals","",null,"Python",13448,435,83,150,0,3,15,36,9,42.92,"Apache License 2.0",false,"master",true,[27,28,29,30,31,32,33,34,35,36,37,38,39,5],"cpu","cpu-profiling","gpu","gpu-programming","memory-allocation","memory-consumption","performance-analysis","performance-cpu","profiler","profiles-memory","profiling","python","python-profilers","2026-06-12 02:02:42","![scalene](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fraw\u002Fmaster\u002Fdocs\u002Fscalene-icon-white.png)\n\n# Scalene: a Python CPU+GPU+memory profiler with AI-powered optimization proposals\n\nby [Emery Berger](https:\u002F\u002Femeryberger.com), [Sam Stern](https:\u002F\u002Fsamstern.me\u002F), and [Juan Altmayer Pizzorno](https:\u002F\u002Fgithub.com\u002Fjaltmayerpizzorno).\n\n[![Scalene community Slack](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fraw\u002Fmaster\u002Fdocs\u002Fimages\u002Fslack-logo.png)](https:\u002F\u002Fjoin.slack.com\u002Ft\u002Fscaleneprofil-jge3234\u002Fshared_invite\u002Fzt-110vzrdck-xJh5d4gHnp5vKXIjYD3Uwg)[Scalene community Slack](https:\u002F\u002Fjoin.slack.com\u002Ft\u002Fscaleneprofil-jge3234\u002Fshared_invite\u002Fzt-110vzrdck-xJh5d4gHnp5vKXIjYD3Uwg)\n\n[![PyPI Latest Release](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fscalene.svg)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fscalene\u002F)[![Anaconda-Server Badge](https:\u002F\u002Fimg.shields.io\u002Fconda\u002Fv\u002Fconda-forge\u002Fscalene)](https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fscalene) [![Downloads](https:\u002F\u002Fstatic.pepy.tech\u002Fbadge\u002Fscalene)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fscalene)[![Anaconda downloads](https:\u002F\u002Fimg.shields.io\u002Fconda\u002Fd\u002Fconda-forge\u002Fscalene?logo=conda)](https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fscalene) [![Downloads](https:\u002F\u002Fstatic.pepy.tech\u002Fbadge\u002Fscalene\u002Fmonth)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fscalene) ![Python versions](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fscalene.svg?style=flat-square)[![Visual Studio Code Extension version](https:\u002F\u002Fimg.shields.io\u002Fvisual-studio-marketplace\u002Fv\u002Femeryberger.scalene?logo=visualstudiocode)](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=EmeryBerger.scalene) ![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fplasma-umass\u002Fscalene) [![GitHub Repo stars](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fplasma-umass\u002Fscalene?style=social)](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene)\n\n\n![Ozsvald tweet](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fraw\u002Fmaster\u002Fdocs\u002FOzsvald-tweet.png)\n\n(tweet from Ian Ozsvald, author of [_High Performance Python_](https:\u002F\u002Fsmile.amazon.com\u002FHigh-Performance-Python-Performant-Programming\u002Fdp\u002F1492055026\u002Fref=sr_1_1?crid=texbooks))\n\n![Semantic Scholar success story](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fraw\u002Fmaster\u002Fdocs\u002Fsemantic-scholar-success.png)\n\n[_Python Profiler Links to AI to Improve Code Scalene identifies inefficiencies and asks GPT-4 for suggestions_](https:\u002F\u002Fspectrum.ieee.org\u002Fpython-programming), IEEE Spectrum\n\n[Episode 172: Measuring Multiple Facets of Python Performance With Scalene](https:\u002F\u002Frealpython.com\u002Fpodcasts\u002Frpp\u002F172\u002F), The Real Python podcast\n\n***Scalene web-based user interface:*** [https:\u002F\u002Fscalene-gui.github.io\u002Fscalene-gui\u002F](https:\u002F\u002Fscalene-gui.github.io\u002Fscalene-gui\u002F)\n\n## About Scalene\n\nScalene is a high-performance CPU, GPU *and* memory profiler for\nPython that does a number of things that other Python profilers do not\nand cannot do.  It runs orders of magnitude faster than many other\nprofilers while delivering far more detailed information. It is also\nthe first profiler ever to incorporate AI-powered proposed\noptimizations.\n\n### AI-powered optimization suggestions\n\n> **Note**\n>\n> For optimization suggestions, Scalene supports a variety of AI providers, including [Amazon Bedrock](https:\u002F\u002Faws.amazon.com\u002Fbedrock), [Microsoft Azure](https:\u002F\u002Fazure.microsoft.com\u002Fen-us\u002F), [OpenAI](https:\u002F\u002Fopenai.com), and local models via [Ollama](https:\u002F\u002Follama.com\u002F). To enable AI-powered optimization suggestions from AI providers, you need to select a provider and, if needed, enter your credentials, in the box under \"AI Optimization Options\".\n>\n> \u003Cimg width=\"607\" height=\"316\" alt=\"AI Optimization Options\" src=\"https:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F3c803237-063f-481a-8624-5c1d7f205c8a\" \u002F>\n\n\nOnce you've entered your key and any other needed data, click on the lightning bolt (⚡) beside any line or the explosion (💥) for an entire region of code to generate a proposed optimization. Click on a proposed optimization to copy it to the clipboard.\n\n\u003Cimg width=\"571\" alt=\"example proposed optimization\" src=\"https:\u002F\u002Fuser-images.githubusercontent.com\u002F1612723\u002F211639968-37cf793f-3290-43d1-9282-79e579558388.png\">\n\nYou can click as many times as you like on the lightning bolt or explosion, and it will generate different suggested optimizations. Your mileage may vary, but in some cases, the suggestions are quite impressive (e.g., order-of-magnitude improvements). \n  \n### Quick Start\n\n#### Installing Scalene:\n\n```console\npython3 -m pip install -U scalene\n```\n\nor\n\n```console\nconda install -c conda-forge scalene\n```\n\n#### Using Scalene:\n\nAfter installing Scalene, you can use Scalene at the command line, or as a Visual Studio Code extension.\n\n\u003Cdetails>\n  \u003Csummary>\n    Using the Scalene VS Code Extension:\n  \u003C\u002Fsummary>\n  \n\nFirst, install \u003Ca href=\"https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=EmeryBerger.scalene\">the Scalene extension from the VS Code Marketplace\u003C\u002Fa> or by searching for it within VS Code by typing Command-Shift-X (Mac) or Ctrl-Shift-X (Windows). Once that's installed, click Command-Shift-P or Ctrl-Shift-P to open the \u003Ca href=\"https:\u002F\u002Fcode.visualstudio.com\u002Fdocs\u002Fgetstarted\u002Fuserinterface\">Command Palette\u003C\u002Fa>. Then select \u003Cb>\"Scalene: AI-powered profiling...\"\u003C\u002Fb> (you can start typing Scalene and it will pop up if it's installed). Run that and, assuming your code runs for at least a second, a Scalene profile will appear in a webview.\n  \n\u003Cimg width=\"734\" alt=\"Screenshot 2023-09-20 at 7 09 06 PM\" src=\"https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fassets\u002F1612723\u002F7e78e3d2-e649-4f02-86fd-0da2a259a1a4\">\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nCommonly used command-line options:\n\u003C\u002Fsummary>\n\nScalene uses a verb-based command structure with two main commands: `run` (to profile) and `view` (to display results).\n\n```console\n# Profile a program (saves to scalene-profile.json)\nscalene run your_prog.py\npython3 -m scalene run your_prog.py              # equivalent alternative\n\n# View a profile\nscalene view                                     # open profile in browser\nscalene view --cli                               # view in terminal\nscalene view --html                              # save to scalene-profile.html\nscalene view --standalone                        # save as self-contained HTML\n\n# Common profiling options\nscalene run --cpu-only your_prog.py              # only profile CPU (faster)\nscalene run -o results.json your_prog.py         # custom output filename\nscalene run -c config.yaml your_prog.py          # load options from config file\n\n# Pass arguments to your program (use --- separator)\nscalene run your_prog.py --- --arg1 --arg2\n\n# Get help\nscalene --help                                   # main help\nscalene run --help                               # profiling options\nscalene run --help-advanced                      # advanced profiling options\nscalene view --help                              # viewing options\n```\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nUsing a YAML configuration file:\n\u003C\u002Fsummary>\n\nYou can store Scalene options in a YAML configuration file and load them with `-c` or `--config`:\n\n```console\nscalene run -c scalene.yaml your_prog.py\n```\n\nExample `scalene.yaml`:\n\n```yaml\n# Output options\noutfile: my-profile.json\n\n# Profiling mode (use only one)\ncpu-only: true              # CPU profiling only (faster)\n# gpu: true                 # Include GPU profiling\n# memory: true              # Include memory profiling\n\n# Filter what gets profiled\nprofile-only: \"mypackage,mymodule\"    # Only profile these paths\nprofile-exclude: \"tests,venv\"          # Exclude these paths\nprofile-all: false                     # Profile all code, not just target\n\n# Performance tuning\ncpu-percent-threshold: 1     # Min CPU% to report (default: 1)\ncpu-sampling-rate: 0.01      # Sampling interval in seconds\nmalloc-threshold: 100        # Min allocations to report\n\n# Other options\nuse-virtual-time: false      # Measure CPU time only (not I\u002FO)\nstacks: true                 # Collect stack traces (default: true)\nmemory-leak-detector: true   # Detect likely memory leaks\n```\n\nCommand-line arguments override config file settings.\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nUsing Scalene programmatically in your code:\n\u003C\u002Fsummary>\n\nInvoke using `scalene` as above and then:\n\n```Python\nfrom scalene import scalene_profiler\n\n# Turn profiling on\nscalene_profiler.start()\n\n# your code\n\n# Turn profiling off\nscalene_profiler.stop()\n```\n\n```Python\nfrom scalene.scalene_profiler import enable_profiling\n\nwith enable_profiling():\n    # do something\n```\n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nUsing Scalene to profile only specific functions via \u003Ccode>@profile\u003C\u002Fcode>:\n\u003C\u002Fsummary>\n\nJust preface any functions you want to profile with the `@profile` decorator and run it with Scalene:\n\n```Python\n# do not import profile!\n\n@profile\ndef slow_function():\n    import time\n    time.sleep(3)\n```\n\n\u003C\u002Fdetails>\n\n#### Web-based GUI\n\nScalene has both a CLI and a web-based GUI [(demo here)](https:\u002F\u002Fscalene-gui.github.io\u002Fscalene-gui\u002F).\n\nBy default, once Scalene has profiled your program, it will open a\ntab in a web browser with an interactive user interface (all processing is done\nlocally). Hover over bars to see breakdowns of CPU and memory\nconsumption, and click on underlined column headers to sort the\ncolumns. The GUI works fully offline with no internet connection required.\n\nUse `scalene view --standalone` to generate a completely self-contained HTML file with all assets embedded, perfect for sharing or archiving.\n\n[![Scalene web GUI](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fscalene-gui-example.png)](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fscalene-gui-example-full.png)\n\n\n## Scalene Overview\n\n### Scalene talk (PyCon US 2021)\n\n[This talk](https:\u002F\u002Fyoutu.be\u002F5iEf-_7mM1k) presented at PyCon 2021 walks through Scalene's advantages and how to use it to debug the performance of an application (and provides some technical details on its internals). We highly recommend watching this video!\n\n[![Scalene presentation at PyCon 2021](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fscalene-video-img.png)](https:\u002F\u002Fyoutu.be\u002F5iEf-_7mM1k \"Scalene presentation at PyCon 2021\")\n\n### Fast and Accurate\n\n- Scalene is **_fast_**. It uses sampling instead of instrumentation or relying on Python's tracing facilities. Its overhead is typically no more than 10-20% (and often less).\n\n- Scalene is **accurate**. We tested CPU profiler accuracy and found that Scalene is among the most accurate profilers, correctly measuring time taken.\n\n![Profiler accuracy](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fraw\u002Fmaster\u002Fdocs\u002Fcpu-accuracy-comparison.png)\n\n- Scalene performs profiling **_at the line level_** _and_ **_per function_**, pointing to the functions and the specific lines of code responsible for the execution time in your program.\n\n### CPU profiling\n\n- Scalene **separates out time spent in Python from time in native code** (including libraries). Most Python programmers aren't going to optimize the performance of native code (which is usually either in the Python implementation or external libraries), so this helps developers focus their optimization efforts on the code they can actually improve.\n- Scalene **highlights hotspots** (code accounting for significant percentages of CPU time or memory allocation) in red, making them even easier to spot.\n- Scalene also separates out **system time**, making it easy to find I\u002FO bottlenecks.\n\n### GPU profiling\n\n- Scalene reports **GPU time** (currently limited to NVIDIA-based systems).\n\n### Memory profiling\n\n- Scalene **profiles memory usage**. In addition to tracking CPU usage, Scalene also points to the specific lines of code responsible for memory growth. It accomplishes this via an included specialized memory allocator.\n- Scalene separates out the percentage of **memory consumed by Python code vs. native code**.\n- Scalene produces **_per-line_ memory profiles**.\n- Scalene **identifies lines with likely memory leaks**.\n- Scalene **profiles _copying volume_**, making it easy to spot inadvertent copying, especially due to crossing Python\u002Flibrary boundaries (e.g., accidentally converting `numpy` arrays into Python arrays, and vice versa).\n\n### Async profiling\n\nScalene attributes wall-clock **`await` time** to the exact line where the\ncoroutine is suspended, alongside the **mean** and **peak** number of\ncoroutines waiting concurrently on that line. This makes it easy to spot\nserialized I\u002FO (long `await`, low concurrency) versus genuinely-parallel\nfan-out (long `await`, high concurrency). The await column in the GUI\ndraws a clockwise pie wedge per line; bigger wedges mean more time spent\nsuspended on that `await`.\n\nAsync profiling is on by default; pass `--no-async` to disable it.\nOverhead on non-async code is negligible (one frozenset lookup per\nsignal, and `sys.monitoring` callbacks never fire when no coroutines\nare running).\n\n![Per-line await time pies](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fscalene-async-pies.png)\n\n### Stack views (call stacks, memory flame chart, timeline)\n\nWhen Scalene is run with `--stacks` (the default — pass `--no-stacks`\nto disable), it captures **stitched Python + native (C\u002FC++) stacks** at\nevery CPU and allocation sample, and presents them three ways in the\nGUI:\n\n- **Call stacks** — a flame chart of the top stitched stacks across the\n  whole run. Python frames are clickable to jump to source. Native\n  frames are demangled and shown alongside Python frames in the same\n  picture, so you can see exactly which library call is on the hot path.\n\n  ![Call stacks flame chart](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fscalene-call-stacks.png)\n\n- **Memory stacks** — a memory-weighted flame chart where frame width is\n  proportional to **MB allocated** along that call path (not sample\n  count). Useful for finding which call paths are responsible for a\n  program's memory footprint, especially when allocations come from deep\n  inside a library.\n\n  ![Memory stacks flame chart](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fscalene-memory-stacks.png)\n\n- **Timeline** — an icicle\u002Ftime-series view of the same stitched stacks\n  laid out left-to-right by wall-clock time, with tracks at the top\n  marking GC, I\u002FO, and GIL activity. Coroutines appear as `[await]\n  task_name` frames so you can see when each task ran versus waited.\n\n  ![Timeline view](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fscalene-timeline.png)\n\nAll three views are collapsible and resizable; expand them via the\ndisclosure triangles at the bottom of the GUI.\n\n### Other features\n\n- Scalene can produce **reduced profiles** (via `--reduced-profile`) that only report lines that consume more than 1% of CPU or perform at least 100 allocations.\n- Scalene supports `@profile` decorators to profile only specific functions.\n- When Scalene is profiling a program launched in the background (via `&`), you can **suspend and resume profiling**.\n- Scalene supports **free-threaded Python (3.13t \u002F 3.14t)** with full\n  CPU + memory profiling.\n- Scalene's GUI is **fully offline \u002F air-gapped** — assets are vendored\n  and `scalene view --standalone` produces a single self-contained HTML\n  file you can email or archive.\n\n# Comparison to Other Profilers\n\n## Performance and Features\n\nBelow is a table comparing the **performance and features** of various profilers to Scalene.\n\n![Performance and feature comparison](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fprofiler-comparison.png)\n\n- **Slowdown**: the slowdown when running a benchmark from the Pyperformance suite. Green means less than 2x overhead. Scalene's overhead is just a 35% slowdown.\n\nScalene has all of the following features, many of which only Scalene supports:\n\n- **Lines or functions**: does the profiler report information only for entire functions, or for every line -- Scalene does both.\n- **Unmodified Code**: works on unmodified code.\n- **Threads**: supports Python threads.\n- **Multiprocessing**: supports use of the `multiprocessing` library -- _Scalene only_\n- **Python vs. C time**: breaks out time spent in Python vs. native code (e.g., libraries) -- _Scalene only_\n- **System time**: breaks out system time (e.g., sleeping or performing I\u002FO) -- _Scalene only_\n- **Profiles memory**: reports memory consumption per line \u002F function\n- **GPU**: reports time spent on an NVIDIA GPU (if present) -- _Scalene only_\n- **Memory trends**: reports memory use over time per line \u002F function -- _Scalene only_\n- **Copy volume**: reports megabytes being copied per second -- _Scalene only_\n- **Detects leaks**: automatically pinpoints lines responsible for likely memory leaks -- _Scalene only_\n- **Async \u002F `await` profiling**: per-line wall-clock attribution of suspended coroutine time, with mean and peak concurrency -- _Scalene only_\n- **Stitched Python + native stacks**: flame charts and a wall-clock timeline that combine Python and C\u002FC++ frames in one picture -- _Scalene only_\n\n## Output\n\nIf you include the `--cli` option, Scalene prints annotated source code for the program being profiled\n(as text, JSON (`--json`), or HTML (`--html`)) and any modules it\nuses in the same directory or subdirectories (you can optionally have\nit `--profile-all` and only include files with at least a\n`--cpu-percent-threshold` of time).  Here is a snippet from\n`pystone.py`.\n\n![Example profile](https:\u002F\u002Fraw.githubusercontent.com\u002Fplasma-umass\u002Fscalene\u002Fmaster\u002Fdocs\u002Fimages\u002Fsample-profile-pystone.png)\n\n* **Memory usage at the top**: Visualized by \"sparklines\", memory consumption over the runtime of the profiled code.\n* **\"Time Python\"**: How much time was spent in Python code.\n* **\"native\"**: How much time was spent in non-Python code (e.g., libraries written in C\u002FC++).\n* **\"system\"**: How much time was spent in the system (e.g., I\u002FO).\n* **\"GPU\"**: (not shown here) How much time spent on the GPU, if your system has an NVIDIA GPU installed.\n* **\"Memory Python\"**: How much of the memory allocation happened on the Python side of the code, as opposed to in non-Python code (e.g., libraries written in C\u002FC++).\n* **\"net\"**: Positive net memory numbers indicate total memory allocation in megabytes; negative net memory numbers indicate memory reclamation.\n* **\"timeline \u002F %\"**: Visualized by \"sparklines\", memory consumption generated by this line over the program runtime, and the percentages of total memory activity this line represents.\n* **\"Copy (MB\u002Fs)\"**: The amount of megabytes being copied per second (see \"About Scalene\").\n\n##  Scalene\n\nThe following command runs Scalene on a provided example program.\n\n```console\nscalene test\u002Ftestme.py\n```\n\n\u003Cdetails>\n \u003Csummary>\n  Click to see all Scalene's options (available by running with \u003Ccode>--help\u003C\u002Fcode>)\n \u003C\u002Fsummary>\n\n```console\n% scalene --help\nScalene: a high-precision CPU and memory profiler, version 1.5.51 (2025.01.29)\nhttps:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\n\ncommands:\n  run     Profile a Python program (saves to scalene-profile.json)\n  view    View an existing profile in browser or terminal\n\nexamples:\n  % scalene run your_program.py              # profile, save to scalene-profile.json\n  % scalene view                             # view scalene-profile.json in browser\n  % scalene view --cli                       # view profile in terminal\n\nin Jupyter, line mode:\n  %scrun [options] statement\n\nin Jupyter, cell mode:\n  %%scalene [options]\n   your code here\n\n% scalene run --help\nProfile a Python program with Scalene.\n\nexamples:\n  % scalene run prog.py                 # profile, save to scalene-profile.json\n  % scalene run -o my.json prog.py      # save to custom file\n  % scalene run --cpu-only prog.py      # profile CPU only (faster)\n  % scalene run -c scalene.yaml prog.py # load options from config file\n  % scalene run prog.py --- --arg       # pass args to program\n  % scalene run --help-advanced         # show advanced options\n\noptions:\n  -h, --help            show this help message and exit\n  -o, --outfile OUTFILE output file (default: scalene-profile.json)\n  --cpu-only            only profile CPU time (no memory\u002FGPU)\n  -c, --config FILE     load options from YAML config file\n  --help-advanced       show advanced options\n\n% scalene run --help-advanced\nAdvanced options for scalene run:\n\nbackground profiling:\n  Use --off to start with profiling disabled, then control it from another terminal:\n    % scalene run --off prog.py          # start with profiling off\n    % python3 -m scalene.profile --on  --pid \u003CPID>   # resume profiling\n    % python3 -m scalene.profile --off --pid \u003CPID>   # suspend profiling\n\noptions:\n  --profile-all         profile all code, not just the target program\n  --profile-only PATH   only profile files containing these strings (comma-separated)\n  --profile-exclude PATH exclude files containing these strings (comma-separated)\n  --profile-system-libraries  profile Python stdlib and installed packages (default: skip)\n  --gpu                 profile GPU time and memory\n  --memory              profile memory usage\n  --stacks              collect stack traces (default: on)\n  --no-stacks           disable stack-trace collection\n  --profile-interval N  output profiles every N seconds (default: inf)\n  --use-virtual-time    measure only CPU time, not I\u002FO or blocking\n  --cpu-percent-threshold N  only report lines with at least N% CPU (default: 1%)\n  --cpu-sampling-rate N CPU sampling rate in seconds (default: 0.01)\n  --allocation-sampling-window N  allocation sampling window in bytes\n  --malloc-threshold N  only report lines with at least N allocations (default: 100)\n  --program-path PATH   directory containing code to profile\n  --memory-leak-detector  EXPERIMENTAL: report likely memory leaks\n  --on                  start with profiling on (default)\n  --off                 start with profiling off\n\n% scalene view --help\nView an existing Scalene profile.\n\nexamples:\n  % scalene view                    # open in browser\n  % scalene view --cli              # view in terminal\n  % scalene view --html             # save to scalene-profile.html\n  % scalene view --standalone       # save as self-contained HTML\n  % scalene view myprofile.json     # open specific profile in browser\n\noptions:\n  -h, --help     show this help message and exit\n  --cli          display profile in the terminal\n  --html         save to scalene-profile.html (no browser)\n  --standalone   save as self-contained HTML with all assets embedded\n  -r, --reduced  only show lines with activity (--cli mode)\n```\n\u003C\u002Fdetails>\n\n### Scalene with Jupyter\n\n\u003Cdetails>\n\u003Csummary>\nInstructions for installing and using Scalene with Jupyter notebooks\n\u003C\u002Fsummary>\n\n[This notebook](https:\u002F\u002Fnbviewer.jupyter.org\u002Fgithub\u002Fplasma-umass\u002Fscalene\u002Fblob\u002Fmaster\u002Fdocs\u002Fscalene-demo.ipynb) illustrates the use of Scalene in Jupyter.\n\nInstallation:\n\n```console\n!pip install scalene\n%load_ext scalene\n```\n\nLine mode:\n\n```console\n%scrun [options] statement\n```\n\nCell mode:\n\n```console\n%%scalene [options]\ncode...\ncode...\n```\n\u003C\u002Fdetails>\n\n## Installation\n\n\u003Cdetails open>\n\u003Csummary>Using \u003Ccode>pip\u003C\u002Fcode> (Mac OS X, Linux, Windows, and WSL2)\u003C\u002Fsummary>\n\nScalene is distributed as a `pip` package and works on Mac OS X, Linux (including Ubuntu in [Windows WSL2](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fwindows\u002Fwsl\u002Fwsl2-index)) and Windows platforms.\n\n> **Note for Windows users**\n>\n> Starting with Scalene 2.0, Windows supports full memory profiling. If you\n> encounter issues, ensure you have the [Visual C++ Redistributable](https:\u002F\u002Faka.ms\u002Fvs\u002F17\u002Frelease\u002Fvc_redist.x64.exe)\n> installed. If building from source, you will need Visual C++ Build Tools and CMake.\n>\n\nYou can install it as follows:\n```console\n  % pip install -U scalene\n```\n\nor\n```console\n  % python3 -m pip install -U scalene\n```\n\nYou may need to install some packages first.\n\nSee https:\u002F\u002Fstackoverflow.com\u002Fa\u002F19344978\u002F4954434 for full instructions for all Linux flavors.\n\nFor Ubuntu\u002FDebian:\n\n```console\n  % sudo apt install git python3-all-dev\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>Using \u003Ccode>conda\u003C\u002Fcode> (Mac OS X, Linux, Windows, and WSL2)\u003C\u002Fsummary>\n\n```console\n  % conda install -c conda-forge scalene\n```\n\nScalene is distributed as a `conda` package and works on Mac OS X, Linux (including Ubuntu in [Windows WSL2](https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fwindows\u002Fwsl\u002Fwsl2-index)) and Windows platforms.\n\n> **Note for Windows users**\n>\n> Starting with Scalene 2.0, Windows supports full memory profiling. If you\n> encounter issues, ensure you have the [Visual C++ Redistributable](https:\u002F\u002Faka.ms\u002Fvs\u002F17\u002Frelease\u002Fvc_redist.x64.exe)\n> installed.\n>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>On ArchLinux\u003C\u002Fsummary>\n\nYou can install Scalene on Arch Linux via the [AUR\npackage](https:\u002F\u002Faur.archlinux.org\u002Fpackages\u002Fpython-scalene-git\u002F). Use your favorite AUR helper, or\nmanually download the `PKGBUILD` and run `makepkg -cirs` to build. Note that this will place\n`libscalene.so` in `\u002Fusr\u002Flib`; modify the below usage instructions accordingly.\n\u003C\u002Fdetails>\n\n# Frequently Asked Questions\n\n\u003Cdetails>\n\u003Csummary>\nCan I use Scalene with PyTest?\n\u003C\u002Fsummary>\n\n**A:** Yes! You can run it as follows (for example):\n\n`scalene run -m pytest your_test.py`\n\nor\n\n`python3 -m scalene run -m pytest your_test.py` \n\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nIs there any way to get shorter profiles or do more targeted profiling?\n\u003C\u002Fsummary>\n\n**A:** Yes! There are several options:\n\n1. Use `--reduced-profile` to include only lines and files with memory\u002FCPU\u002FGPU activity.\n2. Use `--profile-only` to include only filenames containing specific strings (as in, `--profile-only foo,bar,baz`).\n3. Decorate functions of interest with `@profile` to have Scalene report _only_ those functions.\n4. Turn profiling on and off programmatically by importing Scalene profiler (`from scalene import scalene_profiler`) and then turning profiling on and off via `scalene_profiler.start()` and `scalene_profiler.stop()`. By default, Scalene runs with profiling on, so to delay profiling until desired, use the `--off` command-line option (`scalene run --off yourprogram.py`).\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nHow do I run Scalene in PyCharm?\n\u003C\u002Fsummary>\n\n**A:**  In PyCharm, you can run Scalene at the command line by opening the terminal at the bottom of the IDE and running a Scalene command (e.g., `scalene run \u003Cyour program>`). Then use `scalene view --html` to generate an HTML file (`scalene-profile.html`) that you can view in the IDE.\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\nHow do I use Scalene with Django?\n\u003C\u002Fsummary>\n\n**A:** Pass in the `--noreload` option (see https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fissues\u002F178).\n\u003C\u002Fdetails>\n\n\n\u003Cdetails>\n\u003Csummary>\nDoes Scalene work with gevent\u002FGreenlets?\n\u003C\u002Fsummary>\n\n**A:** Yes! Put the following code in the beginning of your program, or modify the call to `monkey.patch_all` as below:\n\n```python\nfrom gevent import monkey\nmonkey.patch_all(thread=False)\n```\n\u003C\u002Fdetails>\n\n\n\n\u003Cdetails>\n\u003Csummary>\nHow do I use Scalene with PyTorch on the Mac?\n\u003C\u002Fsummary>\n\n**A:** Scalene works with PyTorch version 1.5.1 on Mac OS X. There's a bug in newer versions of PyTorch (https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fpytorch\u002Fissues\u002F57185) that interferes with Scalene (discussion here: https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fissues\u002F110), but only on Macs.\n\u003C\u002Fdetails>\n\n# Technical Information\n\nFor details about how Scalene works, please see the following paper, which won the Jay Lepreau Best Paper Award at [OSDI 2023](https:\u002F\u002Fwww.usenix.org\u002Fconference\u002Fosdi23\u002Fpresentation\u002Fberger): [Triangulating Python Performance Issues with Scalene](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2212.07597). (Note that this paper does not include information about the AI-driven proposed optimizations.)\n\n\u003Cdetails>\n\u003Csummary>\nTo cite Scalene in an academic paper, please use the following:\n\u003C\u002Fsummary>\n\n```latex\n@inproceedings{288540,\nauthor = {Emery D. Berger and Sam Stern and Juan Altmayer Pizzorno},\ntitle = {Triangulating Python Performance Issues with {S}calene},\nbooktitle = {{17th USENIX Symposium on Operating Systems Design and Implementation (OSDI 23)}},\nyear = {2023},\nisbn = {978-1-939133-34-2},\naddress = {Boston, MA},\npages = {51--64},\nurl = {https:\u002F\u002Fwww.usenix.org\u002Fconference\u002Fosdi23\u002Fpresentation\u002Fberger},\npublisher = {USENIX Association},\nmonth = jul\n}\n```\n\u003C\u002Fdetails>\n\n\n# Success Stories\n\nIf you use Scalene to successfully debug a performance problem, please [add a comment to this issue](https:\u002F\u002Fgithub.com\u002Fplasma-umass\u002Fscalene\u002Fissues\u002F58)!\n\n\n# Acknowledgements\n\nLogo created by [Sophia Berger](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fsophia-berger\u002F).\n\nThis material is based upon work supported by the National Science\nFoundation under Grant No. 1955610. Any opinions, findings, and\nconclusions or recommendations expressed in this material are those of\nthe author(s) and do not necessarily reflect the views of the National\nScience Foundation.\n","Scalene 是一个高性能的 Python CPU、GPU 和内存分析工具，能够提供详细的性能分析，并结合 AI 技术提出优化建议。它不仅支持对 CPU 和 GPU 的性能进行深度剖析，还能够精确追踪内存使用情况，帮助开发者发现代码中的性能瓶颈和资源浪费问题。与其他 Python 分析工具相比，Scalene 在速度上有着显著优势，同时提供了更详尽的数据报告。此外，该工具还创新性地引入了基于 AI 的优化建议功能，为开发者提供改进代码的具体指导。适用于需要细致性能调优及资源管理的 Python 开发场景中，如大规模数据处理、机器学习模型训练等。",2,"2026-06-11 03:34:00","high_star"]