Skip to content

Commit

Permalink
Include memory stats in ws updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Sep 8, 2024
1 parent 8986c71 commit f06de57
Showing 1 changed file with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,32 @@ public SystemStatistics getSystemStatistics() {
return builder.build();
}

public PlatformStatistics getPlatformStatistics(Map<String, GarbageCollectorStatistics> startingGcStatistics, boolean detailed) {
public PlatformStatistics getPlatformStatistics(Map<String, GarbageCollectorStatistics> startingGcStatistics, boolean includeWorldStatistics) {
PlatformStatistics.Builder builder = PlatformStatistics.newBuilder();

PlatformStatistics.Memory.Builder memory = PlatformStatistics.Memory.newBuilder()
.setHeap(memoryUsageProto(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()))
.setNonHeap(memoryUsageProto(ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()));

if (detailed) {
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) {
if (memoryPool.getType() != MemoryType.HEAP) {
continue;
}
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) {
if (memoryPool.getType() != MemoryType.HEAP) {
continue;
}

MemoryUsage usage = memoryPool.getUsage();
MemoryUsage collectionUsage = memoryPool.getCollectionUsage();
MemoryUsage usage = memoryPool.getUsage();
MemoryUsage collectionUsage = memoryPool.getCollectionUsage();

if (usage.getMax() == -1) {
usage = new MemoryUsage(usage.getInit(), usage.getUsed(), usage.getCommitted(), usage.getCommitted());
}

memory.addPools(PlatformStatistics.Memory.MemoryPool.newBuilder()
.setName(memoryPool.getName())
.setUsage(memoryUsageProto(usage))
.setCollectionUsage(memoryUsageProto(collectionUsage))
.build()
);
if (usage.getMax() == -1) {
usage = new MemoryUsage(usage.getInit(), usage.getUsed(), usage.getCommitted(), usage.getCommitted());
}

memory.addPools(PlatformStatistics.Memory.MemoryPool.newBuilder()
.setName(memoryPool.getName())
.setUsage(memoryUsageProto(usage))
.setCollectionUsage(memoryUsageProto(collectionUsage))
.build()
);
}

builder.setMemory(memory.build());
Expand Down Expand Up @@ -240,7 +238,7 @@ public PlatformStatistics getPlatformStatistics(Map<String, GarbageCollectorStat
: PlatformStatistics.OnlineMode.OFFLINE
);

if (detailed) {
if (includeWorldStatistics) {
try {
WorldStatisticsProvider worldStatisticsProvider = new WorldStatisticsProvider(
new AsyncWorldInfoProvider(this.platform, this.platform.getPlugin().createWorldInfoProvider())
Expand Down

0 comments on commit f06de57

Please sign in to comment.