Skip to content

Commit b37735a

Browse files
committed
Don’t hide timings with value 0.
Introduce new type safe, composable functions for parsing and formatting. Apply to request/response timings to use consistent formatting for milliseconds, and to only treat -1, not 0, as a missing/invalid value.
1 parent 66ac350 commit b37735a

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

Diff for: src/ts/waterfall/details-overlay/extract-details-keys.ts

+32-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ import {getHeader} from "../../helpers/har";
22
import {Entry, Header} from "../../typing/har";
33
import {WaterfallEntry} from "../../typing/waterfall";
44

5+
function parseAndFormat<S, T>(source: S, parseFn: ((_: S) => T), formatFn: ((_: T) => string)): string {
6+
if (typeof source === "undefined") {
7+
return undefined;
8+
}
9+
const parsed = parseFn(source);
10+
if (typeof parsed === "undefined") {
11+
return undefined;
12+
}
13+
return formatFn(parsed);
14+
}
15+
16+
function parseNonNegative(n: number): number {
17+
if (n < 0) {
18+
return undefined;
19+
}
20+
return n;
21+
}
22+
23+
function formatMilliseconds(millis: number): string {
24+
return `${millis} ms`;
25+
}
26+
527
let ifValueDefined = (value: number, fn: (_: number) => any) => {
628
if (!isFinite(value) || value <= 0) {
729
return undefined;
@@ -154,16 +176,17 @@ function parseResponseDetails(harEntry: Entry): KvTuple[] {
154176
function parseTimings(entry: WaterfallEntry): KvTuple[] {
155177
const timings = entry.rawResource.timings;
156178

157-
// FIXME should only filter -1 values here, 0 is a valid timing.
179+
const optionalTiming = (timing?: number) => parseAndFormat(timing, parseNonNegative, formatMilliseconds);
180+
158181
return [
159-
["Total", `${entry.total} ms`],
160-
["Blocked", formatTime(timings["blocked"])],
161-
["DNS", formatTime(timings["dns"])],
162-
["Connect", formatTime(timings["connect"])],
163-
["SSL (TLS)", formatTime(timings["ssl"])],
164-
["Send", formatTime(timings["send"])],
165-
["Wait", formatTime(timings["wait"])],
166-
["Receive", formatTime(timings["receive"])],
182+
["Total", formatMilliseconds(entry.total)],
183+
["Blocked", optionalTiming(timings.blocked)],
184+
["DNS", optionalTiming(timings.dns)],
185+
["Connect", optionalTiming(timings.connect)],
186+
["SSL (TLS)", optionalTiming(timings.ssl)],
187+
["Send", formatMilliseconds(timings.send)],
188+
["Wait", formatMilliseconds(timings.wait)],
189+
["Receive", formatMilliseconds(timings.receive)],
167190
];
168191
}
169192

0 commit comments

Comments
 (0)