Skip to content

Commit c5c47ae

Browse files
committed
Add memory section to metadata
1 parent 3ab8f26 commit c5c47ae

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

src/style/metadata.module.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,46 @@
4343
margin: 0 5px;
4444
}
4545

46+
.memory {
47+
display: flex;
48+
flex-wrap: wrap;
49+
gap: 10px;
50+
51+
.memory-pool {
52+
background-color: #293134;
53+
padding: 5px;
54+
border-radius: 5px;
55+
}
56+
57+
.header {
58+
text-align: center;
59+
margin-bottom: 10px;
60+
color: #fff;
61+
}
62+
63+
.usage-bar {
64+
height: 20px;
65+
width: 500px;
66+
border: 3px solid #252b2d;
67+
display: flex;
68+
background-color: #252b2d;
69+
70+
> div {
71+
background-color: #b5b5b5;
72+
}
73+
}
74+
75+
ul {
76+
li {
77+
list-style: none;
78+
79+
span {
80+
color: #fff;
81+
}
82+
}
83+
}
84+
}
85+
4686
.configurations {
4787
ul {
4888
padding-left: 20px;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
};

src/viewer/common/components/metadata/MetadataDetail.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import ExtraPlatformMetadata from './ExtraPlatformMetadata';
1010
import GameRules from './GameRules';
1111
import JvmStartupArgs from './JvmStartupArgs';
12+
import MemoryStatistics from './MemoryStatistics';
1213
import PlatformStatistics from './PlatformStatistics';
1314
import PluginsModsList from './PluginsModsList';
1415
import ServerConfigurations from './ServerConfigurations';
@@ -64,6 +65,9 @@ export default function MetadataDetail({ metadata }: MetadataDetailProps) {
6465
const [view, setView] = useState('Platform');
6566
const views = {
6667
'Platform': () => true,
68+
'Memory': () =>
69+
platformStatistics?.memory &&
70+
platformStatistics.memory.pools.length,
6771
'JVM Flags': () => systemStatistics?.java?.vmArgs,
6872
'Configurations': () => parsedConfigurations,
6973
'World': () =>
@@ -109,6 +113,11 @@ export default function MetadataDetail({ metadata }: MetadataDetailProps) {
109113
numberOfIncludedTicks={numberOfIncludedTicks}
110114
engine={samplerEngine}
111115
/>
116+
) : view === 'Memory' ? (
117+
<MemoryStatistics
118+
memory={platformStatistics?.memory!}
119+
gc={platformStatistics?.gc!}
120+
/>
112121
) : view === 'JVM Flags' ? (
113122
<JvmStartupArgs systemStatistics={systemStatistics!} />
114123
) : view === 'Configurations' ? (

0 commit comments

Comments
 (0)