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.17.tar.gz (58.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

slipcover-1.0.17-py312-none-any.whl (35.7 kB view details)

Uploaded Python 3.12

slipcover-1.0.17-cp310-abi3-win_amd64.whl (89.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

slipcover-1.0.17-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (53.0 kB view details)

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

slipcover-1.0.17-cp310-abi3-macosx_14_0_universal2.whl (46.1 kB view details)

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

slipcover-1.0.17-cp310-abi3-macosx_13_0_universal2.whl (46.6 kB view details)

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

slipcover-1.0.17-cp39-cp39-win_amd64.whl (89.7 kB view details)

Uploaded CPython 3.9Windows x86-64

slipcover-1.0.17-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (55.7 kB view details)

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

slipcover-1.0.17-cp39-cp39-macosx_14_0_universal2.whl (46.1 kB view details)

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

slipcover-1.0.17-cp39-cp39-macosx_13_0_universal2.whl (46.6 kB view details)

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

slipcover-1.0.17-cp38-cp38-win_amd64.whl (89.6 kB view details)

Uploaded CPython 3.8Windows x86-64

slipcover-1.0.17-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (56.1 kB view details)

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

slipcover-1.0.17-cp38-cp38-macosx_14_0_universal2.whl (46.3 kB view details)

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

slipcover-1.0.17-cp38-cp38-macosx_13_0_universal2.whl (46.6 kB view details)

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

File details

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

File metadata

  • Download URL: slipcover-1.0.17.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for slipcover-1.0.17.tar.gz
Algorithm Hash digest
SHA256 c94fb8f587e010773b0977e19aaca03767200d44a17ad48424638e93022582ca
MD5 eeed79ade494bcc2402ab1317577f506
BLAKE2b-256 87bde53b1cd649299f3bcfb77674942331de5f8a3e1de54266c04a0298d0ff55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slipcover-1.0.17-py312-none-any.whl
  • Upload date:
  • Size: 35.7 kB
  • Tags: Python 3.12
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for slipcover-1.0.17-py312-none-any.whl
Algorithm Hash digest
SHA256 d7b8924c44870dfdb5137f115a62494283116ff5ab16f6c375a26d78aabf5e4f
MD5 92ce8a740e849361a415991cd16e489c
BLAKE2b-256 eb328635acbd422643d0b646a73aa77df8eaf2d7de0998b3e0de36fc34f4fca0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-1.0.17-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ccd60c6be5eb9d77b170b405cebe267b793a0001e558147d7aeb8550efabd784
MD5 74d2ca38ba7c926a7fc9680b7aef806b
BLAKE2b-256 3bdc340d871a312630a1d54e8602310df4214f7726635ad9c097c0631271666f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a76466654d26e916e425d31f35773426ef25dd1c4ea13d12f51ec58ca36c5246
MD5 cd7de29551a63a1e4d8823c74885f128
BLAKE2b-256 60013e3bc8381fc24f97df4443557a0dc1f0c2349eb17d98d1c5148606dc0019

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp310-abi3-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 9ac11a3fab59aa93ab011d5865fb63cfb3965c908cb67cc4189678151189ce7d
MD5 9f35ffd4d7cead4e58853fa5683f7f27
BLAKE2b-256 ace05bb5e0c2325fc45a2fef42ea74509d980e09463be4071855db441238b5db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp310-abi3-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 7ad17d58f9ee843471d2fa0a8e5f104a6f6d861f77ecac977d45c411c4297814
MD5 d162e81f919fba2d80a5f39089e88951
BLAKE2b-256 264e8361d79ec30e2f05da25aedb297e0d8d5fbb7ff0b376c7765bd9f0ef138c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-1.0.17-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cf1a8e2fe409b70f6b2150951802b2ee4c283fa007a74aed16454620e1d3bc2b
MD5 3095b9085871be016222126acbd05e99
BLAKE2b-256 fc254a62f96979ce8f4249c8b820200d6521ee57ee389ba010ed620358daf3e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0770e72a10412dab8d559dfef32531aadc407b87b69aefc681dbcf41323cb8d7
MD5 5d6ece2e5f27cb5d2eaa4d813d6b0c3b
BLAKE2b-256 93c97b1c207938aac317d5ecbe8b8430d261438ae21734e23b00e4f30ab4e4ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp39-cp39-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 012b10bc43bc4f501f7fdda6c356950f3e036f7fbd32a86819d529ee1637b9eb
MD5 737fe1f1bfa156e563c76485eb57526e
BLAKE2b-256 7592aab04ec664a6e707ea1edfa08160ad78a9da20ff02f7031ef470878ce761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp39-cp39-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 71d3d72af4b789b9768663bbe6d29e77765c1085facf8157e9a87b1372f3d6a4
MD5 967686033acbff8b0c8def91a8ae7157
BLAKE2b-256 aee10f04f39415a8851af0a832259706b953b98b0286528d6d097fe096bb4248

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-1.0.17-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 174b841e483ba31522ebd50d31e4cf7c804d0922d735bdba0a479f25fc4b462f
MD5 ebed1d946d32b6abd8ef14e1870e98aa
BLAKE2b-256 f50a8500c1e10f4c966bd3acc763de6270947b0de713b7140312fa48bc23deb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 874a6fb3525e17be5661383b0c25814462fa51b0ac9646cd002183235f437a06
MD5 2dab6f0c77fa4e8cfe5945cdc3b895df
BLAKE2b-256 4c09024943631cbfa9a9c1124ebd466f24b4436381036abf13a107352af64515

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp38-cp38-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 7d3562af3a086e7d9dcfece16b889fc755ba6f8ceeaf5bc9020e2f77a14ecb3c
MD5 a9f042447c6512a88fd42ba062bf0ad5
BLAKE2b-256 4aae318955fe0fee2e4efb7793137ffff714137233042dd20af54d47259dba7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.17-cp38-cp38-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 cf984d9a97061138aa9ef523117b281e6096d126dd7f4a01be90e72ab0529ca6
MD5 5953b26abfddc476714e75fc243595e9
BLAKE2b-256 b6d3c247dc407df51175c0e42fe3e9c23828d66cdc43eaeef144bd09d24b7bac

See more details on using hashes here.

Supported by

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