Files
overub/core/profiler.py
2025-12-21 17:12:32 +01:00

15 lines
348 B
Python

import cProfile
import pstats
from pathlib import Path
from typing import Callable
def profile(func: Callable, output: Path) -> None:
profiler = cProfile.Profile()
profiler.enable()
func()
profiler.disable()
output.parent.mkdir(parents=True, exist_ok=True)
stats = pstats.Stats(profiler)
stats.dump_stats(str(output))