taolib.harness.devtools.profiler#
性能剖析器 - 节点耗时、LLM 延迟、Token 吞吐与内存峰值的统一采集。
提供 PerformanceProfiler 作为入口,搭配 profiled() 装饰器
对函数级别打点,最后由 HotspotAnalyzer 识别耗时热点。
Classes#
热点分析器 - 从剖析样本中识别最耗时的标签。 |
|
热点条目。 |
|
性能剖析器。 |
|
剖析配置。 |
|
剖析结果。 |
|
单条耗时打点。 |
Functions#
|
函数装饰器:自动向当前活跃剖析器登记耗时。 |
Module Contents#
- class taolib.harness.devtools.profiler.HotspotAnalyzer(*, top_k: int = 5)#
热点分析器 - 从剖析样本中识别最耗时的标签。
- analyze(samples_or_result: collections.abc.Sequence[ProfileSample] | ProfileResult) list[HotspotEntry]#
聚合并按总耗时降序返回
top_k个热点。
- class taolib.harness.devtools.profiler.PerformanceProfiler(*, config: ProfileConfig | None = None)#
性能剖析器。
- ameasure(label: str, *, category: str = 'node', metadata: collections.abc.Mapping[str, Any] | None = None, tokens: collections.abc.Mapping[str, float] | None = None) PerformanceProfiler#
异步打点上下文。
- async aprofile(execution: collections.abc.Callable[[], collections.abc.Awaitable[R]], *, label: str = 'execution') tuple[R, ProfileResult]#
异步剖析单次执行。
- classmethod current() PerformanceProfiler | None#
返回栈顶的活跃剖析器(若存在)。
- measure(label: str, *, category: str = 'node', metadata: collections.abc.Mapping[str, Any] | None = None, tokens: collections.abc.Mapping[str, float] | None = None) Any#
同步打点上下文。
- profile(execution: collections.abc.Callable[[], R], *, label: str = 'execution') tuple[R, ProfileResult]#
同步剖析单次执行。
- record_event(label: str, duration_seconds: float, *, category: str = 'node', metadata: collections.abc.Mapping[str, Any] | None = None, tokens: collections.abc.Mapping[str, float] | None = None) None#
直接登记一条已知耗时的打点。
- report() ProfileResult#
生成当前已收集样本的报告(不停止剖析)。
- session() Any#
上下文管理器:
with profiler.session(): ...。
- stop() ProfileResult#
停止剖析并生成结果。
- class taolib.harness.devtools.profiler.ProfileConfig#
Bases:
pydantic.BaseModel剖析配置。
- model_config#
- output_path: pathlib.Path | None = None#
- class taolib.harness.devtools.profiler.ProfileResult#
Bases:
pydantic.BaseModel剖析结果。
- model_config#
- samples: list[ProfileSample]#
- class taolib.harness.devtools.profiler.ProfileSample#
Bases:
pydantic.BaseModel单条耗时打点。
- model_config#
- taolib.harness.devtools.profiler.profiled(label: str | None = None, *, category: str = 'node') collections.abc.Callable[[collections.abc.Callable[P, R]], collections.abc.Callable[P, R]]#
函数装饰器:自动向当前活跃剖析器登记耗时。
若调用时没有活跃剖析器则等同于直接调用。