Skip to content

Commit

Permalink
Add plugin memory usage to o.plugins command
Browse files Browse the repository at this point in the history
  • Loading branch information
AspectTheDev authored and MrBlue committed Feb 21, 2024
1 parent a170dd7 commit 858efeb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/RustCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 858efeb

Please sign in to comment.