Skip to main content

Traceipy is a Python tracing and profiling toolkit that provides clear, detailed insights into code execution to help you identify performance bottlenecks.

Project description

Traceipy

Python License

Traceipy is a powerful Python tracing and profiling tool that provides detailed insights into your code execution, supporting both synchronous and asynchronous functions. It helps you understand the performance characteristics and execution flow of your Python applications with beautiful rich-formatted output.

Features

  • 🔄 Support for both synchronous and asynchronous functions
  • 📊 Detailed CPU time and wait time measurements
  • 🌳 Hierarchical function call tracking with visual tree representation
  • 🎨 Beautiful rich-formatted output tables
  • 🔍 Function call stack visualization
  • 🏷️ Unique function call ID generation with natural ordering
  • 📝 Parent-child relationship tracking
  • 🎯 Visual function call tree with timing information
  • 🔀 Ordered trace output using custom function ID comparison

Installation

pip install traceipy

Usage

Here's a simple example that demonstrates how to use Traceipy:

import asyncio
from traceipy import Traceipy
from traceipy.trace_decorator import traceipy_decorator

# Initialize the tracer
root_class = Traceipy()

# Decorate your functions
# Set show_tree=True to display the execution tree visualization
@traceipy_decorator(root_class=root_class, show_tree=True)
def cpu_bound(n):
    total = 0
    for i in range(n):
        total += i * i
    return total

@traceipy_decorator(root_class=root_class, show_tree=True)
async def slow_async():
    await asyncio.sleep(1)
    return cpu_bound(1000000)

@traceipy_decorator(root_class=root_class, show_tree=True)
async def main():
    x = await slow_async()
    y = cpu_bound(100000000)
    return x + y

# Run your code
if __name__ == "__main__":
    result = asyncio.run(main())

The output includes:

  1. A detailed profiling table showing:

    • Parent function ID and name
    • Current function ID and name
    • CPU time consumption
    • Wait time for async functions
    • Function type indication (SYNC/ASYNC)
  2. A visual execution tree (when show_tree=True) displaying:

    • Hierarchical function calls
    • CPU time for each function
    • Wait time for async functions
    • Parent-child relationships in tree format

How It Works

Traceipy uses context variables to maintain the execution state and provides a decorator that can be applied to both synchronous and asynchronous functions. It tracks:

  • Function call depth
  • Parent-child relationships
  • CPU time using time.process_time()
  • Wait time for async operations
  • Unique call IDs for each function invocation

The trace data is organized using a custom-ordered data structure where function IDs are compared naturally (e.g., "1.2" comes before "1.10"). This ordering is implemented using Python's @total_ordering decorator, ensuring consistent and logical presentation of the execution trace.

Requirements

  • Python 3.12 or higher
  • rich>=14.1.0
  • yappi>=1.6.10

Contributing

Contributions are welcome! Feel free to:

  • Report issues
  • Submit pull requests
  • Suggest new features
  • Improve documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

  • Deban Kumar Sahu

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

traceipy-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

traceipy-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file traceipy-0.1.0.tar.gz.

File metadata

  • Download URL: traceipy-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for traceipy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3954ba21d979b57055b99215fdce5fd603333e7527bfe5273552666395eb845
MD5 3695a37d3e4a99eaa3330ce24c5882f9
BLAKE2b-256 f674ce8065e193df2bd2628a0e566c26dd18dfa2f207abfadc6880e6803f15b0

See more details on using hashes here.

File details

Details for the file traceipy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: traceipy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for traceipy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93942f28c7357426030c97176e8e9f8ddf0284d871da809ae2dce1a9bc2076c8
MD5 735960c2700ef1f051f38cf4a402a2fc
BLAKE2b-256 cea8e0e16b8be5c14a4b9b706aaac660698bb4040cd3db42e3f4ffa8622bca3f

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