Skip to main content

Simple logic path tracer

Project description

OracleTrace

OracleTrace is a simple logic path tracer for Python applications. It visualizes the execution flow of your code, helping you understand function calls and performance bottlenecks.

PyPI PyPI Downloads

GitHub: https://github.com/KaykCaputo/oracletrace

Features

  • Performance Summary Table: Visualize the most time-consuming functions with a clean table showing total time and average time per call.
  • Logic Flow Visualization: See a tree structure of function calls.
  • Performance Metrics: View execution time and call counts for each function.
  • Clean Output: Filters out internal Python calls for better readability.
  • JSON Export: Save trace results to a JSON file for further analysis or record keeping.
  • Trace Comparison: Compare two trace JSON files to see performance changes, new or removed functions, and time differences.

How It Works

OracleTrace uses Python's built-in sys.setprofile() function to intercept function call events (call, return). It measures the time spent inside each function and records the caller-callee relationships. By tracking the file path of each function, it can filter out calls that are not part of your local project directory, resulting in a clean and relevant report.

Installation

pip install oracletrace

Quick Start

  1. Create a Python script. For example, save the following as my_app.py:

    # my_app.py
    import time
    
    def process_data():
        print("  > Processing data...")
        time.sleep(0.1)
        calculate_results()
    
    def calculate_results():
        print("    > Calculating results...")
        time.sleep(0.2)
    
    def main():
        print("Starting application...")
        for i in range(2):
            print(f"\nIteration {i+1}:")
            process_data()
        print("\nApplication finished.")
    
    if __name__ == "__main__":
        main()
    
  2. Run oracletrace from your terminal:

    oracletrace your_script.py
    

    Or run it as a module:

    python -m oracletrace.cli your_script.py
    

    To export the trace result to a JSON file:

    oracletrace your_script.py --json result.json
    

    To compare two trace results:

    oracletrace your_script.py --json new_run.json --compare old_run.json
    

Example Output

Running the command above will execute your script and then generate a report like this:

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)

Requirements

  • Python >= 3.10
  • rich

Contributing

Contributions are welcome! If you find a bug, have a suggestion for a new feature, or want to improve the code, please feel free to open an issue or submit a pull request. All feedback and contributions are highly appreciated.

Project details


Download files

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

Source Distribution

oracletrace-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

oracletrace-0.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for oracletrace-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d52f859fa76eaaa213c54167f313a13e95030e5f765172a66af89dcc069fd506
MD5 42d5ab3741d38029a1721b3ff7f2f937
BLAKE2b-256 9ec20226eec91f667adfbc5872b2b31dee54dd210106a944a3faecc41cc80776

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for oracletrace-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0478447e9c9959b100a834c58bb073f3fa7bd8b0b02296559d8af0cc6d1f5b48
MD5 60c67eb591dba966d35564a5b8046550
BLAKE2b-256 92dc8a45d34472a9ea002193896d78c52662de48045eb7b00bc7d9d86e8d627e

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 Pingdom Monitoring Sentry Error logging StatusPage Status page