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 totam 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.

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
    

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.1.3.tar.gz (5.8 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.1.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for oracletrace-0.1.3.tar.gz
Algorithm Hash digest
SHA256 07780cbe2de6bd198ea339e70325b448fc5fce839d93f08aed6941821e770701
MD5 fbfbb8f30cb0bcf2d38bc8597350300a
BLAKE2b-256 7efe8c1596c68b100558d0b35bf99af90e8b6866068f7cfccf3eda12de91dc4b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for oracletrace-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1b9f9e14e760e24e27ba7065cee77b75d3825346866f9a65400c72486e9d7f7c
MD5 5eb34d4d7017e78d8618d683371aa6a0
BLAKE2b-256 bfcc77c9b7a1c244f0497da2f84dfd61effb006100e22bdeb1877302d46e32d9

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