Skip to main content

latency-steps

English | 한국어

Someone says "it got slower". latency-steps reads your raw JSONL or CSV event log offline and tells you, per key (tool, endpoint, model), when latency stepped up and whether that step is one host, a shift in the load mix, or everything. It builds p50/p90 time series with DuckDB, finds sustained steps with a small pure-Python change-point detector, and then splits the windows before and after each step by the dimensions you name.

Terminal output of latency-steps demo: three findings and one observation One command on built-in synthetic practice data: three sustained steps (findings) and one one-day spike (observation).

Who it is for

  • You run a backend or an agent and keep tool-call, API or model-response logs as files, and you get "it feels slower since last week".
  • You want to know whether a slowdown is a bad host, a change in what kind of traffic arrives, or a global change, before the meeting.
  • You want a nightly CI job that fails when a new latency step appears.

Install

Needs Python 3.11 or newer (DuckDB 2.0 requires it) and uv.

curl -LsSf https://astral.sh/uv/install.sh | sh     # installs uv (macOS / Linux)
git clone https://github.com/LeeGyeongPil/latency-steps
cd latency-steps
uv tool install .                                    # puts `latency-steps` on your PATH
latency-steps --version
latency-steps 0.2.0

On a minimal Linux image you also need git and curl (and ca-certificates). The only runtime dependency is duckdb.

Or run straight from the clone without installing: uv run latency-steps demo.

Quick start: the practice mode

demo is a practice (mock) mode: it writes a seeded synthetic log (4 keys x 4 hosts x 21 days, about 20,000 rows) and analyzes it through the same code path as a real file. The numbers are planted, not a real incident, and the screen says so. Nothing else is faked, and no network or API key is involved.

latency-steps demo --lang en
*** SYNTHETIC PRACTICE DATA - the numbers are planted, not a real incident. ***

Latency step report (latency-steps 0.2.0)
Input: demo (seed 7, 21 days, 40/hour) - 20160 rows read, 20160 kept, dropped rows 0
Fields: timestamp=ts, duration=duration_ms (ms), key=tool
Buckets: day (UTC), min rows 30, step lasts 3+ buckets, change x1.2+

Findings (3) - sustained steps
key     since       p50 before > after  p90 before > after  ratio        verdict    where
------  ----------  ------------------  ------------------  -----------  ---------  -------------------
embed   2026-10-13  299 ms > 344 ms     478 ms > 1.55 s     x3.25 (p90)  localized  host = h3
rerank  2026-10-09  508 ms > 689 ms     775 ms > 1.98 s     x2.56 (p90)  mix shift  concurrency: new 8+
search  2026-10-11  1.20 s > 3.39 s     1.87 s > 5.18 s     x2.83 (p50)  global     all cells

Observations (1) - worth a look, not a sustained step
key   when        kind         ratio
----  ----------  -----------  -----------
chat  2026-10-06  brief spike  x2.88 (p50)

(The full report continues with one evidence table per finding and dimension.) How to read it:

  • Findings are steps that lasted at least 3 buckets and changed p50 or p90 by at least x1.2. since is the first bucket at the new level.
  • search got slower everywhere (global), embed only on host h3 (localized; its overall p50 barely moves, which is why the p90 column matters), rerank because a new kind of traffic appeared (mix shift).
  • Observations are things that went back (chat was slow for one day only) or went the other way. They are shown but never counted as a step.

Analyze your own logs

latency-steps analyze app.jsonl --key tool --by host --by concurrency:1-3,4-7,8+
Option What it does Example
path JSONL or CSV file (comma, semicolon, tab or pipe separated; UTF-8 with BOM, e.g. Excel exports, is fine; durations need a dot as decimal separator), .gz / .zst also work, - reads standard input app.jsonl.gz, -
--ts FIELD Timestamp field. Default: the first of ts, timestamp, time, ... that exists --ts time
--duration FIELD Latency field. Default: the first of duration_ms, latency_ms, duration, ... --duration elapsed
--duration-unit ms|s|us Unit of bare numbers (guessed from the field name, else ms). Values like 12ms or 1.2s are read as written --duration-unit s
--key FIELD One series per value of this field. Default: a single series --key endpoint
--by DIM Dimension to stratify by, repeatable: a field, or numeric ranges field:1-3,4-7,8+ --by host
--bucket hour|day|auto Time bucket (auto = day when the log spans 14+ days) --bucket hour
--min-n N Buckets with fewer rows are left out of the series (default 30) --min-n 50
--min-run N A step must last this many buckets (default 3) --min-run 4
--min-ratio X A step must change p50 or p90 by this factor (default 1.2) --min-ratio 1.5
--metric p50|p90|both Which percentile series to inspect (default both) --metric p90
--tz ZONE Bucket time zone (default UTC) --tz Asia/Seoul
--only KEY Analyze only this key, repeatable --only search
--memory-limit SIZE DuckDB memory cap (default 1GB); raise it for very large inputs --memory-limit 4GB
--format table|md|svg|json, --out FILE Output format and destination --format md --out report.md
--fail-on-step Exit with code 1 when a step is found
--lang en|ko Screen language --lang ko

latency-steps demo takes the same output options plus --seed, --per-hour and --save FILE (keep the synthetic log as a JSONL file to experiment on).

Messy logs are reported, not fatal

Broken lines, unparseable timestamps and values like "12ms" do not stop the run. Values are read as text and converted tolerantly; rows that cannot be interpreted are counted and shown. Rows with invalid UTF-8 bytes are counted too, in JSONL and in CSV. Here two bad lines were appended to a saved demo log:

latency-steps demo --save app.jsonl > /dev/null
printf 'not json at all\n{"ts":"yesterday-ish","duration_ms":"12ms","tool":"search","host":"h1","concurrency":2}\n' >> app.jsonl
latency-steps analyze app.jsonl --key tool --by host --only search --lang en | head -3
Latency step report (latency-steps 0.2.0)
Input: app.jsonl - 20162 rows read, 20160 kept, dropped rows 2
  dropped: unparseable line 1, bad timestamp 1

Terminal output showing dropped rows and why Rows that could not be used are counted with a reason.

How it decides

Think of a body-temperature chart. One hot afternoon is not a fever; a week at a higher level is.

  1. Percentiles, not averages. For each key and time bucket it computes p50 (the typical request) and p90 (the slow tail). A regression that hits one host in four barely moves p50 but shows up in p90. Buckets with fewer than --min-n rows are skipped and reported, so a quiet night cannot fake a step.
  2. Change points on a log scale. The series is split recursively where the medians on the two sides differ most, measured in units of how noisy the series is. Median-based, so a single odd day does not become a step. The log scale means "twice as slow" counts the same at 100 ms and at 3 s.
  3. Steps versus spikes. Instead of tuning a penalty number, you say how long (--min-run) and how big (--min-ratio) a change must be. Short or reverting changes become observations.
  4. Stratify. For every finding the windows before and after are split by each --by dimension, and each cell gets its row counts, before/after value, ratio and share of traffic.

Reading the verdict

Verdict Meaning Look at
localized Only a few cells got slower the host, region or version in the where column
mix_shift Cell ratios are flat, or a cell that did not exist before appeared: the traffic changed, not the code path's speed the share before > after column and new notes
global At least 80% of cells got slower a change that touches everything: deploy, dependency, shared service
inconclusive Cells are too thin or two cells moved together the table; collect more data

With several --by dimensions the overall verdict is chosen in the order localized > mix shift > global > inconclusive. The rerank story in the demo is Simpson's paradox: judged by host every host is about x2.5 slower, yet by concurrency the old cells are flat and a cell 8+ that had no rows before carries the whole step.

latency-steps demo --only rerank --lang en
  by concurrency: mix shift - a cell that did not exist before appeared
    cell  rows before/after  p90              ratio  share before > after  note
    ----  -----------------  ---------------  -----  --------------------  ----
    1-3   1459/793           779 ms > 797 ms  x1.02  75% > 26%
    4-7   479/1049           744 ms > 794 ms  x1.07  25% > 34%
    8+    0/1240             - > 2.45 s       -      0% > 40%              new

Stratification table for rerank: host cells all slower, concurrency cells flat, new cell 8+ The verdicts are heuristics. Always read them together with the cell tables.

Reports

  • --format md --out report.md writes Findings, Observations and the stratification tables as Markdown.
  • --format svg --out chart.svg writes one small panel per key with p50 and p90 lines, a vertical line at each step and a dot on spikes.
latency-steps demo --format svg --out chart.svg --lang en

Small-multiple chart of p50 and p90 per key with step lines The SVG report of the demo log.

  • --format json writes a stable structure with "schema_version": 1. Keys and verdict codes are always English; only the summary strings follow --lang.

CI usage

Exit codes: 0 ok, 1 a step was found (only with --fail-on-step), 2 input or option error.

latency-steps demo --format json --fail-on-step --lang en > steps.json; echo "exit=$?"; grep -m 2 -E '"(schema_version|summary)"' steps.json | cut -c1-110
exit=1
  "schema_version": 1,
  "summary": "embed: p90 went from 478 ms to 1.55 s (x3.25) starting 2026-10-13; verdict localized. rerank: p9

JSON summary and exit code 1 In CI, replace demo with analyze nightly.jsonl --key tool and let the exit code fail the job.

- run: latency-steps analyze nightly.jsonl --key tool --by host --format json --fail-on-step > steps.json

Language

The screen is available in English and Korean. Priority: --lang en|ko > LATENCY_STEPS_LANG > LC_ALL / LC_MESSAGES / LANG (a value starting with ko selects Korean, anything else English). Help text, tables, Markdown and SVG labels follow it.

LATENCY_STEPS_LANG=ko latency-steps demo

Help text of latency-steps analyze latency-steps --lang en analyze --help. The same screen exists in Korean.

How it works

flowchart LR
  IN[JSONL / CSV / gz / stdin] --> ING[ingest<br/>tolerant parsing]
  DEMO[demo<br/>synthetic log] --> ING
  ING --> SER[series<br/>p50, p90 per key and bucket]
  SER --> DET[detect<br/>robust binary segmentation]
  DET -->|finding| STR[stratify<br/>cells before / after]
  STR --> VER[verdict]
  DET -->|observation| OUT
  VER --> OUT[table, md, svg, json]
  OUT --> EXIT[exit code 0 / 1 / 2]

Ingest and the percentile series run in DuckDB; detection and verdict rules are plain Python standard library (math), no numpy, scipy or ruptures.

Limits

  • Verdicts are heuristics read from cell tables. Two hosts degrading together, or thin cells, give inconclusive.
  • A regression diluted across a large share of traffic is only caught through the p90 series. Per-dimension detection (--detect-by) is not in 0.2.0.
  • Hourly buckets of a multi-day outage appear as a step up and a step down; use --bucket day for day-level questions.
  • Rows (CSV) and lines (JSONL) with invalid UTF-8 are counted as invalid UTF-8 in the dropped-rows summary, not analysed. Convert a CSV to UTF-8 first if it may contain other encodings.
  • .zst input relies on DuckDB reading it and is not covered by an automated test.
  • The field-name check for JSONL looks only at the first 50 non-blank lines, so a field that first appears later in the file is reported as missing; reorder the file or pass names that appear early.
  • It answers "when" and "where", not "why". Pair the result with your deploy and config history.

When to use it

  • Good fit: you have raw event logs as files, you do not know when a slowdown started, and you want a first narrowing by host, region or load level without a server.
  • Other tools for other jobs: change-point detection on already-aggregated benchmark metrics in a CI store, see Apache Otava; change-point algorithms as a library, see ruptures; interactive exploration of live traces in a hosted service, see Honeycomb BubbleUp; browsing and querying log files, see lnav.

Troubleshooting

Symptom Cause Fix
An installation error about the Python version DuckDB 2.0 needs Python 3.11+ Use uv python install 3.13 or any 3.11+ interpreter
error: input file not found and exit code 2 Wrong path Check the path, or pass - to read standard input
error: could not find the nosuch field. Fields seen: ts, duration_ms, ... and exit code 2 A --key, --by, --ts or --duration name does not exist in the file (checked in the first 50 non-blank lines of JSONL, and in the CSV header) Use one of the names listed after Fields seen:
error: the file is empty: no non-blank lines found. and exit code 2 The file has no content, for example a log rotation just happened Point to the right file
error: could not read the input: ... and exit code 2 DuckDB cannot read the file at all, for example mixed line endings or corrupt data (rows with invalid UTF-8 are not this error; they are counted as dropped rows) Normalise the line endings or repair the file
No findings on a log you know regressed Too few rows per bucket, or the step is shorter than --min-run buckets Lower --min-n, use --bucket hour, or lower --min-run
Many "dropped rows" The timestamp or duration field was picked wrongly Pass --ts and --duration explicitly; see the dropped: reason line
Verdict inconclusive Cells too thin or two cells moved together Read the cell tables, add a better --by dimension

Development

uv sync
uv run pytest -q
65 passed

Bugs and ideas are welcome as issues. Changes are listed in CHANGELOG.md.

More reading

License

MIT. All demo data is generated by the built-in generator.

Metadata

Release files for latency-steps 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latency-steps 0.2.0
File Size Uploaded Provenance Actions
latency_steps-0.2.0.tar.gz 818.8 kB Without provenance Details for latency_steps-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for latency-steps 0.2.0
File Interpreter ABI Platform Actions
latency_steps-0.2.0-py3-none-any.whl Python 3 none any Details for latency_steps-0.2.0-py3-none-any.whl

Total release size: 863.6 kB

Release files / latency_steps-0.2.0.tar.gz

Download URL latency_steps-0.2.0.tar.gz
Size 818.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e677dee4dc62e88cf6462d3fc7e1ff39372ba3ef93399a54dfc6f4fd6008680e
BLAKE2b-256 checksum
How to use checksums
47c089248da77e5a955de91abedfad5cb08349b40a14bc37183e73485035a84b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / latency_steps-0.2.0-py3-none-any.whl

Download URL latency_steps-0.2.0-py3-none-any.whl
Size 44.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8534470e13dd15c2e3636213aeef830cf770d61a220484f1afaba576c70d8d5
BLAKE2b-256 checksum
How to use checksums
53209369ce2ee4e03f2f5015a330c1ffa6269add32c71300752a00c8e262bf93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for latency-steps 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page