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.18.tar.gz (65.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.18-py312-none-any.whl (39.7 kB view details)

Uploaded Python 3.12

slipcover-1.0.18-cp310-abi3-win_amd64.whl (93.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

slipcover-1.0.18-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (57.0 kB view details)

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

slipcover-1.0.18-cp310-abi3-macosx_14_0_universal2.whl (50.0 kB view details)

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

slipcover-1.0.18-cp39-cp39-win_amd64.whl (93.7 kB view details)

Uploaded CPython 3.9Windows x86-64

slipcover-1.0.18-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (59.7 kB view details)

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

slipcover-1.0.18-cp39-cp39-macosx_14_0_universal2.whl (50.1 kB view details)

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

slipcover-1.0.18-cp38-cp38-win_amd64.whl (93.6 kB view details)

Uploaded CPython 3.8Windows x86-64

slipcover-1.0.18-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (60.1 kB view details)

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

slipcover-1.0.18-cp38-cp38-macosx_14_0_universal2.whl (50.2 kB view details)

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

File details

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

File metadata

  • Download URL: slipcover-1.0.18.tar.gz
  • Upload date:
  • Size: 65.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for slipcover-1.0.18.tar.gz
Algorithm Hash digest
SHA256 7b48458539444ccd6d75fe87228570825778e686f280752e59976be140ec4f26
MD5 1d7f9fc892ea76d2f59f4cdfb7195131
BLAKE2b-256 eec34f7b1794d37e11d8e61110d54b65f2cab8a9c5555653887fa22b6a8c5b93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slipcover-1.0.18-py312-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3.12
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for slipcover-1.0.18-py312-none-any.whl
Algorithm Hash digest
SHA256 108d84638c7a9c66e77b00bcef95602d9fac4e53be2f89deae5915acb8b953fc
MD5 e00200b75187274bb11040226b7f1a98
BLAKE2b-256 4246f0cfc087db27c2be53162de30cc0a92d7cc7aec8e1af85d4eb0b376479bf

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-1.0.18-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a4679949dcf46281ff966f3284ea2b74d30c0c808664b1fca2fbef02932529ed
MD5 e61aab82ca2db6f5458a3a043b14b196
BLAKE2b-256 da99531bb6db127443f9fa0660ee600472987e650dcc661d85cc75f4ed9655ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d1eb4e6c37f11135c10a6dd01363fa738649030e136ca5d98844956b196433a
MD5 384ce55a7349597bc36583f83c8af7b7
BLAKE2b-256 b8ed4b1acb607f43c40a97598daa6fc28cdf008dd1e08723c192cfb434b47adb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp310-abi3-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 f8f4d667b573ebed8c41532f34d6589c3b4ed296b1e0e3ee82916dcc0289b8d4
MD5 b346a08c73edb262f6050aeea26d25be
BLAKE2b-256 afa4c16baa1afcaedc206771ed7108224637054a59e3394b2d1469d8daca97cc

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-1.0.18-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3b421255eb835095f13ccfea9a7a262463dd9d06a74ae8bc3331d1ddf73f0768
MD5 43b8b4673cb2333893680794bfe336de
BLAKE2b-256 87e948bdd788868aeef74b5d98b4e5d55d44f4d85d6dadede0888dac8044c8a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab5f20fa5f2d7a73782ce15c6100f2197e45697ac50f846ff28d0bee64b594aa
MD5 9a3b489b2ddb18c53bd9b0c452a040ed
BLAKE2b-256 fe5efd0e09d05f0102c1a7a3e069ceab62d95dbb23c7f83e6de3783e23bed652

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp39-cp39-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 8e320a71aa0c97eb8da133e58e4b8220c816a95247fec10eee892c3bb1b52d30
MD5 4d29c19940507adb5244e67326494a15
BLAKE2b-256 2341e017843880d11f418e2e89b603e8093e38a4050e8765dd5b83a7efcf6312

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slipcover-1.0.18-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 93.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.18-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 42eb84e82f2ce5854a2787ff1afff07fc90a3eb5de74b2dcf3a50684b83d2f66
MD5 1317615319a76ed5f9b9db877323260d
BLAKE2b-256 615f500c15b183ad9cd02316be6c5ec984e693d75d4315aad4978fb22e7b87eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 446fcf75368398ea06984f26016127a116f3765e08c59a2fd5e13023afaa4736
MD5 ae27c3803e171e8967387a9386be5742
BLAKE2b-256 30e6f4da7a3ef655f9e49c87ce806c2aa74666a5cc0ebaa485fb9752d246e485

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-1.0.18-cp38-cp38-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 724fc865dc768399659b2d81e680ca605445b1b54a7fb9693fa17f804a9709b6
MD5 5ae82f8236ffe7ccfe2566892bf5556b
BLAKE2b-256 53591ea3be002a8e3031b91f6090628b6c6fa25bdb30ba8f2594c7e564050b34

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