|
| 1 | +import { |
| 2 | + PlatformStatistics_Gc, |
| 3 | + PlatformStatistics_Memory, |
| 4 | + PlatformStatistics_Memory_MemoryUsage, |
| 5 | +} from '../../../proto/spark_pb'; |
| 6 | +import { formatBytes } from '../../util/format'; |
| 7 | +import { WidgetFormat } from '../widgets/format'; |
| 8 | + |
| 9 | +export interface MemoryStatisticsProps { |
| 10 | + memory: PlatformStatistics_Memory; |
| 11 | + gc: Record<string, PlatformStatistics_Gc>; |
| 12 | +} |
| 13 | + |
| 14 | +export default function MemoryStatistics({ |
| 15 | + memory, |
| 16 | + gc, |
| 17 | +}: MemoryStatisticsProps) { |
| 18 | + return ( |
| 19 | + <> |
| 20 | + <h2>Memory Areas</h2> |
| 21 | + <div className="memory"> |
| 22 | + <MemoryPool name="Heap" usage={memory.heap!} /> |
| 23 | + <MemoryPool name="Non Heap" usage={memory.nonHeap!} /> |
| 24 | + {memory.pools |
| 25 | + .filter(pool => pool.usage) |
| 26 | + .map(pool => { |
| 27 | + return ( |
| 28 | + <MemoryPool |
| 29 | + key={pool.name} |
| 30 | + name={'Heap - ' + pool.name} |
| 31 | + usage={pool.usage!} |
| 32 | + collectionUsage={pool.collectionUsage} |
| 33 | + /> |
| 34 | + ); |
| 35 | + })} |
| 36 | + </div> |
| 37 | + </> |
| 38 | + ); |
| 39 | +} |
| 40 | + |
| 41 | +interface MemoryPoolProps { |
| 42 | + name: string; |
| 43 | + usage: PlatformStatistics_Memory_MemoryUsage; |
| 44 | + collectionUsage?: PlatformStatistics_Memory_MemoryUsage; |
| 45 | +} |
| 46 | + |
| 47 | +const MemoryPool = ({ name, usage, collectionUsage }: MemoryPoolProps) => { |
| 48 | + return ( |
| 49 | + <div className="memory-pool"> |
| 50 | + <div className="header">{name}</div> |
| 51 | + <MemoryUsageBar {...usage} /> |
| 52 | + {collectionUsage && ( |
| 53 | + <div> |
| 54 | + <br /> |
| 55 | + <div className="header">{name} (at last GC)</div> |
| 56 | + <MemoryUsageBar {...collectionUsage} /> |
| 57 | + </div> |
| 58 | + )} |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +const MemoryUsageBar = ({ |
| 64 | + used, |
| 65 | + committed, |
| 66 | + max, |
| 67 | +}: PlatformStatistics_Memory_MemoryUsage) => { |
| 68 | + let percent; |
| 69 | + if (max && max > 0) { |
| 70 | + percent = used / max; |
| 71 | + } else { |
| 72 | + percent = used / committed; |
| 73 | + } |
| 74 | + |
| 75 | + let color; |
| 76 | + if (percent > 0.9) { |
| 77 | + color = WidgetFormat.colors.red; |
| 78 | + } else if (percent > 0.65) { |
| 79 | + color = WidgetFormat.colors.yellow; |
| 80 | + } else { |
| 81 | + color = WidgetFormat.colors.green; |
| 82 | + } |
| 83 | + |
| 84 | + return ( |
| 85 | + <> |
| 86 | + <div className="usage-bar"> |
| 87 | + <div |
| 88 | + style={{ |
| 89 | + width: `${Math.ceil(percent * 100)}%`, |
| 90 | + backgroundColor: color, |
| 91 | + }} |
| 92 | + /> |
| 93 | + </div> |
| 94 | + <ul> |
| 95 | + <li> |
| 96 | + Used: <span>{formatBytes(used)}</span> |
| 97 | + </li> |
| 98 | + <li> |
| 99 | + Committed: <span>{formatBytes(committed)}</span> |
| 100 | + </li> |
| 101 | + {max !== -1 && max !== committed && ( |
| 102 | + <li> |
| 103 | + Max: <span>{formatBytes(max)}</span> |
| 104 | + </li> |
| 105 | + )} |
| 106 | + </ul> |
| 107 | + </> |
| 108 | + ); |
| 109 | +}; |
0 commit comments