Fixed memory counter not refreshing over time

This commit is contained in:
Kaoticz
2021-10-17 22:56:10 +00:00
committed by Kwoth
parent 24a4745193
commit 92365fd22d
3 changed files with 19 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ using System.Threading.Tasks;
namespace NadekoBot.Services
{
public class StatsService : IStatsService, IReadyExecutor, INService
public class StatsService : IStatsService, IReadyExecutor, INService, IDisposable
{
private readonly Process _currentProcess = Process.GetCurrentProcess();
private readonly DiscordSocketClient _client;
@@ -23,8 +23,6 @@ namespace NadekoBot.Services
public const string BotVersion = "3.0.7";
public string Author => "Kwoth#2452";
public string Library => "Discord.Net";
public double PrivateMemory => _currentProcess.PrivateMemorySize64 / (double)1.MiB();
public double MessagesPerSecond => MessageCounter / GetUptime().TotalSeconds;
private long _textChannels;
@@ -173,5 +171,17 @@ namespace NadekoBot.Services
_voiceChannels = guilds.Sum(g => g.Channels.Count(cx => cx is IVoiceChannel));
return Task.CompletedTask;
}
public double GetPrivateMemory()
{
_currentProcess.Refresh();
return _currentProcess.PrivateMemorySize64 / (double)1.MiB();
}
public void Dispose()
{
_currentProcess.Dispose();
GC.SuppressFinalize(this);
}
}
}