From 3d4a2128e2eeca57395829580b5d044478544966 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Wed, 9 Aug 2023 03:42:33 +0200 Subject: [PATCH] switched to the new converter instead of the formatter functions to convert byte sizes --- Moonlight/App/Helpers/Formatter.cs | 8 -------- Moonlight/App/Services/Background/CleanupService.cs | 10 +++++----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Moonlight/App/Helpers/Formatter.cs b/Moonlight/App/Helpers/Formatter.cs index 90df31f..132a6fd 100644 --- a/Moonlight/App/Helpers/Formatter.cs +++ b/Moonlight/App/Helpers/Formatter.cs @@ -156,15 +156,7 @@ public static class Formatter return (i / (1024D * 1024D)).Round(2) + " GB"; } } - - public static double BytesToGb(long bytes) - { - const double gbMultiplier = 1024 * 1024 * 1024; // 1 GB = 1024 MB * 1024 KB * 1024 B - double gigabytes = (double)bytes / gbMultiplier; - return gigabytes; - } - public static RenderFragment FormatLineBreaks(string content) { return builder => diff --git a/Moonlight/App/Services/Background/CleanupService.cs b/Moonlight/App/Services/Background/CleanupService.cs index 4354347..0492c5f 100644 --- a/Moonlight/App/Services/Background/CleanupService.cs +++ b/Moonlight/App/Services/Background/CleanupService.cs @@ -93,14 +93,14 @@ public class CleanupService Logger.Debug($"Max CPU: {maxCpu}"); executeCleanup = true; } - else if (Formatter.BytesToGb(memoryMetrics.Total) - Formatter.BytesToGb(memoryMetrics.Used) < - minMemory / 1024D) + else if (ByteSizeValue.FromKiloBytes(memoryMetrics.Total).MegaBytes - ByteSizeValue.FromKiloBytes(memoryMetrics.Used).MegaBytes < + minMemory) { Logger.Debug($"{node.Name}: Memory Usage is too high"); - Logger.Debug($"Memory (Total): {Formatter.BytesToGb(memoryMetrics.Total)}"); - Logger.Debug($"Memory (Used): {Formatter.BytesToGb(memoryMetrics.Used)}"); + Logger.Debug($"Memory (Total): {ByteSizeValue.FromKiloBytes(memoryMetrics.Total).MegaBytes}"); + Logger.Debug($"Memory (Used): {ByteSizeValue.FromKiloBytes(memoryMetrics.Used).MegaBytes}"); Logger.Debug( - $"Memory (Free): {Formatter.BytesToGb(memoryMetrics.Total) - Formatter.BytesToGb(memoryMetrics.Used)}"); + $"Memory (Free): {ByteSizeValue.FromKiloBytes(memoryMetrics.Total).MegaBytes - ByteSizeValue.FromKiloBytes(memoryMetrics.Used).MegaBytes}"); Logger.Debug($"Min Memory: {minMemory}"); executeCleanup = true; }