Skip to main content

Near Zero-Overhead Python Code Coverage

Project description

license pypi pyversions tests

Slipcover: Near Zero-Overhead Python Code Coverage

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

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 and tracking coverage using Slipcover, 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, at 5% or less overhead.

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 --disable-warnings
============================================================================= test session starts ==============================================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/juan/project/wally/d2k-5
collected 439 items                                                                                                                                                            

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

================================================================= 438 passed, 1 skipped, 53 warnings in 55.31s =================================================================

File                #lines    #missed    Cover%  Lines missing
----------------  --------  ---------  --------  ---------------------------------------------------------------------------------------------------
d2k/__init__.py          3          0       100
d2k/network.py         359          1       100  236
d2k/box.py             105         27        74  73, 142, 144-146, 148-149, 151, 154, 156-159, 161, 163-166, 168, 170-171, 173-174, 176-177, 180-181
d2k/image.py            38          4        89  70-73
tests/darknet.py       132         11        92  146, 179-181, 183-187, 189, 191
$

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

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.1.3.tar.gz (22.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-0.1.3-cp310-cp310-win_amd64.whl (78.8 kB view details)

Uploaded CPython 3.10Windows x86-64

slipcover-0.1.3-cp310-cp310-manylinux_2_24_x86_64.whl (42.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

slipcover-0.1.3-cp310-cp310-macosx_10_15_universal2.whl (22.0 kB view details)

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

slipcover-0.1.3-cp39-cp39-win_amd64.whl (78.8 kB view details)

Uploaded CPython 3.9Windows x86-64

slipcover-0.1.3-cp39-cp39-manylinux_2_24_x86_64.whl (42.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64

slipcover-0.1.3-cp39-cp39-macosx_10_15_universal2.whl (22.0 kB view details)

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

slipcover-0.1.3-cp38-cp38-win_amd64.whl (78.8 kB view details)

Uploaded CPython 3.8Windows x86-64

slipcover-0.1.3-cp38-cp38-manylinux_2_24_x86_64.whl (42.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.24+ x86-64

slipcover-0.1.3-cp38-cp38-macosx_10_14_universal2.whl (21.9 kB view details)

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

File details

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

File metadata

  • Download URL: slipcover-0.1.3.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.12

File hashes

Hashes for slipcover-0.1.3.tar.gz
Algorithm Hash digest
SHA256 643eee1082f0f7550366c09af65cf579f071709c822e7451ae20fe4cc97d8364
MD5 f5aa2f07f1a41dc1d486f653a2eb84fc
BLAKE2b-256 119457e8bc6adb322c29e7dc5ceb61b49fb238b8e5a3278d4058a527d102a91f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slipcover-0.1.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 78.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for slipcover-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d58413643f593b74ce294832f6cc67bd3f13c079710e22d6244fbcb4f9f3a89b
MD5 a92cccff6bf07874d438075cb2afc720
BLAKE2b-256 0cbddd9da4ca55c66c91360ff643338be318bed307a56b696f1a3469238a69e8

See more details on using hashes here.

File details

Details for the file slipcover-0.1.3-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.1.3-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 a2378497fdb24b2375da7c22266060ccad3c10d123c3dbc53e3e458a8283f6fb
MD5 03d9de39895b556e0f52d7d546a24d53
BLAKE2b-256 6c00b2e652ed26f1dce3c2d7c99f18391430871c280e4318c1b47378f57e6777

See more details on using hashes here.

File details

Details for the file slipcover-0.1.3-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.1.3-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 a7f7e84755e8820d6d9fad5dfb1d0f36106d85c2399b3f07cae219e41cd35fb3
MD5 fd29c7c06d41ff78d541bb2932f4dfef
BLAKE2b-256 e60db323588c83589282ed93a91953ab3ac3664ea8320e44c1b93006ea22c07a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slipcover-0.1.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 78.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for slipcover-0.1.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2ee8891c396d02623227d5a3ad65fd7e99c70b2a11a2de55cf4983ba32d58c23
MD5 f35a96597f515f9daadd3c6a609d4232
BLAKE2b-256 b26c9f81b09edd1e6f6727c1f269c86275a5f94b48c3623997fabf52666183db

See more details on using hashes here.

File details

Details for the file slipcover-0.1.3-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.1.3-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 12a388c0cd40908a6af62933751a9b8cfcd484f20244af5aadf9ad7729909954
MD5 c3eec64861916f4afbe5255aa6dd296f
BLAKE2b-256 afc6aede35c92e9aaa785e6f77a8ec9ca4418ec72d694521e9f7822ced91c5cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slipcover-0.1.3-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 3c2fa2605ddffd211f7fd3b705e1f69c44dd350bf1f1de8ae31328d470aad889
MD5 a2d99ca3f0c3f73d56224062e3f44198
BLAKE2b-256 732bccb37eb100b78400112012c0867e19eca1d1eb745f005984b63da583e32a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slipcover-0.1.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c35328cf9bb2e3ae103a24d2d0bdf8091ec582a064b8683f4a24b6a084bfbbdc
MD5 3f3670f44d6d06fb2b8cc654758e5a2d
BLAKE2b-256 dc9c99619aa5bd30a79ce2dcb0f71ecd885a7ddcb883856fbe59bdbc08878c32

See more details on using hashes here.

File details

Details for the file slipcover-0.1.3-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for slipcover-0.1.3-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 7e51ff6cec267b2aa67e63c89b1f7534692568159a3692edb5cfa40e76fb9b68
MD5 40bc4269b97a869295f92f1b6de275fa
BLAKE2b-256 c787b81f5a19faba00b7f5c48b4e0d80de1d1de44aa99e2e7a276dd19161c7d4

See more details on using hashes here.

File details

Details for the file slipcover-0.1.3-cp38-cp38-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for slipcover-0.1.3-cp38-cp38-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 00101a98c4e51128e111cc01aa0f2ce848f8626b324cd900542decda75843942
MD5 d9b7453e7919a83a82721305cf8ddb08
BLAKE2b-256 239b65107747a6c4ebd90effd772351211af210021cfe097e9f6fe4d149a1337

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