Instrument, extend and visualize your programs
Project description
Voir
Voir lets you wrap your scripts to display certain values or metrics and/or analyze their behavior. To use Voir:
- Add a file named
voirfile.pyin the current directory. - Define one or more instruments in
voirfile.py. - Run
voir script.pyinstead ofpython script.py.
Here are a few things you can do:
- Patch functions and libraries prior to running a script
- Log CPU or GPU usage
- Manipulate or log streams of data coming from the script
- Show a nifty dashboard
Functioning
An instrument is a function defined in voirfile.py that begins with instrument_, or a value in the __instruments__ dictionary of the same file. It takes one argument, the overseer, and its purpose is to do things at various points during execution. In order to do so, it is implemented as a generator function: all it has is to yield one of the overseer's phases, and the overseer will return to the instrument after that phase is finished. The overseer defines the order, so you only need to yield the phases you want to wait for.
def instrument_show_phases(ov):
yield ov.phases.init
# Voir has initialized itself. You can add command-line arguments here.
yield ov.phases.parse_args
# The command-line arguments have been parsed.
yield ov.phases.load_script
# The script has been loaded: its imports have been done, its functions defined,
# but the top level statements have not been executed. You can perform some
# manipulations prior to the script running.
yield ov.phases.run_script
# The script has finished.
yield ov.phases.finalize
Voir also logs events in the 3rd file descriptor if it is open, or to the $DATA_FD descriptor. Consequently, if you run voir script.py 3>&1 you should be able to see the list of phases.
Example
This instrument adds a --time command-line argument to Voir. When given, it will calculate the time the script took to load and import its dependencies, and then the time it took to run, and it will print out these times.
def instrument_time(ov):
yield ov.phases.init
ov.argparser.add_argument("--time", action="store_true")
yield ov.phases.parse_args
if ov.options.time:
t0 = time.time()
yield ov.phases.load_script
t1 = time.time()
print(f"Load time: {(t1 - t0) * 1000}ms")
yield ov.phases.run_script
t2 = time.time()
print(f"Run time: {(t2 - t1) * 1000}ms")
The --time argument goes BEFORE the script, so you would invoke it like this:
voir --time script.py SCRIPT_ARGUMENTS ...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file voir-0.2.23.tar.gz.
File metadata
- Download URL: voir-0.2.23.tar.gz
- Upload date:
- Size: 69.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5876548e79b6579970ca757efbcefb73a5b36f399809302a724a8bf7102296a3
|
|
| MD5 |
8061916ce1e3ca373676c0a4d86efba1
|
|
| BLAKE2b-256 |
7c2a7fe30404520a112af331e1374783551a0510f29b273031f989724fa7eeeb
|
Provenance
The following attestation bundles were made for voir-0.2.23.tar.gz:
Publisher:
publish.yml on breuleux/voir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
voir-0.2.23.tar.gz -
Subject digest:
5876548e79b6579970ca757efbcefb73a5b36f399809302a724a8bf7102296a3 - Sigstore transparency entry: 775164041
- Sigstore integration time:
-
Permalink:
breuleux/voir@3e920aa5afe5d48368dfd9bc442be257d3b09142 -
Branch / Tag:
refs/tags/v0.2.23 - Owner: https://github.com/breuleux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e920aa5afe5d48368dfd9bc442be257d3b09142 -
Trigger Event:
push
-
Statement type:
File details
Details for the file voir-0.2.23-py3-none-any.whl.
File metadata
- Download URL: voir-0.2.23-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0091e40ef3f341100ae300af0304710d189d45f9cffcad1d2e79439f0902a1fe
|
|
| MD5 |
093ecc9f3f6b101e361bbf7bb9152709
|
|
| BLAKE2b-256 |
4d1e3c67d5887ae727f9df28802b804dcbf931ba55b41a438a986d04f89d6f97
|
Provenance
The following attestation bundles were made for voir-0.2.23-py3-none-any.whl:
Publisher:
publish.yml on breuleux/voir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
voir-0.2.23-py3-none-any.whl -
Subject digest:
0091e40ef3f341100ae300af0304710d189d45f9cffcad1d2e79439f0902a1fe - Sigstore transparency entry: 775164042
- Sigstore integration time:
-
Permalink:
breuleux/voir@3e920aa5afe5d48368dfd9bc442be257d3b09142 -
Branch / Tag:
refs/tags/v0.2.23 - Owner: https://github.com/breuleux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e920aa5afe5d48368dfd9bc442be257d3b09142 -
Trigger Event:
push
-
Statement type: