Skip to content

Trace format ​

When kern-serve runs with --trace --trace-dir <DIR> (or a hosted manifest runs with KERN_TRACE_DIR=<DIR>), CUPTI's hardware event system (HES) timestamps every GPU kernel execution in hardware without inserting synchronization between launches. Each rank streams those records into pairs of Apache Parquet files. kern-serve also samples the GPU's own performance counters every 100 µs by default (--trace-pm-us, 0 to turn off) into a third file beside each pair.

Trace an SGLang server records a hosted manifest step by step, with a sample trace to query.

Traces record GPU timing and manifest identifiers only. Prompts, token IDs, completions, request identifiers, and client metadata are never written.

Layout and rotation ​

Each rank writes one file pair per UTC quarter hour under Hive-style partition directories:

text
<trace-dir>/date=YYYY-MM-DD/rank=<q>/HHMMSS.steps.parquet
<trace-dir>/date=YYYY-MM-DD/rank=<q>/HHMMSS.kernels.parquet
<trace-dir>/date=YYYY-MM-DD/rank=<q>/HHMMSS.counters.parquet

HHMMSS is the UTC wall-clock time when the pair opened on its first write in that quarter hour. The counters file, when the rank samples counters, opens and closes with the pair. While open, the files carry a .parquet.part suffix; they are closed and atomically renamed to .parquet at the next quarter-hour boundary, on POST /kern/trace/rotate (served on --trace-port), or on clean process exit. Globbing *.parquet reads only finalized files.

A hosted manifest has no trace port: touching <trace-dir>/rotate closes its files instead. SGLang ends its scheduler with a signal, which is no clean exit, so rotate before stopping the server. Under SGLang's --dp-size above one, every replica is a group of its own and writes this layout under <trace-dir>/dp=<i> (rotated by <trace-dir>/dp=<i>/rotate), so rank stays the rank within a replica and dp reads as one more partition.

Files use Zstandard compression (level 3), dictionary encoding for strings, and delta encoding for integer columns.

Schemas ​

steps.parquet ​

One row per manifest program execution issued on that rank:

ColumnArrow typeNullableMeaning
seqUInt64NoPer-process step counter starting at 1; resets on server restart
programUtf8NoManifest program name (for example load, prefill, decode, round)
shapeUtf8NoBucket label: exact name=value vars for CUDA graphs (seqs=1,tokens=16), or powers of two for eager launches (seqs<=1,tokens<=64)
varsUtf8NoExact variable values passed to the program (seqs=1,tokens=60)
kvUInt64YesExact sum of seq_len across active sequences; null when none apply
graphBooleanNotrue when launched as a captured CUDA graph
start_nsInt64NoStart of the step's first kernel, in Unix nanoseconds
end_nsInt64NoEnd of the step's last kernel, in Unix nanoseconds

Sample rows from a live steps.parquet file:

seqprogramshapevarskvgraphstart_nsend_ns
1load(empty)(empty)nullfalse17943735761532988261794373576154167403
2prefillseqs<=1,tokens<=64seqs=1,tokens=6060false17943736796571827861794373679840495810
3roundseqs=1,tokens=16seqs=1,tokens=1676true17943736798642328151794373679896459210
250roundseqs=4,tokens=64seqs=4,tokens=64190917true17943739446735339231794373944727533892

kernels.parquet ​

One row per GPU kernel execution on that rank, sorted by start_ns:

ColumnArrow typeNullableMeaning
seqUInt64Yessteps.seq of the owning step; null for runtime copies or fills outside a program
start_nsInt64NoKernel start timestamp on the GPU, in Unix nanoseconds
dur_nsInt64NoKernel execution duration on the GPU, in nanoseconds
callUtf8YesManifest call label, else <op>#<index> (? if a graph replay did not match capture 1:1; null when seq is null)
opUtf8YesManifest operator name (null when seq is null)
kernelUtf8NoUnderlying CUDA kernel symbol reported by CUPTI

Sample rows from the matching kernels.parquet file (note that a single manifest call such as l3.attention may launch multiple CUDA kernels):

seqstart_nsdur_nscallopkernel
317943736798642328154001verify.kv_planverify_kv_planattention_plan
31794373679869635030151648l0.gate_upverify_linear_34816_5120fp8_block_gemm
317943736798707048241056l3.attentionverify_attention_flashinferquantize_q
317943736798707060408000l3.attentionverify_attention_flashinferprefill_fp8
null17943736801240065902592nullnullflag

counters.parquet ​

One row per counter sample on that rank, back to back in time. Each row is the whole GPU's counters averaged over the sample's window, read by the GPU itself with no kernel replayed or inserted:

ColumnArrow typeNullableMeaning
start_nsInt64NoWindow start in Unix nanoseconds, on the same timeline as kernels.start_ns
dur_nsInt64NoWindow length in nanoseconds (the --trace-pm-us interval)
sm_mhzUInt16NoSM clock in MHz
sm_active_permilleUInt16NoPermille of elapsed cycles an SM had a warp resident, averaged over SMs
tensor_active_permilleUInt16NoPermille of elapsed cycles the tensor pipes were busy, averaged over SMs
dram_read_gbsUInt16NoDRAM read bandwidth in GB/s
dram_write_gbsUInt16NoDRAM write bandwidth in GB/s

Sampling raises the GPU's power draw by about 35 W at any interval and does not change kernel durations. The interval cannot go below 50 µs, because the host spends about 20 µs decoding each sample.

Joining tables and reading metadata ​

seq is unique only within a single rank process. Always join steps and kernels within the same server session and rank, never on seq alone across restarts or ranks. Timestamps are CUPTI hardware timestamps shifted by the host wall-clock offset sampled when the file pair opened, so ranks, files, and logs share one Unix nanosecond timeline.

Every file also carries Parquet footer key-value metadata:

KeyMeaning
kern.rankRank ordinal that wrote the file
kern.modelmodel identifier from the manifest
kern.manifest_sha256SHA-256 hex digest of the manifest JSON as read
kern.versionWriter binary version and CUDA build
kern.clock_offset_nsNanoseconds added to CUPTI clock values to obtain Unix time
kern.hestrue when the GPU stamped kernels in hardware; false if CUPTI fell back to software timestamps
kern.dropped_recordsCumulative kernel records lost by CUPTI in this process when the file closed

Using a trace ​

1. Build a benchmark workload from live traffic ​

Build a benchmark workload from live traffic: 261,672 online GPU steps fold into 157 weighted shape-by-KV buckets, allowing a 6-minute offline replay to predict over 7 hours of online GPU time within 0.90%

kern workload reads one rank's steps.parquet files, groups steps by (program, shape, kv bucket), and emits a weighted TOML workload that kern bench can price against any candidate manifest for the same model:

sh
kern workload --manifest manifest.json \
  --trace traces/date=2026-11-11/rank=0 \
  --out served.toml

kern bench demo --workload served.toml --out bench.json

Each bucket preserves its step count and mean context, and kern workload reports its bucketing fidelity on the CPU before touching a GPU. A full session of live traffic (~262k steps, 7.3 hours of GPU execution) folds into ~160 scenarios that kern bench prices in about six minutes, matching traced GPU step time within 1% (+0.29% bucket fidelity, +0.90% replayed GPU cost).

Pass a single rank's directory (rank=0) rather than all ranks combined, since kern bench issues each call across every rank of the manifest.

2. Break down operator and context cost in SQL ​

Because directories use date= and rank= Hive partitions, DuckDB, Polars, and PyArrow can query a session directly without ETL:

sql
SELECT
  s.program,
  s.shape,
  k.op,
  count(DISTINCT s.seq) AS steps,
  round(sum(k.dur_ns) / 1e6, 1) AS gpu_ms
FROM read_parquet('traces/date=*/rank=*/*.steps.parquet') s
JOIN read_parquet('traces/date=*/rank=*/*.kernels.parquet') k
  USING (rank, seq)
GROUP BY s.program, s.shape, k.op
ORDER BY gpu_ms DESC
LIMIT 15;

Counters join on time instead of seq. A step's counters are the samples that fall inside it:

sql
SELECT
  s.program,
  count(*) AS samples,
  round(avg(c.sm_active_permille) / 10, 1) AS sm_active_pct,
  round(avg(c.tensor_active_permille) / 10, 1) AS tensor_pct,
  round(avg(c.dram_read_gbs)) AS dram_read_gbs
FROM read_parquet('traces/date=*/rank=*/*.steps.parquet') s
JOIN read_parquet('traces/date=*/rank=*/*.counters.parquet') c
  ON c.rank = s.rank
 AND c.start_ns >= s.start_ns
 AND c.start_ns + c.dur_ns <= s.end_ns
GROUP BY s.program;

Grouping steps by kv buckets (for example floor(kv / 32768) * 32768) with summed k.dur_ns per op isolates how attention, linear layers, or recurrent state scale with context length under real traffic.

3. Diagnose host gaps and multi-rank skew ​

  • Inter-step gaps: start_ns - lag(end_ns) OVER (PARTITION BY rank ORDER BY seq) in steps.parquet measures host scheduling, tokenization, or idle intervals between GPU programs.
  • Unclaimed device work: rows in kernels.parquet where seq IS NULL capture runtime copies, page transfers, or synchronization kernels outside manifest programs.
  • Rank imbalance: comparing compute vs. collective op durations across rank=0..N-1 on the shared Unix nanosecond timeline separates a slow compute rank from peers waiting in nccl_* or peer-buffer reads.

Models ship as verified GPU programs.