実行状態記録を用いた革命的なPythonタイムトラベルデバッグライブラリ
Project description
TimeTravelDebugger 🕐
実行状態記録を用いた革命的なPythonタイムトラベルデバッグライブラリ
🚀 特徴
- 完全実行記録: すべての変数変更、関数呼び出し、実行ステップをキャプチャ
- タイムトラベルインターフェース: プログラムの実行タイムラインをナビゲート
- 多様な使用パターン: デコレータ、コンテキストマネージャー、グローバルデバッグ
- リッチ可視化: 美しいターミナルベースのタイムラインと変数検査
- EphemeralDB統合: パフォーマンス向上のための効率的なスコープベース状態ストレージ
- セッション管理: デバッグセッションの保存、読み込み、共有
- CLIツール: スクリプトデバッグ用のコマンドラインインターフェース
- インタラクティブエクスプローラー: 実行状態をインタラクティブにナビゲート
📦 インストール
pip install Travel-Debugger
必要要件
- Python 3.8+
- ephemeraldb>=1.0.0
- rich>=13.0.0 (拡張可視化用)
- click>=8.0.0 (CLI用)
🎯 クイックスタート
1. デコレータ使用法
from time_travel_debugger import time_travel_debug
@time_travel_debug
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
result = fibonacci(5)
# デバッグデータにアクセス
session = fibonacci.get_last_session()
timeline = session.get_timeline()
variables = session.get_variables_at_time(0.5)
2. コンテキストマネージャー使用法
from time_travel_debugger import TimeTravelContext
with TimeTravelContext() as debugger:
# あなたのコードをここに
result = complex_calculation(10)
# デバッグデータに即座にアクセス
timeline = debugger.get_timeline()
state = debugger.get_state_at_time(0.5)
3. グローバルデバッグ
from time_travel_debugger import start_global_debugging, stop_global_debugging
start_global_debugging()
# あなたのコードをここに
result = my_function()
stop_global_debugging()
timeline = get_global_timeline()
🔍 可視化
タイムライン可視化
from time_travel_debugger import print_timeline
print_timeline(debugger.get_timeline())
変数検査
from time_travel_debugger import print_variables_at_time
print_variables_at_time(debugger, timestamp=0.5)
インタラクティブタイムラインエクスプローラー
from time_travel_debugger import interactive_timeline_explorer
interactive_timeline_explorer(debugger)
🖥️ コマンドラインインターフェース
デバッグ付きでスクリプトを実行
ttdbg run my_script.py --timeline --summary
インタラクティブにコードをデバッグ
ttdbg debug --code "print('Hello, World!')" --interactive
保存されたセッションを読み込んで分析
ttdbg load debug_session.json --interactive
保存されたセッション一覧
ttdbg list-sessions
📊 高度な機能
カスタムフィルタリング
def my_filter(frame):
# 私のモジュール内の関数のみをトレース
return 'my_module' in frame.f_code.co_filename
@time_travel_debug(filter_func=my_filter)
def my_function():
# この関数とmy_module内の呼び出しのみがトレースされます
pass
セッション管理
# セッションを保存
debugger.export_session().export_to_file("my_debug_session.json")
# セッションを読み込み
from time_travel_debugger import load_session
session = load_session("my_debug_session.json")
検索と分析
# 特定の値を持つ変数のすべての状態を検索
states = debugger.search_variables('result', value=42)
# すべての関数呼び出しを取得
call_states = debugger.get_states_by_event('call')
# 特定の関数のすべての状態を取得
func_states = debugger.get_states_by_function('fibonacci')
🏗️ アーキテクチャ
TimeTravelDebuggerは、Pythonのsys.settrace()メカニズムを使用してプログラム実行にフックし、効率的なスコープベース状態ストレージにEphemeralDBを使用します:
- 実行トレース: すべての行実行、関数呼び出し、リターンをキャプチャ
- 状態記録: 変数状態とコールスタックを安全にシリアライズ
- スコープベースストレージ: 関数コンテキスト用にEphemeralDBの階層スコープを使用
- タイムライン管理: 時系列実行履歴を維持
- インタラクティブ分析: キャプチャしたデータを探索するためのツールを提供
📈 パフォーマンスの考慮事項
- メモリ使用量: メモリオーバーフローを防ぐためタイムラインサイズが制限されています
- フィルタリング: 関連するコードのみをトレースするためにカスタムフィルターを使用
- セッション管理: 古いセッションは自動的にクリーンアップされます
- 安全なシリアライゼーション: シリアライズ不可能なオブジェクトは適切に処理されます
🔧 設定
環境変数
TTDBG_MAX_TIMELINE_SIZE: キャプチャする状態の最大数 (デフォルト: 10000)TTDBG_USE_RICH: リッチターミナルフォーマットの有効/無効 (デフォルト: true)
プログラマティック設定
debugger = TimeTravelDebugger()
debugger.max_timeline_size = 5000 # タイムラインサイズを制限
📝 使用例
包括的な使用例については examples/ ディレクトリを参照してください:
basic_example.py: シンプルな関数デバッグfibonacci_example.py: 再帰関数分析recursive_example.py: 高度な再帰アルゴリズム
🤝 コントリビューション
- リポジトリをフォーク
- 機能ブランチを作成 (
git checkout -b feature/amazing-feature) - 変更をコミット (
git commit -m 'Add amazing feature') - ブランチにプッシュ (
git push origin feature/amazing-feature) - プルリクエストを開く
📄 ライセンス
このプロジェクトはMITライセンスの下でライセンスされています - 詳細はLICENSEファイルを参照してください。
🙏 謝辞
- 効率的な状態ストレージのために EphemeralDB を使用
- 可視化は Rich によって実装
- CLIインターフェースは Click で構築
🔗 リンク
ハッピータイムトラベリング! 🕐✨
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
travel_debugger-1.0.0.tar.gz
(9.5 kB
view details)
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 travel_debugger-1.0.0.tar.gz.
File metadata
- Download URL: travel_debugger-1.0.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0df71a5c242a35678a7180a2a9639b2b63ee1ba08f16379998d1e0e2a0214eed
|
|
| MD5 |
feaf9a6179c5a25d419f51bd2723aee1
|
|
| BLAKE2b-256 |
8a45ab9de6469c4b364411e538844e2e29a20fa96c663085c5a6338f46dcb721
|
File details
Details for the file travel_debugger-1.0.0-py3-none-any.whl.
File metadata
- Download URL: travel_debugger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dab8a63f41bb49e1e8c7ce7b03813aa1e4b3d7ca8d28c63f83555fab1949ea7c
|
|
| MD5 |
2445e525bd5f6316119a5e8f6d9eb6d4
|
|
| BLAKE2b-256 |
5b5f00c266eb4dc96e575259e667557212042feef8548d00dba547e137303883
|