Easy profiling in chrome trace format
Project description
keke
This project is an extremely simple trace-event writer for Python.
You can read the traces in Perfetto or chrome's about:tracing. This only
writes the consensus dialect that works in both, and is tiny enough to just
vendor on the off-chance that you want tracing in the future.
If your needs are more like a line profiler, you might want either pytracing (slightly abandoned, the git version does work in py3) or viztracer (unsuitable for vendoring in other projects due to size, but actively maintained).
I drew inspiration from both in writing this.
Simple Example
from __future__ import annotations # for IO[str]
from typing import IO, Optional
import time
import click
@click.command()
@click.option("--trace", type=click.File(mode="w"), help="Trace output filename")
@click.option("--foo", help="This value gets logged")
def main(trace: Optional[IO[str]], foo: Optional[str]) -> None:
with keke.TraceOutput(file=trace):
with kev("main", __name__, foo=foo):
sub()
def sub():
with kev("sub1", __name__):
time.sleep(1)
with kev("sub2", __name__):
time.sleep(2)
Overhead
Very close to zero when not enabled.
The easiest way to not-enable is call TraceOutput(file=None) which will do nothing.
Processes, or "how to get to distributed tracing"
This approach avoids all magic.
If you're calling another (trace-aware) program, then the simplest thing to do is come up with a unique name and pass that to the child in argv, then attempt to merge that yourself once it's done.
If you're doing something like fork/spawn to continue python work, then the parent can control basic information (like the tmpdir to write to) and the child can open a unique file with its pid.
If you're doing something more distributed, you might come up with a guid and pass that to the child instead, for the child to tag it for later log uploading.
What's with the name
I was trying to come up with a short, memorable name and some of the rendered trace points were very pointy, which reminded me of the "bouba/kiki effect." The name "kiki" was taken but "keke" was not.
Version Compat
Usage of this library should work back to 3.7, but development (and mypy compatibility) only on 3.10-3.12. Linting requires 3.12 for full fidelity.
Versioning
This library follows meanver which basically means semver along with a promise to rename when the major version changes.
License
keke is copyright Tim Hatch, and licensed under
the MIT license. See the LICENSE file for details.
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 keke-0.2.0.tar.gz.
File metadata
- Download URL: keke-0.2.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f453a0e064e1cab643e717fc5236a0463e70f805588fd0904aa5e84a2934f3b
|
|
| MD5 |
ddb5fb06ea26c24a7e71ef434a58120c
|
|
| BLAKE2b-256 |
9f371cff3cb88fe5c79da61c8cc2cd84b4c8777ee51b00e98c2a9faf1e255503
|
Provenance
The following attestation bundles were made for keke-0.2.0.tar.gz:
Publisher:
build.yml on keke-tracing/keke
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keke-0.2.0.tar.gz -
Subject digest:
1f453a0e064e1cab643e717fc5236a0463e70f805588fd0904aa5e84a2934f3b - Sigstore transparency entry: 171956284
- Sigstore integration time:
-
Permalink:
keke-tracing/keke@b4cba89efd31c0e3f76466ce5dbe82025fb1c3ce -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/keke-tracing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@b4cba89efd31c0e3f76466ce5dbe82025fb1c3ce -
Trigger Event:
push
-
Statement type:
File details
Details for the file keke-0.2.0-py3-none-any.whl.
File metadata
- Download URL: keke-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb71324bd1d5240813b0830a7b5a19748b45569eb0c2edcd620401a6d07b673d
|
|
| MD5 |
ce6ad2f5daa780bea9fc98fd16569283
|
|
| BLAKE2b-256 |
ee71425a19e6ca988534240bb5ce6f77ba5070d345e688aa7420e8edc51c243f
|
Provenance
The following attestation bundles were made for keke-0.2.0-py3-none-any.whl:
Publisher:
build.yml on keke-tracing/keke
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keke-0.2.0-py3-none-any.whl -
Subject digest:
fb71324bd1d5240813b0830a7b5a19748b45569eb0c2edcd620401a6d07b673d - Sigstore transparency entry: 171956286
- Sigstore integration time:
-
Permalink:
keke-tracing/keke@b4cba89efd31c0e3f76466ce5dbe82025fb1c3ce -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/keke-tracing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@b4cba89efd31c0e3f76466ce5dbe82025fb1c3ce -
Trigger Event:
push
-
Statement type: