feat: add total memory usage to dev bar

This commit is contained in:
goat 2022-01-25 21:50:31 +01:00
parent 29a39b4be1
commit 1083c2f95e
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
3 changed files with 21 additions and 19 deletions

View file

@ -714,6 +714,7 @@ namespace Dalamud.Interface.Internal
ImGui.BeginMenu(Util.GetGitHash(), false);
ImGui.BeginMenu(this.frameCount.ToString(), false);
ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("F2"), false);
ImGui.BeginMenu($"{Util.FormatBytes(GC.GetTotalMemory(false))} total managed", false);
ImGui.EndMainMenuBar();
}

View file

@ -13,6 +13,7 @@ using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Internal;
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows
@ -197,24 +198,6 @@ namespace Dalamud.Interface.Internal.Windows
this.DrawSaveCloseButtons();
}
/// <summary>
/// Transform byte count to human readable format.
/// </summary>
/// <param name="bytes">Number of bytes.</param>
/// <returns>Human readable version.</returns>
private static string FormatBytes(long bytes)
{
string[] suffix = { "B", "KB", "MB", "GB", "TB" };
int i;
double dblSByte = bytes;
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return $"{dblSByte:0.##} {suffix[i]}";
}
private void DrawGeneralTab()
{
ImGui.Text(Loc.Localize("DalamudSettingsLanguage", "Language"));
@ -351,7 +334,7 @@ namespace Dalamud.Interface.Internal.Windows
ImGuiHelpers.ScaledDummy(12);
ImGui.TextColored(ImGuiColors.DalamudGrey, "Total memory used by Dalamud & Plugins: " + FormatBytes(GC.GetTotalMemory(false)));
ImGui.TextColored(ImGuiColors.DalamudGrey, "Total memory used by Dalamud & Plugins: " + Util.FormatBytes(GC.GetTotalMemory(false)));
}
private void DrawCustomReposSection()

View file

@ -335,6 +335,24 @@ namespace Dalamud.Utility
if (exit)
Environment.Exit(-1);
}
/// <summary>
/// Transform byte count to human readable format.
/// </summary>
/// <param name="bytes">Number of bytes.</param>
/// <returns>Human readable version.</returns>
public static string FormatBytes(long bytes)
{
string[] suffix = { "B", "KB", "MB", "GB", "TB" };
int i;
double dblSByte = bytes;
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return $"{dblSByte:0.##} {suffix[i]}";
}
/// <summary>
/// Retrieve a UTF8 string from a null terminated byte array.