From 0920d3ff4526c66b118dc4bf350bcb2fdaad397b Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Sun, 22 Feb 2026 23:50:37 +0100 Subject: [PATCH] fix: implement human-readable memory formatting and ensure hierarchical tree respects profiler filtering --- src/App.tsx | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bb9e188..0293d43 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -72,6 +72,19 @@ function cn(...inputs: (string | undefined | null | false)[]) { return twMerge(clsx(inputs)); } +function formatBytes(bytes: number, decimals = 1) { + if (!bytes || bytes === 0) return '0 B'; + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; +} + +function formatMB(mb: number, decimals = 1) { + return formatBytes(mb * 1024 * 1024, decimals); +} + function App() { const [view, setView] = useState<'dashboard' | 'report'>('dashboard'); const [stats, setStats] = useState(null); @@ -420,11 +433,11 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () =>
{proc.peak_cpu.toFixed(1)}%
- {proc.inclusive_avg_memory_mb.toFixed(0)}MB - {proc.children.length > 0 && ({proc.avg_memory_mb.toFixed(0)}MB self)} + {formatMB(proc.inclusive_avg_memory_mb)} + {proc.children.length > 0 && ({formatMB(proc.avg_memory_mb)} self)}
-
{proc.peak_memory_mb.toFixed(0)}MB
+
{formatMB(proc.peak_memory_mb, 0)}
{proc.warnings.length > 0 ? proc.warnings.map((w, idx) => ( @@ -436,7 +449,10 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () => )}
- {hasChildren && isExpanded && renderTreeRows(proc.children, depth + 1)} + {hasChildren && isExpanded && renderTreeRows( + proc.children.filter(c => !hideProfiler || !c.is_syspulse), + depth + 1 + )} ); }); @@ -521,6 +537,11 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () => { + if (name === 'MEM GB') return [formatBytes(value * 1024 * 1024 * 1024), 'RAM']; + if (name === 'CPU %') return [`${value.toFixed(1)}%`, 'CPU']; + return [value, name]; + }} /> @@ -590,7 +611,7 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () =>
Total Avg RAM
-
{selectedProcess.inclusive_avg_memory_mb.toFixed(0)}MB
+
{formatMB(selectedProcess.inclusive_avg_memory_mb)}

Combined RSS memory of the subtree.

@@ -615,6 +636,11 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () => { + if (name === 'Self Mem (MB)') return [formatMB(value), 'RAM (Self)']; + if (name === 'Self CPU %') return [`${value.toFixed(1)}%`, 'CPU (Self)']; + return [value, name]; + }} /> @@ -632,7 +658,7 @@ function ReportView({ report, onBack }: { report: ProfilingReport, onBack: () =>
Peak Self RAM - {selectedProcess.peak_memory_mb.toFixed(0)}MB + {formatMB(selectedProcess.peak_memory_mb)}
Child Process Count