arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2305.02886cs.SEcs.PL
收藏

SlipCover:面向Python的近零开销代码覆盖率分析工具

SlipCover: Near Zero-Overhead Code Coverage for Python

Juan Altmayer Pizzorno, Emery D Berger

AI总结:

SlipCover通过AST识别与动态字节码插桩及周期性去插桩,实现Python近零开销覆盖率分析,中位数开销仅5%,并显著加速覆盖率驱动的测试工具。

摘要:

覆盖率分析被广泛使用,但可能带来很高的开销。这种开销在Python环境中尤为严重,因为Python本身已经以运行缓慢著称(最近一项研究观察到其相比原生代码大约慢30倍)。我们发现,Python最先进的覆盖率工具coverage.py在标准Python解释器下会引入中位数180%的开销。当使用PyPy(一种JIT编译的Python实现)时,性能下降更为极端,coverage.py带来的中位数开销高达1300%。这种性能退化降低了覆盖率分析在大多数使用场景中的实用性,包括测试和模糊测试,并使其无法在部署环境中使用。本文提出了SlipCover,一种新颖的、近零开销的Python覆盖率分析器。SlipCover无需修改Python解释器或PyPy即可工作。它首先处理程序的AST以准确识别所有分支和代码行。然后,SlipCover动态重写Python字节码,为每个识别出的分支和代码行添加轻量级插桩。在运行时,SlipCover会周期性地对已覆盖的代码行和分支进行去插桩处理。其结果是极低的开销——中位数仅为5%——使得SlipCover适用于部署环境。我们展示了其高效性可以转化为基于覆盖率的客户端速度的显著提升。作为概念验证,我们将SlipCover集成到TPBT(一种定向的基于属性的测试系统)中,并观察到22倍的加速。

英文摘要:

Coverage analysis is widely used but can suffer from high overhead. This overhead is especially acute in the context of Python, which is already notoriously slow (a recent study observes a roughly 30x slowdown vs. native code). We find that the state-of-the-art coverage tool for Python, coverage$.$py, introduces a median overhead of 180% with the standard Python interpreter. Slowdowns are even more extreme when using PyPy, a JIT-compiled Python implementation, with coverage$.$py imposing a median overhead of 1,300%. This performance degradation reduces the utility of coverage analysis in most use cases, including testing and fuzzing, and precludes its use in deployment. This paper presents SlipCover, a novel, near-zero overhead coverage analyzer for Python. SlipCover works without modifications to either the Python interpreter or PyPy. It first processes a program's AST to accurately identify all branches and lines. SlipCover then dynamically rewrites Python bytecodes to add lightweight instrumentation to each identified branch and line. At run time, SlipCover periodically de-instruments already-covered lines and branches. The result is extremely low overheads -- a median of just 5% -- making SlipCover suitable for use in deployment. We show its efficiency can translate to significant increases in the speed of coverage-based clients. As a proof of concept, we integrate SlipCover into TPBT, a targeted property-based testing system, and observe a 22x speedup.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑