feat(timing): add --timing request phase breakdown (#14)#21
Merged
Conversation
Add a --timing flag that prints how long each phase of a request took: DNS lookup, TCP connection, TLS handshake, server processing (TTFB), content transfer, and total. The phases the Go transport can observe (connect, TLS, request-written, first-response-byte) are collected with net/http/httptrace. DNS is timed separately around the client's own concurrent resolver, since that resolution happens in a custom DialContext that httptrace cannot see. The client returns before the body is read, so it measures up to the first response byte and exposes TimeToFirstByte; main owns the overall wall clock and derives the content-transfer phase (Total - TimeToFirstByte). --timing is also persisted by save/run. Tests cover the phase() helper, that Fetch populates timing against a local server (and leaves it nil when not requested), the --timing flag parsing, and the rendered output format. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14.
Adds a
--timingflag that prints a per-phase breakdown of where a request spent its time, matching the issue's proposed output:How it works
net/http/httptrace.DialContext(Cloudflare 1.1.1.1 raced against the system resolver), which httptrace's DNS hooks can't observe, so the--timingpath records the DNS phase right there.TimeToFirstByte.mainowns the wall-clock window around the body read and derives the content-transfer phase asTotal - TimeToFirstByte.0sfor the phases it skipped rather than stale values.--timingis persisted bykurl save/kurl run.Acceptance criteria
--timingflaghttptracepackage for accurate measurements (plus explicit DNS timing for kurl's custom resolver)Tests
client:phase()helper edge cases;Fetchpopulates timing against a localhttptestserver (TCP/TTFB positive, TLS zero for http) and leavesTimingnil when not requested.main:--timingflag parsing (set and default).printer: rendered output format includes every phase label and value plusTotal.go test ./...,go vet ./..., andgofmtare all clean. Verified manually against both HTTPS (Cloudflare) and plain-HTTP endpoints.🤖 Generated with Claude Code