Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keke-0.3.0b2.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

keke-0.3.0b2-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file keke-0.3.0b2.tar.gz.

File metadata

  • Download URL: keke-0.3.0b2.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for keke-0.3.0b2.tar.gz
Algorithm Hash digest
SHA256 ddd828e3c8cc1ec1b67f9f073544b99a858747005f46504e48eb0ea851886c72
MD5 ffdd0a6b007bc5ee284b7dd02b74c4bc
BLAKE2b-256 2b174fbad910a28ae3deeee31c99a4a08cfd4df677ab8f339abe1ff2146a7b89

See more details on using hashes here.

Provenance

The following attestation bundles were made for keke-0.3.0b2.tar.gz:

Publisher: build.yml on keke-tracing/keke

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keke-0.3.0b2-py3-none-any.whl.

File metadata

  • Download URL: keke-0.3.0b2-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for keke-0.3.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 52d08274246472796ae06e95ae8ea11406a2d673a8dd173cfed4a79c141943a6
MD5 0ea265db8576c8f1cc481b278c00ed3d
BLAKE2b-256 de6392a31fcd350c87dfdad110e551014b6061a985b3eeca7cdf487895917ce8

See more details on using hashes here.

Provenance

The following attestation bundles were made for keke-0.3.0b2-py3-none-any.whl:

Publisher: build.yml on keke-tracing/keke

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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