A lightweight Python tracer for capturing and analyzing function call events with tree visualization and JSON serialization support.
Project description
Crimson Tracer
Crimson Tracer is a lightweight Python tracing utility that records function call events and provides useful insights into your code execution. It captures details such as function inputs, file names, line numbers, and more, allowing you to analyze the call flow. Additionally, you can convert raw trace events into a nested tree structure and serialize them to JSON for further processing.
Features
- Function Call Tracing: Automatically capture call, line, and return events during execution.
- Tree Generation: Convert a linear list of trace events into a nested tree structure for easy visualization.
- JSON Serialization: Serialize trace data to JSON, ensuring all dictionary keys are strings.
- Frame Filtering: Include or exclude specific frames based on filename patterns using the built-in
FrameFilter. - Customizable Event Editing: Modify trace events on the fly with an optional custom event editor.
Install
pip install crimson-tracer
Example
Tracer
The TraceManager collects all called functions along with valuable details such as function inputs and execution context.
For a complete example, see tracer.ipynb.
from crimson.tracer import TraceManager
def sample_function():
# Your function logic here
return "result"
# Run the tracer on the sample function
TraceManager.run_trace(sample_function, name="sample_trace")
trace_events = TraceManager.get_trace("sample_trace")
Node
Convert the traced result into a nested tree structure for a clearer view of the call hierarchy using generate_trace_tree.
For more details, refer to node.ipynb.
from crimson.tracer import generate_trace_tree, TraceManager
trace_events = TraceManager.get_trace("sample_trace")
trace_tree = generate_trace_tree(trace_events)
API Overview
-
TraceManager:
Manages the tracing process, collects trace events, and provides methods to run and retrieve traces. -
TraceEvent:
A Pydantic model that represents a trace event with details like function name, filename, line number, event type, local variables, and more. -
generate_trace_tree:
Transforms a list of trace events into a nested tree structure to reflect the call hierarchy. -
dumps:
Serializes trace data into a JSON-formatted string with all dictionary keys as strings. -
FrameFilter:
Allows filtering of stack frames based on inclusion and exclusion rules to refine the tracing process.
Crimson Tracer offers a flexible and efficient way to monitor and analyze function calls in your Python applications. Enjoy exploring your code's execution flow with ease!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crimson_tracer-0.1.5.tar.gz.
File metadata
- Download URL: crimson_tracer-0.1.5.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ec31ed91fe7d347d3519079564c8d2d7272e4214d45aa54a053124fcf02c94e
|
|
| MD5 |
55623f6a7a08eea255a268c448b9c44d
|
|
| BLAKE2b-256 |
cda268fb4c84d9d0b8149f39c4de8aa6f34fbf6ede940dc25550e57051bef016
|
File details
Details for the file crimson_tracer-0.1.5-py3-none-any.whl.
File metadata
- Download URL: crimson_tracer-0.1.5-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed950d8ad7198aea9c830ccea6c615c8384360cf1ef1d6863b2b1cdd9c2c7d95
|
|
| MD5 |
c3b2a396534695ea675e4b5f674335c9
|
|
| BLAKE2b-256 |
dffeda373c4276b4804515ef4ab970284665ef4e028a74732aa0ece33eac03cd
|