mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 17:53:32 +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();
|
Spotify = new Spotify();
|
||||||
Cpu = new CpuDataModel();
|
Cpu = new CpuDataModel();
|
||||||
|
Performance = new PerformanceDataModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CpuDataModel Cpu { get; set; }
|
public CpuDataModel Cpu { get; set; }
|
||||||
|
public PerformanceDataModel Performance { get; set; }
|
||||||
public Spotify Spotify { get; set; }
|
public Spotify Spotify { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +28,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
public int Core8Usage { get; set; }
|
public int Core8Usage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PerformanceDataModel
|
||||||
|
{
|
||||||
|
public int CPUUsage { get; set; }
|
||||||
|
public int RAMUsage { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class Spotify
|
public class Spotify
|
||||||
{
|
{
|
||||||
public bool Running { get; set; }
|
public bool Running { get; set; }
|
||||||
|
|||||||
@ -8,13 +8,69 @@ using Artemis.Models;
|
|||||||
using Artemis.Models.Profiles;
|
using Artemis.Models.Profiles;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
using SpotifyAPI.Local;
|
using SpotifyAPI.Local;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Artemis.Modules.Effects.WindowsProfile
|
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
|
public class WindowsProfileModel : EffectModel
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private List<PerformanceCounter> _cores;
|
private List<PerformanceCounter> _cores;
|
||||||
|
private PerformanceCounter _overallCPU;
|
||||||
private int _cpuFrames;
|
private int _cpuFrames;
|
||||||
private SpotifyLocalAPI _spotify;
|
private SpotifyLocalAPI _spotify;
|
||||||
private bool _spotifySetupBusy;
|
private bool _spotifySetupBusy;
|
||||||
@ -100,6 +156,16 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
|||||||
dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue();
|
dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue();
|
||||||
if (_cores[7] != null)
|
if (_cores[7] != null)
|
||||||
dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue();
|
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)
|
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);
|
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()
|
public static List<PerformanceCounter> GetPerformanceCounters()
|
||||||
{
|
{
|
||||||
var performanceCounters = new List<PerformanceCounter>();
|
var performanceCounters = new List<PerformanceCounter>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user