Skip to main content

Near Zero-Overhead Python Code Coverage

Project description

slipcover

SlipCover: Near Zero-Overhead Python Code Coverage

by Juan Altmayer Pizzorno and Emery Berger at UMass Amherst's PLASMA lab.

license pypi Downloads pyversions tests

About Slipcover

SlipCover is a fast code coverage tool. It tracks a Python program as it runs and reports on the parts that executed and those that didn't. That can help guide your testing (showing code that isn't being tested), debugging, fuzzing or to find "dead" code.

Past code coverage tools can make programs significantly slower; it is not uncommon for them to take twice as long to execute. SlipCover aims to provide the same information with near-zero overhead, often almost as fast as running the original Python program.

How it works

Previous coverage tools like Coverage.py rely on Python's tracing facilities, which add significant overhead. Instead, SlipCover uses just-in-time instrumentation and de-instrumentation. When SlipCover gathers coverage information, it modifies the program's Python byte codes, inserting instructions that let it keep track the lines executed by the program. As the program executes, SlipCover gradually removes instrumentation that is no longer needed, allowing those parts to run at full speed. Care is taken throughout SlipCover to keep things as efficient as possible. On Python 3.12, rather than rewrite bytecode, SlipCover uses the new sys.monitoring API to collect coverage information.

Performance

The first image on the right shows SlipCover's speedup, ranging from 1.1x to 3.4x, in relation to Coverage.py, running on CPython 3.10.5.

The first two benchmarks are the test suites for scikit-learn and Flask; "sudoku" runs Peter Norvig's Sudoku solver while the others were derived from the Python Benchmark Suite.

More "Python-intensive" programs such as sudoku and those from the benchmark suite (with a larger proportion of execution time spent in Python, rather than in native code) generate more tracing events, causing more overhead in Coverage.py. While each program's structure can affect SlipCover's ability to de-instrument, its running time stays relatively close to the original.

On PyPy 3.9, the speedup ranges from 2.1x to 104.9x. Since it is so high for some of the benchmarks, we plot it on a logarithmic scale (see the second image on the right).

In a proof-of-concept integration with a property-based testing package, SlipCover sped up coverage-based testing 22x.

Accuracy

We verified SlipCover's accuracy against Coverage.py and against a simple script of our own that collects coverage using Python tracing. We found SlipCover's results to be accurate, in fact, in certain cases more accurate.

Getting started

SlipCover is available from PyPI. You can install it like any other Python module with

pip3 install slipcover

You could then run your Python script with:

python3 -m slipcover myscript.py

Using it with a test harness

SlipCover can also execute a Python module, as in:

python3 -m slipcover -m pytest -x -v

which starts pytest, passing it any options (-x -v in this example) after the module name. No plug-in is required for pytest.

Usage example

$ python3 -m slipcover -m pytest
================================================================ test session starts ================================================================
platform darwin -- Python 3.9.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/juan/project/wally/d2k-5, configfile: pytest.ini
plugins: hypothesis-6.39.3, mock-3.7.0, repeat-0.9.1, doctestplus-0.12.0, arraydiff-0.5.0
collected 439 items                                                                                                                                 

tests/box_test.py .........................                                                                                                   [  5%]
tests/image_test.py ...............                                                                                                           [  9%]
tests/network_equivalence_test.py .........................................s................................................................. [ 33%]
..............................................................................                                                                [ 51%]
tests/network_test.py ....................................................................................................................... [ 78%]
...............................................................................................                                               [100%]

=================================================== 438 passed, 1 skipped, 62 warnings in 48.43s ====================================================

File                                 #lines    #miss    Cover%  Lines missing
---------------------------------  --------  -------  --------  ------------------------
d2k/__init__.py                           3        0       100
d2k/box.py                              105       27        74  73, 142-181
d2k/image.py                             38        4        89  70-73
d2k/network.py                          359        1        99  236
tests/box_test.py                       178        0       100
tests/darknet.py                        132       11        91  146, 179-191
tests/image_test.py                      45        0       100
tests/network_equivalence_test.py       304       30        90  63, 68, 191-215, 455-465
tests/network_test.py                   453        0       100
$ 

As can be seen in the coverage report, d2k lacks some coverage, especially in its box.py and image.py components.

Platforms

Our GitHub workflows run the automated test suite on Linux, MacOS and Windows, but really it should work anywhere where CPython/PyPy does.

Contributing

SlipCover is under active development; contributions are welcome! Please also feel free to create a new issue with any suggestions or issues you may encounter.

Technical Information

For more details about how SlipCover works please see the following paper, published at ISSTA'23: SlipCover: Near Zero-Overhead Code Coverage for Python.

Acknowledgements

Logo design by Sophia Berger.

This material is based upon work supported by the National Science Foundation under Grant No. 1955610. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slipcover-1.0.16.tar.gz (58.2 kB view details)

Uploaded Source

Built Distributions

slipcover-1.0.16-py312-none-any.whl (35.4 kB view details)

Uploaded Python 3.12

slipcover-1.0.16-cp310-abi3-win_amd64.whl (89.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

slipcover-1.0.16-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (52.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

slipcover-1.0.16-cp310-abi3-macosx_14_0_universal2.whl (45.8 kB view details)

Uploaded CPython 3.10+macOS 14.0+ universal2 (ARM64, x86-64)

slipcover-1.0.16-cp310-abi3-macosx_13_0_universal2.whl (46.3 kB view details)

Uploaded CPython 3.10+macOS 13.0+ universal2 (ARM64, x86-64)

slipcover-1.0.16-cp39-cp39-win_amd64.whl (89.3 kB view details)

Uploaded CPython 3.9Windows x86-64

slipcover-1.0.16-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (55.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

slipcover-1.0.16-cp39-cp39-macosx_14_0_universal2.whl (45.8 kB view details)

Uploaded CPython 3.9macOS 14.0+ universal2 (ARM64, x86-64)

slipcover-1.0.16-cp39-cp39-macosx_13_0_universal2.whl (46.4 kB view details)

Uploaded CPython 3.9macOS 13.0+ universal2 (ARM64, x86-64)

slipcover-1.0.16-cp38-cp38-win_amd64.whl (89.3 kB view details)

Uploaded CPython 3.8Windows x86-64

slipcover-1.0.16-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (55.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

slipcover-1.0.16-cp38-cp38-macosx_14_0_universal2.whl (46.1 kB view details)

Uploaded CPython 3.8macOS 14.0+ universal2 (ARM64, x86-64)

slipcover-1.0.16-cp38-cp38-macosx_13_0_universal2.whl (46.4 kB view details)

Uploaded CPython 3.8macOS 13.0+ universal2 (ARM64, x86-64)

File details

Details for the file slipcover-1.0.16.tar.gz.

File metadata

  • Download URL: slipcover-1.0.16.tar.gz
  • Upload date:
  • Size: 58.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for slipcover-1.0.16.tar.gz
Algorithm Hash digest
SHA256 b8293f7e2be3e8c3883e22a1c202f61811627faf05035bd1a03a29689ae9f05e
MD5 489dc61d0916ff6566cb6b9260654c32
BLAKE2b-256 90af036f83dfd54612b6ea6b4dadfc59148d111d5490caa6db1352f977f1ae14

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-py312-none-any.whl.

File metadata

  • Download URL: slipcover-1.0.16-py312-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3.12
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for slipcover-1.0.16-py312-none-any.whl
Algorithm Hash digest
SHA256 d3c2970816d16ee896bc616687e4e041f9a896063817f09a8bd006fa28c09d05
MD5 8befd771bd33a00c5788c9abbc3732bc
BLAKE2b-256 9f19d42ac85de31554321e59d146400f586bd241deb05d39467b992f12e6ee3f

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: slipcover-1.0.16-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 89.2 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for slipcover-1.0.16-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 10b82c6e1964d85ccea4478a3d2f2e237296571d05198003264c7a8c328682a2
MD5 3a4eb9d08112229d06a196b0534a3d3e
BLAKE2b-256 5f286462d9a676a721ac47f265f1cbbfb9a0992877c0ac37d83a0119a47ef15f

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0523ff5b0a97b5585be7773f8745ece649bfe74e0e8ef80a4e8fce5121856ed5
MD5 3d509dd666b8b74a56d67bd3bf084c79
BLAKE2b-256 3483a57ce36d39b3f65b6f93174240447a846d8034132b992641d113950b5dd1

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp310-abi3-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp310-abi3-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 90594b3575cd393ad3eedee58878a595cd1562fc31a324e0f412bba17b902dec
MD5 744a3b4a4de427f0bfcb7a6679f9fda9
BLAKE2b-256 e1497e287fca54c7b16eb0717cbe06aa4be04df540e23eab5a9b2c8d98df1081

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp310-abi3-macosx_13_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp310-abi3-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 3ecaf29e495b8d671d7a8fc0546f12da6a11ec15cae287f42512df7daabe8988
MD5 0e9b3f2cf90a93e5b35f72638bad020e
BLAKE2b-256 cd856cfbb4e9553147d97be69c3d14652184d39c981e894bf3ca0177c9cc58c1

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: slipcover-1.0.16-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 89.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for slipcover-1.0.16-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 644f58a7b865fa17b236c44f7530c8b75f53aef3bd671a187e1e918cfd37b0b5
MD5 2f078ac6338e9d659eddddc10151534d
BLAKE2b-256 c7cd8f07c610538e29b2f9a01e47e5f1806e77596a93cc3fe4d9e2f644de089c

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8050f828731904b683180d609010d1763f308a233a359c113b4a2d722bcad63d
MD5 5e1d48057c80bcce4565e798ec379462
BLAKE2b-256 5ebd418c1079dc9ece6e8ed3de022ec7cc2ea260733f657f680b4ad4839ea1de

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp39-cp39-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp39-cp39-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 292bd2a75aa168eb53ac6b5c1ee4bf650b5a10deb0d033dbd2ea764ce3942c82
MD5 7527911d935f96d834738c56bee81d97
BLAKE2b-256 770013d469cb55708b91474c1fb38b60a43e4c8edfa030d8face56e74e195b64

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp39-cp39-macosx_13_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp39-cp39-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 30ff1977930251810001f7e381a7ab409eb2d0c1648280d8b213ce70f37c634d
MD5 b2cf4a72e35f1ba6a409e5a2f66cc204
BLAKE2b-256 23bc80c3956e06cca6e3b7c95718505de084c5f3a86b5b380624be9b39241390

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: slipcover-1.0.16-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 89.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for slipcover-1.0.16-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 22ecd6139ae2b2fd4c5f1944cad0422ff072e6be7d5d32584751672b95f439e3
MD5 909a030671b0b32d002ff7bb58a8d56d
BLAKE2b-256 f24f3b8ae17af85d776817cb0d4d9ff538fcdd96e067d22e2816e21dc34d8e8d

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b140b5ca8a349ca8844c5c1cd0fa77363a6a6c06e834d3c82fa1b2bd736b54df
MD5 9b45ab31076b40d2d03bc611ad5a2b48
BLAKE2b-256 367fea12a409d292307ecf0a4d1e073c0e5e15f3448ec73f0a0d35ec95378f68

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp38-cp38-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp38-cp38-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 a51882f3eacd4ce583e6585aa4643b36eb0405040bf090a14bc12efa3db73ace
MD5 3aeff1d85e8725028a48c8aadce91c6d
BLAKE2b-256 494d58e3370452779b1ec3ccc7e5cc260b4035b779126f2e85a8897dffb8708b

See more details on using hashes here.

File details

Details for the file slipcover-1.0.16-cp38-cp38-macosx_13_0_universal2.whl.

File metadata

File hashes

Hashes for slipcover-1.0.16-cp38-cp38-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 04d0258989d85ef1042ea67940dafbaa41285cdbc4bbd79800ccbb884209c4e8
MD5 8630cddcbfea1a3a90f42226a3afb321
BLAKE2b-256 ed25b3b3521a391567cbcca4dd5b744d2cf28fee7ae61b27e6c0c3f09ec9c6bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page