{"id":6868,"library":"scalene","title":"Scalene: CPU, GPU, and Memory Profiler","description":"Scalene is a high-resolution, low-overhead profiler for Python that analyzes CPU, GPU, and memory usage, providing AI-powered optimization suggestions. It's actively developed with frequent releases, typically addressing bug fixes, performance improvements, and compatibility updates for various Python versions and ecosystems.","status":"active","version":"2.2.1","language":"en","source_language":"en","source_url":"https://github.com/plasma-umass/scalene","tags":["profiler","performance","cpu","gpu","memory","ai","optimization"],"install":[{"cmd":"pip install scalene","lang":"bash","label":"Install Scalene"}],"dependencies":[],"imports":[{"note":"For programmatic control (start/stop) of the profiler. Most users will use the CLI directly.","symbol":"scalene_profiler","correct":"from scalene import scalene_profiler"}],"quickstart":{"code":"# my_script.py\nimport time\nimport math\n\ndef calculate_heavy_stuff(n):\n    result = 0\n    for _ in range(n):\n        result += math.sin(math.sqrt(time.time()))\n    return result\n\ndef main():\n    print(\"Starting heavy calculations...\")\n    calculate_heavy_stuff(1000000) # Perform 1 million iterations\n    print(\"Calculations finished.\")\n\nif __name__ == \"__main__\":\n    main()\n\n# To run the profiler from your terminal:\n# python -m scalene my_script.py","lang":"python","description":"Create a Python script (e.g., `my_script.py`) and then run Scalene from the command line using `python -m scalene my_script.py`. Scalene will generate a detailed profile in your terminal or an HTML report."},"warnings":[{"fix":"Ensure your Python environment is not 3.11.0. Upgrade to 3.11.1+ or use another compatible version (3.8, 3.9, 3.10, 3.12, etc.).","message":"Scalene explicitly requires Python versions `!=3.11.0` and `>=3.8`. This means Python 3.11.0 is not supported, though 3.11.1+ should be fine.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to Scalene v2.2.1 or newer. This version includes a fix that handles conflicts by falling back to alternative tool IDs or the legacy `PyEval_SetTrace` tracer.","message":"Earlier versions of Scalene (before 2.2.1) could crash with `SIGSEGV` when used with PyTorch Lightning on Python 3.12+ due to `sys.monitoring` tool ID conflicts.","severity":"breaking","affected_versions":"<2.2.1"},{"fix":"Upgrade to Scalene v2.2.1 or newer to ensure compatibility with TensorFlow 2.21 and later.","message":"TensorFlow 2.21+ changed `trace.enabled` from a callable to a boolean, causing compatibility issues with Scalene versions prior to 2.2.1.","severity":"breaking","affected_versions":"<2.2.1"},{"fix":"Upgrade to Scalene v2.1.2 or newer to resolve this issue. Version 2.1.2 fixed the Windows timer loop to use the actual configured sampling rate.","message":"On Windows, Scalene v2.1.x could experience extreme slowness and memory explosion during CPU profiling due to a hardcoded 1ms sampling interval, overriding the configured rate.","severity":"gotcha","affected_versions":"2.1.0 - 2.1.1"},{"fix":"For general profiling, always prefer `python -m scalene <your_script.py> [args]` or use the Jupyter `%%scalene` magic. Use the programmatic API (`from scalene import scalene_profiler; scalene_profiler.start()`) for fine-grained control within specific code blocks.","message":"The primary and recommended way to use Scalene for profiling is via the command-line interface (`python -m scalene your_script.py`) or Jupyter magics (`%%scalene`). While a programmatic API exists, directly importing and calling functions to *run* the profiler in a general context is less common and might not capture the full execution scope as effectively.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}