| 2075 | } |
| 2076 | |
| 2077 | function printTimingSummary() { |
| 2078 | if (stepTimings.length === 0) { |
| 2079 | return; |
| 2080 | } |
| 2081 | const rows = stepTimings.map((timing) => ({ |
| 2082 | label: timing.label, |
| 2083 | phase: timing.phase, |
| 2084 | activeMs: Math.max(0, timing.elapsedMs - timing.sleepMs), |
| 2085 | elapsedMs: timing.elapsedMs, |
| 2086 | sleepMs: timing.sleepMs, |
| 2087 | describeUiMs: timing.describeUiMs, |
| 2088 | commandMs: timing.commandMs, |
| 2089 | ok: timing.ok, |
| 2090 | })); |
| 2091 | const totalActiveMs = rows.reduce((sum, row) => sum + row.activeMs, 0); |
| 2092 | const totalElapsedMs = rows.reduce((sum, row) => sum + row.elapsedMs, 0); |
| 2093 | const totalSleepMs = rows.reduce((sum, row) => sum + row.sleepMs, 0); |
| 2094 | const totalDescribeUiMs = rows.reduce( |
| 2095 | (sum, row) => sum + row.describeUiMs, |
| 2096 | 0, |
| 2097 | ); |
| 2098 | const phaseTotals = new Map(); |
| 2099 | for (const row of rows) { |
| 2100 | const totals = phaseTotals.get(row.phase) ?? { |
| 2101 | activeMs: 0, |
| 2102 | elapsedMs: 0, |
| 2103 | sleepMs: 0, |
| 2104 | describeUiMs: 0, |
| 2105 | }; |
| 2106 | totals.activeMs += row.activeMs; |
| 2107 | totals.elapsedMs += row.elapsedMs; |
| 2108 | totals.sleepMs += row.sleepMs; |
| 2109 | totals.describeUiMs += row.describeUiMs; |
| 2110 | phaseTotals.set(row.phase, totals); |
| 2111 | } |
| 2112 | |
| 2113 | console.log( |
| 2114 | "\nIntegration timing summary (artificial delays excluded from active):", |
| 2115 | ); |
| 2116 | console.log("active\twall\tdelay\tdescribe\tphase\tstatus\tstep"); |
| 2117 | for (const row of rows.toSorted( |
| 2118 | (left, right) => right.activeMs - left.activeMs, |
| 2119 | )) { |
| 2120 | console.log( |
| 2121 | `${formatDuration(row.activeMs)}\t${formatDuration(row.elapsedMs)}\t${formatDuration(row.sleepMs)}\t${formatDuration(row.describeUiMs)}\t${row.phase}\t${row.ok ? "ok" : "fail"}\t${row.label}`, |
| 2122 | ); |
| 2123 | } |
| 2124 | console.log("\nPhase totals:"); |
| 2125 | for (const [phase, totals] of [...phaseTotals.entries()].sort()) { |
| 2126 | console.log( |
| 2127 | `${phase}: active ${formatDuration(totals.activeMs)} / wall ${formatDuration(totals.elapsedMs)} / artificial delay ${formatDuration(totals.sleepMs)} / describe ${formatDuration(totals.describeUiMs)}`, |
| 2128 | ); |
| 2129 | } |
| 2130 | const testTotals = phaseTotals.get(phaseTest) ?? { |
| 2131 | activeMs: 0, |
| 2132 | elapsedMs: 0, |
| 2133 | sleepMs: 0, |
| 2134 | describeUiMs: 0, |