| | |
| | |
| | |
| | |
| | |
| |
|
| | export const formatMemoryUsage = (bytes: number): string => { |
| | const gb = bytes / (1024 * 1024 * 1024); |
| | if (bytes < 1024 * 1024) { |
| | return `${(bytes / 1024).toFixed(1)} KB`; |
| | } |
| | if (bytes < 1024 * 1024 * 1024) { |
| | return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; |
| | } |
| | return `${gb.toFixed(2)} GB`; |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export const formatDuration = (milliseconds: number): string => { |
| | if (milliseconds <= 0) { |
| | return '0s'; |
| | } |
| |
|
| | if (milliseconds < 1000) { |
| | return `${Math.round(milliseconds)}ms`; |
| | } |
| |
|
| | const totalSeconds = milliseconds / 1000; |
| |
|
| | if (totalSeconds < 60) { |
| | return `${totalSeconds.toFixed(1)}s`; |
| | } |
| |
|
| | const hours = Math.floor(totalSeconds / 3600); |
| | const minutes = Math.floor((totalSeconds % 3600) / 60); |
| | const seconds = Math.floor(totalSeconds % 60); |
| |
|
| | const parts: string[] = []; |
| |
|
| | if (hours > 0) { |
| | parts.push(`${hours}h`); |
| | } |
| | if (minutes > 0) { |
| | parts.push(`${minutes}m`); |
| | } |
| | if (seconds > 0) { |
| | parts.push(`${seconds}s`); |
| | } |
| |
|
| | |
| | if (parts.length === 0) { |
| | if (hours > 0) return `${hours}h`; |
| | if (minutes > 0) return `${minutes}m`; |
| | return `${seconds}s`; |
| | } |
| |
|
| | return parts.join(' '); |
| | }; |
| |
|