Skip to content

Commit

Permalink
memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
anviaan committed Jul 28, 2024
1 parent 2d3b95a commit 9ceadc7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ private static void inject(CallbackInfoReturnable<OptionPage> cir) {
.setControl(TickBoxControl::new)
.setBinding((opts, value) -> opts.extraInformationSettings.showSessionTime = value, opts -> opts.extraInformationSettings.showSessionTime)
.build())
.add(OptionImpl.createBuilder(Boolean.TYPE, sodiumExtraOpts)
.setName(Text.of("Memory usage"))
.setTooltip(Text.of("Show the memory usage on the overlay."))
.setControl(TickBoxControl::new)
.setBinding((opts, value) -> opts.extraInformationSettings.showMemoryUsage = value, opts -> opts.extraInformationSettings.showMemoryUsage)
.build())
.add(OptionImpl.createBuilder(Boolean.TYPE, sodiumExtraOpts)
.setName(Text.of("Memory usage Extended"))
.setTooltip(Text.of("Show a more detailed memory usage on the overlay."))
.setControl(TickBoxControl::new)
.setBinding((opts, value) -> opts.extraInformationSettings.showMemoryUsageExtended = value, opts -> opts.extraInformationSettings.showMemoryUsageExtended)
.build())
.build());

cir.setReturnValue(new OptionPage(Text.translatable("sodium-extra.option.extras"), ImmutableList.copyOf(groups)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,20 @@ private void inject(MinecraftClient client, CallbackInfo ci) {

textList.add(Text.of(hours + "h " + minutes + "m " + seconds + "s"));
}

if (SodiumExtraInformationClient.options().extraInformationSettings.showMemoryUsage) {
Runtime runtime = Runtime.getRuntime();
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
long maxMemory = runtime.maxMemory();

int memoryUsagePercent = (int) ((double) usedMemory / maxMemory * 100);
textList.add(Text.of(memoryUsagePercent + "%"));

if (SodiumExtraInformationClient.options().extraInformationSettings.showMemoryUsageExtended) {
long usedMemoryMB = usedMemory / (1024 * 1024);
long maxMemoryMB = maxMemory / (1024 * 1024);
textList.add(Text.of(usedMemoryMB + "MB / " + maxMemoryMB + "MB"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ public static class ExtraInformationSettings {
public String localTimeFormat;
public boolean showWordTime;
public boolean showSessionTime;
public boolean showMemoryUsage;
public boolean showMemoryUsageExtended;

public ExtraInformationSettings() {
this.showLocalTime = false;
this.localTimeFormat = "HH:mm";
this.showWordTime = false;
this.showSessionTime = false;
this.showMemoryUsage = false;
this.showMemoryUsageExtended = false;
}

private boolean validateTimeFormat(String format) {
Expand Down

0 comments on commit 9ceadc7

Please sign in to comment.