Skip to main content

OracleTrace — Detect Python Performance Regressions with Execution Diff

Detect Python performance regressions before they merge.

OracleTrace Logo

Fail your CI when performance regresses.

OracleTrace is a git diff for performance.

Create a known-good baseline, trace the current run, and see exactly which functions got slower.

PyPI PyPI Downloads GitHub Stars GitHub Forks CI Tests

Documentation: https://kaykcaputo.github.io/oracletrace/

Featured in: PyCoder's Weekly #729La Experimental #30Python技术周刊 #15,#16 and #17 Woudar's Blog #214awesome-debuggerawesome-profiling


Installation

pip install oracletrace

Quick Start

1. See where your program spends time instantly:

oracletrace app.py

2. Compare runs and detect regressions:

oracletrace app.py --json baseline.json
oracletrace app.py --json new.json --compare baseline.json

3. Manage baselines explicitly:

oracletrace baseline save app.py baseline.json
oracletrace app.py --json current.json
oracletrace baseline compare baseline.json current.json --fail-on-regression --threshold 10

Examples

Try these ready-to-run scripts to explore OracleTrace features:

# CPU hotspot — highlights the heaviest function
oracletrace examples/cpu_hotspot.py

# Nested call graph — see the tree visualization
oracletrace examples/nested_calls.py

# Regression demo — baseline vs slower path
oracletrace examples/regression_demo.py --json baseline.json
SLOW=1 oracletrace examples/regression_demo.py --json current.json --compare baseline.json

All examples are deterministic, finish in under a second, and live in examples/. They can also be reused in test suites as smoke tests.


See it in action

See exactly which functions got slower between runs:

OracleTrace CLI demo


Example Output

Starting application...

Iteration 1:
  > Processing data...
    > Calculating results...

Iteration 2:
  > Processing data...
    > Calculating results...

Application finished.

Summary:
                         Top functions by Total Time
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ Function                     ┃ Total Time (s) ┃ Calls ┃ Avg. Time/Call (ms) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ my_app.py:main               │         0.6025 │     1 │             602.510 │
│ my_app.py:process_data       │         0.6021 │     2 │             301.050 │
│ my_app.py:calculate_results  │         0.4015 │     2 │             200.750 │
└──────────────────────────────┴────────────────┴───────┴─────────────────────┘

Logic Flow:
<module>
└── my_app.py:main (1x, 0.6025s)
    └── my_app.py:process_data (2x, 0.6021s)
        └── my_app.py:calculate_results (2x, 0.4015s)

Why OracleTrace?

Problem

Performance regressions often reach production because correctness tests still pass.

Solution

OracleTrace gives CI a small, scriptable performance gate based on saved execution traces.

How it works

  1. Run your script
  2. Generate a trace
  3. Compare results
  4. Identify slowdowns

CI Integration

Fail your pipeline when performance degrades:

oracletrace run \
  --repeat 50 \
  --json current.json \
  --compare baseline.json \
  --fail-on-regression \
  --threshold 35 \
  -- pytest tests/

Add it to your CI to automatically fail on performance regressions.

Baseline-file workflow:

# on a stable branch or release job
oracletrace baseline save app.py baseline.json --repeat 50

# in a pull request job
oracletrace app.py --json current.json --repeat 50
oracletrace baseline compare baseline.json current.json --fail-on-regression --threshold 35

Key Features

  • Detect slower and faster functions
  • Identify new or removed functions
  • Execution time and call count analysis
  • Call graph visualization
  • JSON and CSV export
  • Regex-based filtering (--ignore)
  • Top-N function focus (--top)
  • CI regression gates
  • Baseline save and compare commands

CLI Reference

Flag Description
--json Export trace to JSON
--csv Export trace to CSV
--html Export trace to html
--compare Compare with another trace
--fail-on-regression Exit with error if regression detected
--threshold Regression percentage threshold
--ignore Ignore functions/files via regex
--top Show top N functions
--repeat Repeat the tracing N times

Baseline commands:

oracletrace baseline save app.py baseline.json
oracletrace baseline compare baseline.json current.json --fail-on-regression --threshold 35

Use Cases

Primary

  • Guard pull requests against Python performance regressions

Secondary

  • CI performance validation
  • Execution trace inspection
  • Call graph visualization
  • Release baseline tracking

How It Works

OracleTrace uses Python’s sys.setprofile() to intercept function calls and returns.

It measures execution time per function and records caller–callee relationships.

Filtering removes external/internal calls to focus on application code.


Requirements

  • Python >= 3.11
  • rich

When to use another tool

OracleTrace is for lightweight regression checks and function-level change detection. Use cProfile, py-spy, or a benchmark suite when you need deep profiler statistics, sampling of production processes, memory profiling, or statistically rigorous microbenchmarks.


Contributing

Contributions are welcome.

Please read the Contributing Guide for details on how to get started, coding standards, and the contribution process.


Contributors


⭐ Support the Project

If OracleTrace is useful, consider giving it a star:

GitHub Repository


Maintainers

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oracletrace-3.0.2.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oracletrace-3.0.2-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file oracletrace-3.0.2.tar.gz.

File metadata

  • Download URL: oracletrace-3.0.2.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for oracletrace-3.0.2.tar.gz
Algorithm Hash digest
SHA256 35fedc4f1384ad191d711397c5dab9d4219a5393f9ad987a39cf63fd5e2e6e7a
MD5 69c9d7989aab58ca6e383dc67b6ee5b3
BLAKE2b-256 19777a9fa7f95c1640ff0687d154d1a747cbf63566aeeaa25ed2b5c5c0ace5d4

See more details on using hashes here.

File details

Details for the file oracletrace-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: oracletrace-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for oracletrace-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 691ff973134885db0d25436466bbb197232ec6cf16c0bf6f603a44d6164c212c
MD5 572faf122296726b656a2a7949949bb0
BLAKE2b-256 ad6b4472953c3d43d3c83cd0f5af9fcfe0c72d988a0d993a9019a5daed4fa232

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page