一句话:在 CPython 上借助硬件追踪模块与迹剪枝实现精确低开销的控制流追踪,平均开销仅 2.99%。
采集 Python 代码的控制流与覆盖率剖面在程序测试/fuzzing、调试、理解与优化等任务中需求迫切,但现有追踪手段要么开销高得难以实用,要么只能收集近似信息。本文提出利用现代硬件追踪模块(hardware tracing modules)为 Python 程序实现精确且低开销的控制流追踪,并在 CPython 运行时之上构建了原型系统 Pyriscope,其核心是有效的 trace pruning(迹剪枝)与高效的离线分析技术:通过剪除冗余硬件事件、将原始硬件迹映射回 Python 层的控制流信息,从而在保持信息完整性的同时压低运行时与存储代价。评估表明该系统能够提供信息丰富的控制流追踪,平均开销仅为 2.99%,比当前最先进方法低数个数量级,验证了硬件辅助追踪在托管语言运行时中的可行性。
Capturing the control-flow and/or coverage profiles of Python code becomes a pressing need for Python development community, which is commonly used in a wide spectrum of tasks including program testing/fuzzing, debugging, understanding, and optimizations. Existing tracing approaches either suffer from prohibitively high overhead or only collect approximate information, which cannot satisfy the practical requirements. In this paper, we propose to leverage modern hardware tracing modules to achieve precise and low-overhead control-flow tracing for Python programs. To this goal, we develop Pyriscope on top of CPython runtime by integrating the effective trace pruning and efficient analysis techniques. Evaluation results demonstrate the efficacy of our system. It incurs an average overhead of only 2.99% for rich-informative control-flow tracing, which is orders of magnitude smaller than that of the state of the arts.
@article{paperbot12131,
title = {Pyriscope: Precise and Low-Overhead Python Control Flow Tracing via Sparse Hardware-Based Events},
author = {Xinchen Yao and Wu Daiyou and Zhiqiang Zuo},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839479}
}