keke-stats
Collect process stats for keke traces.
keke-stats records low-frequency process metrics as keke counter events, so they show up alongside trace spans in Perfetto or Chrome Tracing.
Installation
pip install keke-stats
keke-stats depends on keke. It uses psutil where the standard library or platform files do not expose the needed process data directly: RSS on macOS and Windows, and handle counts on Windows.
Usage
The preferred API is a context manager. It starts a background stats thread on entry and stops it on exit:
import keke
import keke_stats
with open("trace.json", "w") as f:
with keke.TraceOutput(file=f):
with keke_stats.collect(period=0.5):
do_work()
You can also choose specific collectors and keep the Stats object:
with keke_stats.collect(["cpu", "rss"], period=1.0) as stats:
do_work()
For fire-and-forget usage, start collectors explicitly and stop them when done:
stats = keke_stats.start(["cpu", "fd", "rss"], period=0.5)
try:
do_work()
finally:
stats.stop()
Collectors
Available collectors:
| Collector | Events | Description |
|---|---|---|
cpu |
proc_cpu_pct |
Process CPU percentage over the sample period. |
fd |
num_fds |
Number of open file descriptors, or handles on Windows. |
rss |
proc_rss_mib, proc_peak_rss_mib |
Current RSS and peak RSS in MiB. |
By default, all collectors are enabled:
keke_stats.DEFAULT_STATS == ("cpu", "fd", "rss")
Notes
Stats are sampled from a single background thread per Stats instance. Collectors should be cheap process-local reads. If a collector becomes expensive, make it optional or move it to a dedicated collector implementation.
Peak RSS is the process-lifetime peak, not the peak since tracing started. This is intentional: it remains useful even if stats collection starts after the process has already been running.
Low-level helpers
The individual helper functions are public for callers that want to record their own counters:
keke_stats.get_fd_count()
keke_stats.get_rss_mib()
keke_stats.get_peak_rss_mib()
Version compatibility
This library supports Python 3.10+.
License
keke-stats is copyright Tim Hatch, and licensed under the MIT license. See the LICENSE file for details.
Metadata
Release files for keke-stats 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keke_stats-0.5.0.tar.gz | 51.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keke_stats-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.1 kB
Release files / keke_stats-0.5.0.tar.gz
| Download URL | keke_stats-0.5.0.tar.gz |
|---|---|
| Size | 51.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c48c62d536f45315e8d31d9e3dcf624f7578b54ba220c9246fa488524c916b2
|
|
BLAKE2b-256 checksum How to use checksums |
11d008c991857503b63638d5f3622565e160020ff67f33803052d19dfdcb4363
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logRelease files / keke_stats-0.5.0-py3-none-any.whl
| Download URL | keke_stats-0.5.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4984cf5d23fcd5e08657e0bd9e5dfc2295d28f6e2f22a91d22f7c2d3c9df5973
|
|
BLAKE2b-256 checksum How to use checksums |
7702cd285703523b817ff73b7568fbffdef843bb7b2bdc844da717663cdb9ad7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency log