From 858efeba11f8f7ab83120e8c5e7fdce4ef9a107d Mon Sep 17 00:00:00 2001 From: Aspect <43487424+AspectTheDev@users.noreply.github.com> Date: Sun, 14 Jan 2024 02:08:16 -0500 Subject: [PATCH] Add plugin memory usage to o.plugins command --- src/RustCommands.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/RustCommands.cs b/src/RustCommands.cs index a9814f87d..60b20f964 100644 --- a/src/RustCommands.cs +++ b/src/RustCommands.cs @@ -319,7 +319,7 @@ private void PluginsCommand(IPlayer player) int number = 1; foreach (Plugin plugin in loadedPlugins.Where(p => p.Filename != null)) { - output += $"\n {number++:00} \"{plugin.Title}\" ({plugin.Version}) by {plugin.Author} ({plugin.TotalHookTime:0.00}s) - {plugin.Filename.Basename()}"; + output += $"\n {number++:00} \"{plugin.Title}\" ({plugin.Version}) by {plugin.Author} ({plugin.TotalHookTime:0.00}s / {FormatBytes(plugin.TotalHookMemory)}) - {plugin.Filename.Basename()}"; } foreach (string pluginName in unloadedPluginErrors.Keys) @@ -330,6 +330,14 @@ private void PluginsCommand(IPlayer player) player.Reply(output); } + private static string FormatBytes(long bytes) + { + if (bytes < 1024) return $"{bytes:0} B"; + if (bytes < 1048576) return $"{bytes / 1024:0} KB"; + if (bytes < 1073741824) return $"{bytes / 1048576:0} MB"; + return $"{bytes / 1073741824:0} GB"; + } + #endregion Plugins Command #region Reload Command