import { Component, createMemo, For, Show } from 'solid-js'; import { StatsData } from '@ns/core'; import { formatBytes, formatTime, formatPercent } from '@ns/ui-utils'; interface TimeChartProps { stats: StatsData; } const TimeChart: Component = props => { const timeData = createMemo(() => { const cpu = props.stats.time.cpu; const gc = props.stats.time.gc || 0; const gcNonInc = props.stats.time.gcNonIncremental || 0; const other = Math.max(0, cpu - gc - gcNonInc); return [ { label: 'Evaluation', value: other, colorClass: 'chart-1' }, { label: 'Incremental GC', value: gc, colorClass: 'chart-gc' }, { label: 'Full GC', value: gcNonInc, colorClass: 'chart-gc-full' }, ].filter(d => d.value > 0); }); const total = createMemo(() => timeData().reduce((sum, d) => sum + d.value, 0)); const barData = createMemo(() => { return timeData().map(item => ({ ...item, percent: total() > 0 ? (item.value / total()) * 100 : 0, })); }); return (
{item => (
{item.label}
{formatTime(item.value)}
)}
GC Cycles {props.stats.gc?.cycles || 0}
Heap Size {formatBytes(props.stats.gc?.heapSize || 0)}
GC Fraction {formatPercent(props.stats.time.gcFraction || 0)}
); }; export default TimeChart;