mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added Overall CPU and RAM resource monitors for Windows Profile.
This commit is contained in:
parent
82b2607911
commit
5f281480e1
@ -8,9 +8,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
{
|
||||
Spotify = new Spotify();
|
||||
Cpu = new CpuDataModel();
|
||||
Performance = new PerformanceDataModel();
|
||||
}
|
||||
|
||||
public CpuDataModel Cpu { get; set; }
|
||||
public PerformanceDataModel Performance { get; set; }
|
||||
public Spotify Spotify { get; set; }
|
||||
}
|
||||
|
||||
@ -26,6 +28,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
public int Core8Usage { get; set; }
|
||||
}
|
||||
|
||||
public class PerformanceDataModel
|
||||
{
|
||||
public int CPUUsage { get; set; }
|
||||
public int RAMUsage { get; set; }
|
||||
}
|
||||
|
||||
public class Spotify
|
||||
{
|
||||
public bool Running { get; set; }
|
||||
|
||||
@ -8,13 +8,69 @@ using Artemis.Models;
|
||||
using Artemis.Models.Profiles;
|
||||
using Ninject.Extensions.Logging;
|
||||
using SpotifyAPI.Local;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Artemis.Modules.Effects.WindowsProfile
|
||||
{
|
||||
static class PerformanceInfo
|
||||
{
|
||||
[DllImport("psapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetPerformanceInfo([Out] out PerformanceInformation PerformanceInformation, [In] int Size);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PerformanceInformation
|
||||
{
|
||||
public int Size;
|
||||
public IntPtr CommitTotal;
|
||||
public IntPtr CommitLimit;
|
||||
public IntPtr CommitPeak;
|
||||
public IntPtr PhysicalTotal;
|
||||
public IntPtr PhysicalAvailable;
|
||||
public IntPtr SystemCache;
|
||||
public IntPtr KernelTotal;
|
||||
public IntPtr KernelPaged;
|
||||
public IntPtr KernelNonPaged;
|
||||
public IntPtr PageSize;
|
||||
public int HandlesCount;
|
||||
public int ProcessCount;
|
||||
public int ThreadCount;
|
||||
}
|
||||
|
||||
public static Int64 GetPhysicalAvailableMemoryInMiB()
|
||||
{
|
||||
PerformanceInformation pi = new PerformanceInformation();
|
||||
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
|
||||
{
|
||||
return Convert.ToInt64((pi.PhysicalAvailable.ToInt64() * pi.PageSize.ToInt64() / 1048576));
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Int64 GetTotalMemoryInMiB()
|
||||
{
|
||||
PerformanceInformation pi = new PerformanceInformation();
|
||||
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
|
||||
{
|
||||
return Convert.ToInt64((pi.PhysicalTotal.ToInt64() * pi.PageSize.ToInt64() / 1048576));
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowsProfileModel : EffectModel
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private List<PerformanceCounter> _cores;
|
||||
private PerformanceCounter _overallCPU;
|
||||
private int _cpuFrames;
|
||||
private SpotifyLocalAPI _spotify;
|
||||
private bool _spotifySetupBusy;
|
||||
@ -100,6 +156,16 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue();
|
||||
if (_cores[7] != null)
|
||||
dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue();
|
||||
|
||||
//From Ted - Let's get overall RAM and CPU usage here
|
||||
dataModel.Performance.CPUUsage = (int)_overallCPU.NextValue();
|
||||
|
||||
Int64 phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
|
||||
Int64 tot = PerformanceInfo.GetTotalMemoryInMiB();
|
||||
decimal percentFree = ((decimal)phav / (decimal)tot) * 100;
|
||||
decimal percentOccupied = 100 - percentFree;
|
||||
|
||||
dataModel.Performance.RAMUsage = (int)percentOccupied;
|
||||
}
|
||||
|
||||
public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets)
|
||||
@ -107,6 +173,17 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
return Profile.GetRenderLayers<WindowsProfileDataModel>(DataModel, renderMice, renderHeadsets, false);
|
||||
}
|
||||
|
||||
public static PerformanceCounter GetOverallPerformanceCounter()
|
||||
{
|
||||
PerformanceCounter cpuCounter = new PerformanceCounter();
|
||||
|
||||
cpuCounter.CategoryName = "Processor";
|
||||
cpuCounter.CounterName = "% Processor Time";
|
||||
cpuCounter.InstanceName = "_Total";
|
||||
|
||||
return cpuCounter;
|
||||
}
|
||||
|
||||
public static List<PerformanceCounter> GetPerformanceCounters()
|
||||
{
|
||||
var performanceCounters = new List<PerformanceCounter>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user