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.
GitHub: https://github.com/KaykCaputo/oracletrace
- 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.
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.
pip install oracletrace-
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()
-
Run
oracletracefrom your terminal:oracletrace your_script.py
Or run it as a module:
python -m oracletrace.cli your_script.py
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)
- Python >= 3.10
- rich
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.