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.

Performance

The image on the right shows the execution time of a few benchmarks. It compares how long they take to run while tracking coverage using Coverage.py, in orange, and tracking coverage using Slipcover, in blue, relative to their normal running times.

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.

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 does.

Contributing

Slipcover is alpha software, and under active development. Please feel free to create a new issue with any suggestions or issues you may encounter.

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

Uploaded Source

Built Distributions

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

slipcover-0.2.2-cp311-cp311-win_amd64.whl (81.7 kB view details)

Uploaded CPython 3.11Windows x86-64

slipcover-0.2.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (48.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

slipcover-0.2.2-cp311-cp311-macosx_10_9_universal2.whl (37.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

slipcover-0.2.2-cp310-cp310-win_amd64.whl (81.7 kB view details)

Uploaded CPython 3.10Windows x86-64

slipcover-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (48.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

slipcover-0.2.2-cp310-cp310-macosx_11_7_universal2.whl (37.8 kB view details)

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

slipcover-0.2.2-cp39-cp39-win_amd64.whl (81.8 kB view details)

Uploaded CPython 3.9Windows x86-64

slipcover-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (48.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

slipcover-0.2.2-cp39-cp39-macosx_10_15_universal2.whl (37.8 kB view details)

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

slipcover-0.2.2-cp38-cp38-win_amd64.whl (81.8 kB view details)

Uploaded CPython 3.8Windows x86-64

slipcover-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

slipcover-0.2.2-cp38-cp38-macosx_10_15_universal2.whl (37.7 kB view details)

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

File details

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

File metadata

  • Download URL: slipcover-0.2.2.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for slipcover-0.2.2.tar.gz
Algorithm Hash digest
SHA256 995d7ae42137e460456c9f30a9a584104b6b3a95c15dbe9f41d15a74b4cb877c
MD5 d8a6dfe6c2ffe0957744ba8c9c52b050
BLAKE2b-256 e17bb5b2b379ad83c2a1f1b603046f8517176fad0f1e9733cf57d71bf97142ae

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: slipcover-0.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 81.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for slipcover-0.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d80db863b36c2e0de34ef6a102d56974a9a5993440f517aa2632796b048124cd
MD5 01702e9b1e0f398826913c22d4b23579
BLAKE2b-256 a7529cee1b5af514bac51761a545948232924806b4a8ca8ff43263b2139f0cf3

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 065f3e193242b8762a5529456f63c62839a3b5d65c6def0f002f02fda2fe18f2
MD5 9ca8ef03e4b7006ee55d9159d0bd76ac
BLAKE2b-256 6e3ab6bd64821d810269a41d3ae26be4468f4a47afda3beabda30e85f8a543b4

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8b86314a0e850f58d475f9ae1483cbc37b5a0fbac486bb8514f2b9cb12c56803
MD5 46fbaabb01ce16e47836c8f66c53acfe
BLAKE2b-256 1d4a446725fa5979d91c4f6e6a866d58ce0513b637f95abf570bb0bdee795727

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: slipcover-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 81.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for slipcover-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 135c643082ad81f77cc46259af2c3112bb67588dcf32738a303c45c6d24a14dc
MD5 82eb470d103f7d5bed01412897a3a0a1
BLAKE2b-256 d5360b8b2eb7daee3585a793b63c8cbb692f7cc5b050c43dc8b2cdb57cbb319b

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82213126d251ef926257aea4075f146fb618806020f62883cc2105095d1cb0fa
MD5 6e7b11026c109733745a530efd58e2bc
BLAKE2b-256 9c1fd1b99172244a431c4adf1823d30a270413b096222d05a3490c74751d7ec6

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp310-cp310-macosx_11_7_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp310-cp310-macosx_11_7_universal2.whl
Algorithm Hash digest
SHA256 5856cfd5bffdc5869c262ce8187a87d1603ad2b5cd5cc7bd6cd69a2cc213de0a
MD5 438926e9f023890d97392326979e926c
BLAKE2b-256 ceed475f655638cb4fe5b07315a3ea8c87039bbc7e467a7814b1aff74feeac26

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 242380704ebab46d1e2409cd5cd121574fd324fb54e80312daa17af5ad31897c
MD5 9610bad0ae5389da882a36e66c93701d
BLAKE2b-256 64a836ca6a2283c3a50886af9c88ffc703983148fe53ac8320732939fcbb0d9c

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f2ee07b9d58289de8230561f13641470198cdae1c0c84a3d8a6a83705fbbfda
MD5 5e7520a2838ea5008b71c3dfca52ee5b
BLAKE2b-256 030fb761376d05d58f754f98eb1a619fc0d300abdaf36261c07197bdab218281

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp39-cp39-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 447885f23eca592a430d6125ef313cf2efe89d456f744c7d7e8229d3f6ae9977
MD5 d84b32ad9e6f228a45ccb06c7402eb30
BLAKE2b-256 37f884e341fd6caad2f7c56aa4b069652b94b106a5ac5487921263b8c96e5c0e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-0.2.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 06469090b383e742c9ca010ff84f14085aaff4affc28c8f127793fb5e3cf5478
MD5 61b3ea1f2f55c8cfa849e3bcf987b908
BLAKE2b-256 f132a8af6ba3fe9b258ba6c84e20a45e83f9b6bc3345c455c09546180284f977

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0860c3187e4496c0e57763bf7c43dec036b84d9d6c3d7dd889b1e842d7dd0b61
MD5 b0d56e06f3f664b80aeded8cdaa561d6
BLAKE2b-256 5cd1b5dc6cfba989777bbaf97a0d985a9ff9bfbb4ebc69a3810eddb001fb3a04

See more details on using hashes here.

File details

Details for the file slipcover-0.2.2-cp38-cp38-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.2.2-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 85d5611aad47d73605ac917b500cfba3fd6f88d0f638d9886b8c6f24f53bdbca
MD5 bec1058f5ea1f37746ab5e372a4fa5c0
BLAKE2b-256 50e10d7eb232c76d2fb3c11208cb504c165bdbbe0f7633684257da4897bc5202

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