import type { Process, ThreadMetrics } from "@core/types"; import { deriveThreadColor } from "../shared/threadUtils"; interface ThreadMetricsTableProps { metrics: ThreadMetrics[]; processMap: Record; } const MiniBar = ({ value, max, color, }: { value: number; max: number; color: string; }) => { const pct = max > 0 ? (value / max) * 100 : 0; return (
{value}
); }; const ThreadMetricsTable = ({ metrics, processMap }: ThreadMetricsTableProps) => { if (metrics.length === 0) { return (
No completed threads yet.
); } const maxResponse = Math.max(...metrics.map((m) => m.responseTime), 1); const maxTurnaround = Math.max(...metrics.map((m) => m.turnaroundTime), 1); const maxWaiting = Math.max(...metrics.map((m) => m.waitingTime), 1); const maxCpu = Math.max(...metrics.map((m) => m.cpuTime), 1); const maxIo = Math.max(...metrics.map((m) => m.ioTime), 1); // Agrupa por processo para mostrar o índice de thread e cor correta const threadIndexByProcess: Record = {}; return (
{metrics.map((m, i) => { const proc = processMap[m.processId]; const procColor = proc?.color ?? "#94a3b8"; // Obtém o índice da thread dentro do processo para cor if (threadIndexByProcess[m.processId] === undefined) { threadIndexByProcess[m.processId] = 0; } const threadIdx = threadIndexByProcess[m.processId]!; threadIndexByProcess[m.processId] = threadIdx + 1; const threadColor = deriveThreadColor(procColor, threadIdx); return ( {/* Thread name */} {/* Process name */} ); })}
Thread Process Arrival Start Finish Response Turnaround Waiting CPU I/O
{m.threadName}
{proc?.name ?? m.processId}
{m.arrivalTime} {m.startTick} {m.finishTick}
); }; export default ThreadMetricsTable;