feat(experimental): add totals row and context-basis controls
This commit is contained in:
1 parent
559c4c689d
commit
f68f375bda
9 files changed
+423
-9
No files matched your search
@@ -24,8 +24,8 @@
|
||||
en: e001601f2f9779b1
|
||||
zh: 077d3703b8c82774
|
||||
/deepseek-ai-dsh-experimental-client-ui-perf/understand-the-implementation:
|
||||
en: 611ac4f20831030d
|
||||
zh: 11051434b5271feb
|
||||
en: e3bf55182a3cfb29
|
||||
zh: 04e432957e126f50
|
||||
/deepseek-ai-dsh-experimental-client-ui-perf/further-exploration:
|
||||
en: 285cfe1d7a99af34
|
||||
zh: fbcee76e0c2f20fb
|
||||
|
||||
@@ -57,6 +57,8 @@ Four Conversation Definitions fold the event window into nodes for one view targ
|
||||
| `src/client/PerfView.tsx` | Scrollport with scroll-to-top paging, table, time bars, step accordion, copy controls, and the prompt image pill with its preview and viewer |
|
||||
| `src/client/locales.ts` | Every visible string, in Chinese, English, and Japanese |
|
||||
|
||||
The footer switches control the totals row and the context basis. `Context basis: Latest` shows each turn's final prompt size; `Cumulative` sums that turn's step prompt sizes, so a row shows the tokens processed rather than the final window. The totals row applies the same basis to every loaded turn and sums the numeric columns (cache stays token-weighted, speed stays output over decode time).
|
||||
|
||||
The turn cache-hit cell is token-weighted across the steps that reported usage (summed cache reads ÷ summed prompt tokens), so one transient cold step is not hidden by a warmer neighbour; the tooltip shows the summed read/input/write breakdown. A step row keeps its own measured share.
|
||||
|
||||
Windows are bounded: when a step's `step/start` is outside the loaded window, its start-dependent columns show `—` with a `start unknown` marker rather than a guessed value. Scrolling to the top asks the Session for one older page; the view offsets the scroll position by the height it prepended, so the row being read stays in place.
|
||||
|
||||
@@ -57,6 +57,8 @@ kind: "package-reference"
|
||||
| `src/client/PerfView.tsx` | 表格、时间条、步骤手风琴、复制按钮,以及提问图片标签、预览与看图器 |
|
||||
| `src/client/locales.ts` | 全部可见文案,中、英、日三份 |
|
||||
|
||||
页脚的开关控制合计行与上下文口径。「上下文口径:最新」显示每轮最后一步的提示词大小;「累计」显示该轮各步提示词大小之和,即这一轮实际处理过的 token 量。合计行对已加载的轮次套用同一口径并汇总数值列(缓存仍按 token 加权,速度仍按输出 ÷ 生成时长)。
|
||||
|
||||
轮次的缓存命中率按报了 usage 的各步做 token 加权(缓存读之和 ÷ 提示词 token 之和),不会因为相邻步命中高就把某一次冷启动盖掉;tooltip 展示汇总后的读/输入/写明细。步骤行仍显示该步自己的实测比例。
|
||||
|
||||
会话窗口是有界的:某一步的 `step/start` 不在已加载窗口里时,与起点有关的列显示 `—` 并标「起止未知」,不估算数值。滚到顶部会向 Session 请求更早的一页;视图按新增内容的高度补偿滚动位置,正在读的行不会跳走。
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'react'
|
||||
import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
|
||||
import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
import { HoverCard, ImageLightbox } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import { HoverCard, ImageLightbox, SegmentedControl, Switch } from '@deepseek-ai/dsh-client-ui-primitives'
|
||||
import type { ConvViewProps } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type {
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
DASH, barShare, formatChars, formatClock, formatDateTime, formatDateTimeShort, formatMs, formatPercent,
|
||||
formatTokens, formatTokensShort, formatTps,
|
||||
} from './perf-format.ts'
|
||||
import { aggregateTotals, turnContext, type ContextMode, type PerfTotals } from './perf-aggregate.ts'
|
||||
import { isNumber } from './perf-usage.ts'
|
||||
import { CALL_LIMIT } from './perf-fold.ts'
|
||||
import type { PerfTranslate } from './locales.ts'
|
||||
@@ -137,6 +138,8 @@ interface ViewState {
|
||||
readonly mode: ViewMode
|
||||
readonly openTurns: Readonly<Record<number, boolean>>
|
||||
readonly stepViews: Readonly<Record<number, StepViewState>>
|
||||
readonly showTotals: boolean
|
||||
readonly contextMode: ContextMode
|
||||
}
|
||||
|
||||
/** Fields both row kinds expose to the numeric column helpers. */
|
||||
@@ -218,6 +221,7 @@ interface TurnRowsOptions {
|
||||
readonly open: boolean
|
||||
readonly state: StepViewState
|
||||
readonly turnScale: number
|
||||
readonly contextMode: ContextMode
|
||||
readonly onToggle: () => void
|
||||
readonly onToggleDetail: (stepNumber: number) => void
|
||||
readonly onControl: (patch: Partial<StepViewState>) => void
|
||||
@@ -346,7 +350,7 @@ function defaultTurnOpen(mode: ViewMode, turnNumber: number, latestTurn: number
|
||||
|
||||
/** Fresh table state: follow the newest turn's open default. */
|
||||
function createViewState(): ViewState {
|
||||
return { mode: 'newest', openTurns: {}, stepViews: {} }
|
||||
return { mode: 'newest', openTurns: {}, stepViews: {}, showTotals: false, contextMode: 'latest' }
|
||||
}
|
||||
|
||||
/** Read an array element whose index the surrounding bounds already prove. */
|
||||
@@ -915,6 +919,47 @@ function TimeCell({ value, scale, gap, className, trackClass, now, t }: TimeCell
|
||||
)
|
||||
}
|
||||
|
||||
/** Props of the totals row. */
|
||||
interface TotalsRowProps {
|
||||
readonly totals: PerfTotals
|
||||
readonly t: PerfTranslate
|
||||
readonly now: number
|
||||
}
|
||||
|
||||
/** Bottom row summing the turns loaded in the current window. */
|
||||
function TotalsRow({ totals, t, now }: TotalsRowProps): ReactElement {
|
||||
const cells = metricsCells(totals, t)
|
||||
const value: TimeState = {
|
||||
running: false,
|
||||
startTime: null,
|
||||
wall: totals.wall,
|
||||
ttft: totals.ttft,
|
||||
model: totals.model,
|
||||
tool: totals.tool,
|
||||
toolWall: totals.toolWall,
|
||||
}
|
||||
return (
|
||||
<tr className={css.totalsRow} title={t('totals.title')}>
|
||||
<td colSpan={2} className={css.totalsLabel}>
|
||||
<span className={css.totalsTitle}>{t('totals.label')}</span>
|
||||
<span className={css.totalsMeta}>{` · ${t('summary', { turns: totals.turnCount, steps: totals.stepCount })}`}</span>
|
||||
</td>
|
||||
<td className={css.turnMetric} />
|
||||
<ContextCell value={totals.context} className={css.turnMetric} />
|
||||
<MetricCells cells={cells} className={css.turnMetric} />
|
||||
<TimeCell
|
||||
value={value}
|
||||
scale={totals.wall ?? 0}
|
||||
gap={undefined}
|
||||
className={css.turnMetric}
|
||||
trackClass={css.barTurn}
|
||||
now={now}
|
||||
t={t}
|
||||
/>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
/** Display name of one prompt image: its recorded name, otherwise its position. */
|
||||
function imageName(attachment: ImageAttachmentRef, index: number, count: number, t: PerfTranslate): string {
|
||||
return attachment.name ?? t('imagePreview.alt', { index, count })
|
||||
@@ -1430,7 +1475,9 @@ function stepRows(options: StepRowsOptions): ReactNode[] {
|
||||
|
||||
/** All rows of one turn: the clickable header, then the expanded body. */
|
||||
function turnRows(options: TurnRowsOptions): ReactNode[] {
|
||||
const { turn, t, loadImage, now, open, state, turnScale, onToggle, onToggleDetail, onControl } = options
|
||||
const {
|
||||
turn, t, loadImage, now, open, state, turnScale, contextMode, onToggle, onToggleDetail, onControl,
|
||||
} = options
|
||||
const cells = metricsCells(turn, t)
|
||||
const rows: ReactNode[] = [
|
||||
<tr
|
||||
@@ -1466,7 +1513,7 @@ function turnRows(options: TurnRowsOptions): ReactNode[] {
|
||||
</td>
|
||||
<PromptCell turn={turn} t={t} className={css.promptCellTurn} loadImage={loadImage} />
|
||||
{turnDidCell(turn, t)}
|
||||
<ContextCell value={turn.context} className={css.turnMetric} />
|
||||
<ContextCell value={turnContext(turn, contextMode)} className={css.turnMetric} />
|
||||
<MetricCells cells={cells} className={css.turnMetric} />
|
||||
<TimeCell
|
||||
value={turn}
|
||||
@@ -1543,6 +1590,7 @@ export function PerfView(props: PerfViewProps): ReactElement {
|
||||
return () => { clearInterval(timer) }
|
||||
}, [hasRunning])
|
||||
// Turns compare only with the other turns in the window.
|
||||
const totals = view.showTotals && turns.length > 0 ? aggregateTotals(turns, view.contextMode) : null
|
||||
const scaleTurns = visibleTurns.size === 0 ? turns : turns.filter(turn => visibleTurns.has(turn.turn))
|
||||
const turnScale = scaleTurns.reduce((max, turn) => {
|
||||
const span = totalSpan(turn, now)
|
||||
@@ -1716,17 +1764,43 @@ export function PerfView(props: PerfViewProps): ReactElement {
|
||||
open: isTurnOpen(turn.turn),
|
||||
state: view.stepViews[turn.turn] ?? EMPTY_STEP_VIEW,
|
||||
turnScale,
|
||||
contextMode: view.contextMode,
|
||||
onToggle: () => { toggleTurn(turn.turn) },
|
||||
onToggleDetail: (stepNumber) => { toggleStepDetail(turn.turn, stepNumber) },
|
||||
onControl: (patch) => { patchStepView(turn.turn, patch) },
|
||||
}))}
|
||||
</tbody>
|
||||
{totals === null ? null : (
|
||||
<tfoot>
|
||||
<TotalsRow totals={totals} t={t} now={now} />
|
||||
</tfoot>
|
||||
)}
|
||||
</table>
|
||||
)}
|
||||
<div className={css.toolbar}>
|
||||
<span className={css.summary}>
|
||||
{t('summary', { turns: turns.length, steps: snapshot.stepCount })}
|
||||
</span>
|
||||
<div className={css.controls}>
|
||||
<span className={css.controlLabel}>{t('table.showTotals')}</span>
|
||||
<Switch
|
||||
checked={view.showTotals}
|
||||
onChange={(next) => { setView(previous => ({ ...previous, showTotals: next })) }}
|
||||
label={t('table.showTotals')}
|
||||
/>
|
||||
<span className={css.controlLabel}>{t('contextMode.label')}</span>
|
||||
<SegmentedControl
|
||||
id="perf-context-mode"
|
||||
value={view.contextMode}
|
||||
options={[
|
||||
{ value: 'latest', label: t('contextMode.latest'), title: t('contextMode.latest.title') },
|
||||
{ value: 'cumulative', label: t('contextMode.cumulative'), title: t('contextMode.cumulative.title') },
|
||||
]}
|
||||
onChange={(next) => { setView(previous => ({ ...previous, contextMode: next })) }}
|
||||
label={t('contextMode.label')}
|
||||
className={css.contextMode}
|
||||
/>
|
||||
</div>
|
||||
<TableButton
|
||||
caption={allOpen ? t('collapse.all') : t('expand.all')}
|
||||
enabled={turns.length > 0}
|
||||
|
||||
@@ -58,6 +58,15 @@ export const zh = {
|
||||
'loadOlder.done': '已经是最早的记录',
|
||||
'loadOlder.failed': '加载失败,重试',
|
||||
'summary': '{turns} 轮 · {steps} 步',
|
||||
'table.showTotals': '显示合计行',
|
||||
'contextMode.label': '上下文口径',
|
||||
'contextMode.latest': '最新',
|
||||
'contextMode.latest.title': '每轮最后一步的提示词大小(最终上下文)',
|
||||
'contextMode.cumulative': '累计',
|
||||
'contextMode.cumulative.title': '该轮各步提示词大小之和(累计处理量)',
|
||||
'totals.label': '合计',
|
||||
'totals.title': '当前已加载轮次的合计',
|
||||
|
||||
'expand.all': '展开全部',
|
||||
'collapse.all': '折叠全部',
|
||||
'turn.expand': '展开',
|
||||
@@ -192,6 +201,15 @@ export const en: Record<PerfKey, string> = {
|
||||
'loadOlder.done': 'Beginning of history reached',
|
||||
'loadOlder.failed': 'Load failed, retry',
|
||||
'summary': '{turns} turns · {steps} steps',
|
||||
'table.showTotals': 'Show total row',
|
||||
'contextMode.label': 'Context basis',
|
||||
'contextMode.latest': 'Latest',
|
||||
'contextMode.latest.title': "Prompt size of the turn's last measured step (final context)",
|
||||
'contextMode.cumulative': 'Cumulative',
|
||||
'contextMode.cumulative.title': "Sum of prompt sizes across the turn's steps (cumulative processing)",
|
||||
'totals.label': 'Total',
|
||||
'totals.title': 'Totals for the turns loaded in this window',
|
||||
|
||||
'expand.all': 'Expand all',
|
||||
'collapse.all': 'Collapse all',
|
||||
'turn.expand': 'Show',
|
||||
@@ -313,6 +331,15 @@ export const ja: Record<PerfKey, string> = {
|
||||
'loadOlder.done': '履歴の先頭に到達しました',
|
||||
'loadOlder.failed': '読み込みに失敗しました。再試行',
|
||||
'summary': '{turns} ターン · {steps} ステップ',
|
||||
'table.showTotals': '合計行を表示',
|
||||
'contextMode.label': 'コンテキスト基準',
|
||||
'contextMode.latest': '最新',
|
||||
'contextMode.latest.title': '各ターンの最後に測定したステップのプロンプトサイズ(最終コンテキスト)',
|
||||
'contextMode.cumulative': '累計',
|
||||
'contextMode.cumulative.title': 'ターン内の各ステップのプロンプトサイズの合計(累計処理量)',
|
||||
'totals.label': '合計',
|
||||
'totals.title': '読み込み済みターンの合計',
|
||||
|
||||
'expand.all': 'すべて展開',
|
||||
'collapse.all': 'すべて折りたたむ',
|
||||
'turn.expand': '展開',
|
||||
|
||||
@@ -38,7 +38,7 @@ function triggerRank(source: string): number {
|
||||
}
|
||||
|
||||
/** Context measured last in the turn: steps without usage keep the previous value. */
|
||||
function turnContext(steps: readonly PerfStepMetrics[]): number | null {
|
||||
function lastContext(steps: readonly PerfStepMetrics[]): number | null {
|
||||
let context: number | null = null
|
||||
for (const step of steps) if (isNumber(step.context)) context = step.context
|
||||
return context
|
||||
@@ -175,7 +175,7 @@ export function aggregateTurn(turn: number, steps: readonly PerfStepMetrics[]):
|
||||
turn,
|
||||
steps,
|
||||
startTime: first !== undefined && isNumber(first.startTime) ? first.startTime : null,
|
||||
context: turnContext(steps),
|
||||
context: lastContext(steps),
|
||||
// Only "nothing measured" counts as unrecorded; partial coverage is a lower bound.
|
||||
ttft: ttftUnknown === all ? null : ttftSum,
|
||||
ttftPending: ttftUnknown === all ? 0 : ttftUnknown,
|
||||
@@ -317,3 +317,144 @@ export function buildTurns(nodes: Iterable<PerfViewNode>): PerfTurnMetrics[] {
|
||||
})
|
||||
return turns
|
||||
}
|
||||
|
||||
/** How a turn or window aggregates prompt sizes: final prompt or cumulative processing. */
|
||||
export type ContextMode = 'latest' | 'cumulative'
|
||||
|
||||
/** Totals over the turns loaded in the current window. */
|
||||
export interface PerfTotals {
|
||||
readonly turnCount: number
|
||||
readonly stepCount: number
|
||||
readonly context: number | null
|
||||
readonly output: number | null
|
||||
readonly cacheHit: number | null
|
||||
readonly cacheRead: number | null
|
||||
readonly cacheWrite: number | null
|
||||
readonly cacheContext: number | null
|
||||
readonly ttft: number | null
|
||||
readonly ttftPending: number
|
||||
readonly model: number | null
|
||||
readonly modelPending: number
|
||||
readonly tps: number | null
|
||||
readonly tool: number | null
|
||||
readonly toolPending: number
|
||||
readonly toolWall: number | null
|
||||
readonly wall: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Context of one turn under the selected basis.
|
||||
* @param turn - aggregated turn.
|
||||
* @param mode - latest final prompt size, or the sum of its step prompt sizes.
|
||||
* @returns the context tokens, or null when no step measured one.
|
||||
*/
|
||||
export function turnContext(turn: PerfTurnMetrics, mode: ContextMode): number | null {
|
||||
if (mode === 'latest') return turn.context
|
||||
let sum = 0
|
||||
let measured = false
|
||||
for (const step of turn.steps) {
|
||||
if (!isNumber(step.context)) continue
|
||||
sum += step.context
|
||||
measured = true
|
||||
}
|
||||
return measured ? sum : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregate the loaded turns into one totals row.
|
||||
* @param turns - aggregated turns in display order.
|
||||
* @param mode - context basis shared with the turn rows.
|
||||
* @returns summed metrics and the context value for the selected basis.
|
||||
*/
|
||||
export function aggregateTotals(turns: readonly PerfTurnMetrics[], mode: ContextMode): PerfTotals {
|
||||
let context: number | null = null
|
||||
let stepCount = 0
|
||||
let outputSum = 0
|
||||
let outputMeasured = false
|
||||
let read = 0
|
||||
let write = 0
|
||||
let contextSum = 0
|
||||
let cacheMeasured = false
|
||||
let ttftSum = 0
|
||||
let ttftMeasured = false
|
||||
let ttftPending = 0
|
||||
let modelSum = 0
|
||||
let modelMeasured = false
|
||||
let modelPending = 0
|
||||
let decodeSum = 0
|
||||
let toolSum = 0
|
||||
let toolMeasured = false
|
||||
let toolPending = 0
|
||||
let toolWallSum = 0
|
||||
let toolWallMeasured = false
|
||||
let wallSum = 0
|
||||
let wallMeasured = false
|
||||
for (const turn of turns) {
|
||||
stepCount += turn.steps.length
|
||||
if (isNumber(turn.context)) context = turn.context
|
||||
if (isNumber(turn.output)) {
|
||||
outputSum += turn.output
|
||||
outputMeasured = true
|
||||
}
|
||||
if (isNumber(turn.cacheRead) && isNumber(turn.cacheContext)) {
|
||||
read += turn.cacheRead
|
||||
write += turn.cacheWrite ?? 0
|
||||
contextSum += turn.cacheContext
|
||||
cacheMeasured = true
|
||||
}
|
||||
if (isNumber(turn.ttft)) {
|
||||
ttftSum += turn.ttft
|
||||
ttftMeasured = true
|
||||
}
|
||||
ttftPending += turn.ttftPending
|
||||
if (isNumber(turn.model)) {
|
||||
modelSum += turn.model
|
||||
modelMeasured = true
|
||||
}
|
||||
modelPending += turn.modelPending
|
||||
if (isNumber(turn.decode)) decodeSum += turn.decode
|
||||
if (isNumber(turn.tool)) {
|
||||
toolSum += turn.tool
|
||||
toolMeasured = true
|
||||
}
|
||||
toolPending += turn.toolPending
|
||||
if (isNumber(turn.toolWall)) {
|
||||
toolWallSum += turn.toolWall
|
||||
toolWallMeasured = true
|
||||
}
|
||||
if (isNumber(turn.wall)) {
|
||||
wallSum += turn.wall
|
||||
wallMeasured = true
|
||||
}
|
||||
}
|
||||
let cumulative = 0
|
||||
let cumulativeMeasured = false
|
||||
if (mode === 'cumulative') {
|
||||
for (const turn of turns) {
|
||||
for (const step of turn.steps) {
|
||||
if (!isNumber(step.context)) continue
|
||||
cumulative += step.context
|
||||
cumulativeMeasured = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
turnCount: turns.length,
|
||||
stepCount,
|
||||
context: mode === 'cumulative' ? (cumulativeMeasured ? cumulative : null) : context,
|
||||
output: outputMeasured ? outputSum : null,
|
||||
cacheHit: cacheMeasured && contextSum > 0 ? Math.min(1, read / contextSum) : null,
|
||||
cacheRead: cacheMeasured ? read : null,
|
||||
cacheWrite: cacheMeasured ? write : null,
|
||||
cacheContext: cacheMeasured ? contextSum : null,
|
||||
ttft: ttftMeasured ? ttftSum : null,
|
||||
ttftPending: ttftMeasured ? ttftPending : 0,
|
||||
model: modelMeasured ? modelSum : null,
|
||||
modelPending,
|
||||
tps: outputMeasured && decodeSum > 0 && outputSum > 0 ? outputSum / (decodeSum / 1000) : null,
|
||||
tool: toolMeasured ? toolSum : null,
|
||||
toolPending,
|
||||
toolWall: toolWallMeasured ? toolWallSum : null,
|
||||
wall: wallMeasured ? wallSum : null,
|
||||
}
|
||||
}
|
||||
@@ -808,6 +808,39 @@
|
||||
color: var(--dsw-alias-label-secondary);
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
row-gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.controlLabel {
|
||||
color: var(--dsw-alias-label-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.contextMode {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.totalsRow td {
|
||||
border-top: 0.5px solid var(--dsw-alias-border-l2);
|
||||
background: var(--dsw-alias-bg-layer-1);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.totalsLabel {
|
||||
color: var(--dsw-alias-label-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.totalsMeta {
|
||||
color: var(--dsw-alias-label-secondary);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.button {
|
||||
padding: 4px 10px;
|
||||
border: 0.5px solid var(--dsw-alias-border-l1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { AttachmentId, type ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
|
||||
import { aggregateTurn, buildTurns } from '../src/client/perf-aggregate.ts'
|
||||
import { aggregateTotals, aggregateTurn, buildTurns, turnContext } from '../src/client/perf-aggregate.ts'
|
||||
import type { PerfCall, PerfStepMetrics, PerfViewNode } from '../src/client/perf-contract.ts'
|
||||
import { CALL_LIMIT } from '../src/client/perf-fold.ts'
|
||||
|
||||
@@ -235,6 +235,93 @@ describe('turn aggregation', () => {
|
||||
expect(empty.cacheHit).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps unmeasured totals blank and skips unmeasured steps', () => {
|
||||
const bare = aggregateTurn(3, [metricsOf({ step: 1 })])
|
||||
expect(turnContext(bare, 'cumulative')).toBeNull()
|
||||
expect(turnContext(bare, 'latest')).toBeNull()
|
||||
const totals = aggregateTotals([bare], 'cumulative')
|
||||
expect(totals.context).toBeNull()
|
||||
expect(totals.output).toBeNull()
|
||||
expect(totals.cacheHit).toBeNull()
|
||||
expect(totals.ttft).toBeNull()
|
||||
expect(totals.model).toBeNull()
|
||||
expect(totals.tps).toBeNull()
|
||||
expect(totals.tool).toBeNull()
|
||||
expect(totals.toolWall).toBeNull()
|
||||
expect(totals.wall).toBeNull()
|
||||
|
||||
const partial = aggregateTurn(4, [metricsOf({ step: 1, context: 100, cacheRead: 40 })])
|
||||
expect(turnContext(partial, 'cumulative')).toBe(100)
|
||||
const mixed = aggregateTotals([partial], 'cumulative')
|
||||
expect(mixed.cacheWrite).toBe(0)
|
||||
expect(mixed.cacheHit).toBe(0.4)
|
||||
const forged = { ...bare, cacheRead: 10, cacheContext: 100, cacheWrite: null }
|
||||
expect(aggregateTotals([forged], 'latest').cacheWrite).toBe(0)
|
||||
})
|
||||
|
||||
it('aggregates loaded turns into totals and switches the context basis', () => {
|
||||
const first = aggregateTurn(1, [
|
||||
metricsOf({
|
||||
step: 1, startTime: 0, endTime: 300, context: 100, output: 10, decode: 1_000,
|
||||
cacheRead: 80, cacheWrite: 5, ttft: 100, model: 200, tool: 50, toolWall: 40, wall: 300,
|
||||
}),
|
||||
metricsOf({
|
||||
step: 2, startTime: 300, endTime: 700, context: 200, output: 20, decode: 500,
|
||||
cacheRead: 150, cacheWrite: 5, ttft: 50, model: 100, wall: 400,
|
||||
}),
|
||||
])
|
||||
const second = aggregateTurn(2, [
|
||||
metricsOf({
|
||||
step: 1, startTime: 700, endTime: 1_200, context: 300, output: 30, decode: 500,
|
||||
cacheRead: 250, cacheWrite: 10, tool: 75, toolWall: 60, wall: 500,
|
||||
}),
|
||||
])
|
||||
const latest = aggregateTotals([first, second], 'latest')
|
||||
expect(latest.turnCount).toBe(2)
|
||||
expect(latest.stepCount).toBe(3)
|
||||
expect(latest.context).toBe(300)
|
||||
expect(turnContext(first, 'latest')).toBe(200)
|
||||
expect(turnContext(first, 'cumulative')).toBe(300)
|
||||
expect(latest.output).toBe(60)
|
||||
expect(latest.cacheRead).toBe(480)
|
||||
expect(latest.cacheWrite).toBe(20)
|
||||
expect(latest.cacheContext).toBe(600)
|
||||
expect(latest.cacheHit).toBe(0.8)
|
||||
expect(latest.ttft).toBe(150)
|
||||
expect(latest.ttftPending).toBe(0)
|
||||
expect(latest.model).toBe(300)
|
||||
expect(latest.modelPending).toBe(1)
|
||||
expect(latest.tps).toBeCloseTo(60 / 2)
|
||||
expect(latest.tool).toBe(125)
|
||||
expect(latest.toolPending).toBe(0)
|
||||
expect(latest.toolWall).toBe(100)
|
||||
expect(latest.wall).toBe(1_200)
|
||||
|
||||
const cumulative = aggregateTotals([first, second], 'cumulative')
|
||||
expect(cumulative.context).toBe(600)
|
||||
|
||||
const empty = aggregateTotals([], 'cumulative')
|
||||
expect(empty).toEqual({
|
||||
turnCount: 0,
|
||||
stepCount: 0,
|
||||
context: null,
|
||||
output: null,
|
||||
cacheHit: null,
|
||||
cacheRead: null,
|
||||
cacheWrite: null,
|
||||
cacheContext: null,
|
||||
ttft: null,
|
||||
ttftPending: 0,
|
||||
model: null,
|
||||
modelPending: 0,
|
||||
tps: null,
|
||||
tool: null,
|
||||
toolPending: 0,
|
||||
toolWall: null,
|
||||
wall: null,
|
||||
})
|
||||
})
|
||||
|
||||
it('sums the sequential step tool spans', () => {
|
||||
const turn = aggregateTurn(5, [
|
||||
metricsOf({ step: 1, toolWall: 300, tool: 400 }),
|
||||
|
||||
@@ -755,6 +755,54 @@ describe('turn rows', () => {
|
||||
}))
|
||||
})
|
||||
|
||||
it('shows a totals row and switches the context basis', () => {
|
||||
mount({
|
||||
turns: [
|
||||
turn({
|
||||
turn: 1,
|
||||
context: 200,
|
||||
output: 30,
|
||||
steps: [step({ step: 1, context: 100 }), step({ step: 2, context: 200, wall: 500 })],
|
||||
}),
|
||||
turn({
|
||||
turn: 2,
|
||||
context: 300,
|
||||
output: 40,
|
||||
steps: [step({ step: 1, context: 200, wall: 600 }), step({ step: 2, context: 100 })],
|
||||
}),
|
||||
],
|
||||
stepCount: 4,
|
||||
})
|
||||
expect(screen.queryByText(say('totals.label'))).toBeNull()
|
||||
const totalsSwitch = screen.getByRole('switch', { name: say('table.showTotals') })
|
||||
expect(totalsSwitch.getAttribute('aria-checked')).toBe('false')
|
||||
fireEvent.click(totalsSwitch)
|
||||
const totalLabel = screen.getByText(say('totals.label'))
|
||||
expect(totalLabel.parentElement?.textContent).toContain(say('summary', { turns: 2, steps: 4 }))
|
||||
const totalRow = totalLabel.closest('tr') as HTMLTableRowElement
|
||||
expect(cellsOf(totalRow)[2]?.textContent).toBe(formatTokensShort(300))
|
||||
|
||||
const first = rowWithPrefix(say('turn.label', { turn: 1 }))
|
||||
expect(cellsOf(first)[3]?.textContent).toBe(formatTokensShort(200))
|
||||
fireEvent.click(screen.getByRole('tab', { name: say('contextMode.cumulative') }))
|
||||
expect(cellsOf(rowWithPrefix(say('turn.label', { turn: 1 })))[3]?.textContent)
|
||||
.toBe(formatTokensShort(300))
|
||||
expect(cellsOf(totalRow)[2]?.textContent).toBe(formatTokensShort(600))
|
||||
expect(screen.getByRole('tab', { name: say('contextMode.cumulative') })
|
||||
.getAttribute('aria-selected')).toBe('true')
|
||||
|
||||
fireEvent.click(totalsSwitch)
|
||||
expect(screen.queryByText(say('totals.label'))).toBeNull()
|
||||
})
|
||||
|
||||
it('leaves the totals time blank when no turn wall was measured', () => {
|
||||
mount({ turns: [turn({ turn: 1, wall: null, context: 500 })], stepCount: 0 })
|
||||
fireEvent.click(screen.getByRole('switch', { name: say('table.showTotals') }))
|
||||
const label = screen.getByText(say('totals.label'))
|
||||
const row = label.closest('tr') as HTMLTableRowElement
|
||||
expect(cellsOf(row).at(-1)?.textContent).toBe('—')
|
||||
})
|
||||
|
||||
it('scales turn bars against the turns visible on screen', () => {
|
||||
interface FakeEntry { readonly target: Element; readonly isIntersecting: boolean }
|
||||
class FakeObserver {
|
||||
|
||||
Reference in new issue
Block a user