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.

License

keke is copyright Tim Hatch, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. 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.1.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

keke-0.1.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file keke-0.1.4.tar.gz.

File metadata

  • Download URL: keke-0.1.4.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for keke-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a8653b7d9936ddae08d1ea2c298e5e36a50eb379705e3f74ab08b1f6ae3831a0
MD5 25c504220b1535bc84d6c8a9d4c70f54
BLAKE2b-256 7f9a3ccba0035eb9a92af133c896b18b32cc9195b5738bbc21dcbb58db056b41

See more details on using hashes here.

File details

Details for the file keke-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: keke-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for keke-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b16eb1f8dd768747cf55e9e272a02fc642a4a80718ff4feccb5cdcdf9290af0a
MD5 644a53e9c000ef0bc6c831ee8b5b0513
BLAKE2b-256 e3e90c70d5501b667988c4a340a2fc6006a58491a874f5aa1da56d0757e6336a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page