Skip to content

Commit 541e7ef

Browse files
committed
feat: formatResultSummary shows L1/L2 cache hit rates
Display per-DO (L1) and per-datacenter (L2) page cache hit rates in the one-line summary. Complements the merge telemetry fix that now propagates cacheHits/cacheMisses/edgeCacheHits/edgeCacheMisses from fragment DOs through the merge layer. Example: "20 rows in 3.2ms | L1: 8/10 hits | L2: 3/10 hits"
1 parent ca216ae commit 541e7ef

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/format.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ describe("formatResultSummary", () => {
9494
expect(summary).toContain("meta: 2.0ms");
9595
});
9696

97+
it("includes L1 and L2 cache hit rates", () => {
98+
const result: QueryResult = {
99+
rows: [{}], rowCount: 1, columns: ["a"],
100+
bytesRead: 1000, pagesSkipped: 0, durationMs: 5.0,
101+
cacheHits: 8, cacheMisses: 2,
102+
edgeCacheHits: 3, edgeCacheMisses: 7,
103+
};
104+
const summary = formatResultSummary(result);
105+
expect(summary).toContain("L1: 8/10 hits");
106+
expect(summary).toContain("L2: 3/10 hits");
107+
});
108+
109+
it("omits cache stats when zero", () => {
110+
const result: QueryResult = {
111+
rows: [{}], rowCount: 1, columns: ["a"],
112+
bytesRead: 0, pagesSkipped: 0, durationMs: 1.0,
113+
};
114+
const summary = formatResultSummary(result);
115+
expect(summary).not.toContain("L1:");
116+
expect(summary).not.toContain("L2:");
117+
});
118+
97119
it("singular row", () => {
98120
const result: QueryResult = {
99121
rows: [{}],

src/format.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export function formatResultSummary(result: QueryResult & Partial<LocalTimingInf
5757
parts.push(`wasm: ${result.wasmExecMs.toFixed(1)}ms`);
5858
}
5959

60+
if ((result.cacheHits ?? 0) + (result.cacheMisses ?? 0) > 0) {
61+
parts.push(`L1: ${result.cacheHits ?? 0}/${(result.cacheHits ?? 0) + (result.cacheMisses ?? 0)} hits`);
62+
}
63+
64+
if ((result.edgeCacheHits ?? 0) + (result.edgeCacheMisses ?? 0) > 0) {
65+
parts.push(`L2: ${result.edgeCacheHits ?? 0}/${(result.edgeCacheHits ?? 0) + (result.edgeCacheMisses ?? 0)} hits`);
66+
}
67+
6068
if (result.spillBytesWritten && result.spillBytesWritten > 0) {
6169
parts.push(`${formatBytes(result.spillBytesWritten)} spilled`);
6270
}

0 commit comments

Comments
 (0)