mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Disabled Bubbles for now, moved CPUUsage to Cpu class in Windows Profile
This commit is contained in:
parent
13e298a9e8
commit
df35b8e5b8
@ -27,7 +27,7 @@ namespace Artemis.InjectionModules
|
||||
// Effects
|
||||
Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope();
|
||||
Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope();
|
||||
Bind<EffectViewModel>().To<BubblesViewModel>().InSingletonScope();
|
||||
//Bind<EffectViewModel>().To<BubblesViewModel>().InSingletonScope(); TODO: Performance
|
||||
Bind<EffectViewModel>().To<WindowsProfileViewModel>().InSingletonScope();
|
||||
|
||||
// Games
|
||||
|
||||
@ -18,6 +18,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
|
||||
public class CpuDataModel
|
||||
{
|
||||
public int TotalUsage { get; set; }
|
||||
public int Core1Usage { get; set; }
|
||||
public int Core2Usage { get; set; }
|
||||
public int Core3Usage { get; set; }
|
||||
@ -30,7 +31,6 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
|
||||
public class PerformanceDataModel
|
||||
{
|
||||
public int CPUUsage { get; set; }
|
||||
public int RAMUsage { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Managers;
|
||||
@ -8,15 +9,34 @@ 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
|
||||
internal static class PerformanceInfo
|
||||
{
|
||||
[DllImport("psapi.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetPerformanceInfo([Out] out PerformanceInformation PerformanceInformation, [In] int Size);
|
||||
public static extern bool GetPerformanceInfo([Out] out PerformanceInformation performanceInformation, [In] int size);
|
||||
|
||||
public static long GetPhysicalAvailableMemoryInMiB()
|
||||
{
|
||||
var pi = new PerformanceInformation();
|
||||
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
|
||||
{
|
||||
return Convert.ToInt64(pi.PhysicalAvailable.ToInt64()*pi.PageSize.ToInt64()/1048576);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static long GetTotalMemoryInMiB()
|
||||
{
|
||||
var pi = new PerformanceInformation();
|
||||
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
|
||||
{
|
||||
return Convert.ToInt64(pi.PhysicalTotal.ToInt64()*pi.PageSize.ToInt64()/1048576);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PerformanceInformation
|
||||
@ -36,45 +56,16 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
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 PerformanceCounter _overallCpu;
|
||||
private SpotifyLocalAPI _spotify;
|
||||
private bool _spotifySetupBusy;
|
||||
private bool _triedCpuFix;
|
||||
|
||||
public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings)
|
||||
: base(mainManager, new WindowsProfileDataModel())
|
||||
@ -119,20 +110,19 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
_cores.Add(null);
|
||||
coreCount++;
|
||||
}
|
||||
_overallCPU = GetOverallPerformanceCounter();
|
||||
_overallCpu = GetOverallPerformanceCounter();
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
_logger.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateCpu(WindowsProfileDataModel dataModel)
|
||||
{
|
||||
if (_cores == null || _overallCPU == null)
|
||||
if (_cores == null || _overallCpu == null)
|
||||
return;
|
||||
|
||||
|
||||
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
|
||||
_cpuFrames++;
|
||||
if (_cpuFrames < 16)
|
||||
@ -159,14 +149,14 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue();
|
||||
|
||||
//From Ted - Let's get overall RAM and CPU usage here
|
||||
dataModel.Performance.CPUUsage = (int)_overallCPU.NextValue();
|
||||
dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue();
|
||||
|
||||
Int64 phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
|
||||
Int64 tot = PerformanceInfo.GetTotalMemoryInMiB();
|
||||
decimal percentFree = ((decimal)phav / (decimal)tot) * 100;
|
||||
decimal percentOccupied = 100 - percentFree;
|
||||
var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
|
||||
var tot = PerformanceInfo.GetTotalMemoryInMiB();
|
||||
var percentFree = phav/(decimal) tot*100;
|
||||
var percentOccupied = 100 - percentFree;
|
||||
|
||||
dataModel.Performance.RAMUsage = (int)percentOccupied;
|
||||
dataModel.Performance.RAMUsage = (int) percentOccupied;
|
||||
}
|
||||
|
||||
public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets)
|
||||
@ -176,11 +166,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
|
||||
public static PerformanceCounter GetOverallPerformanceCounter()
|
||||
{
|
||||
PerformanceCounter cpuCounter = new PerformanceCounter();
|
||||
|
||||
cpuCounter.CategoryName = "Processor";
|
||||
cpuCounter.CounterName = "% Processor Time";
|
||||
cpuCounter.InstanceName = "_Total";
|
||||
var cpuCounter = new PerformanceCounter
|
||||
{
|
||||
CategoryName = "Processor",
|
||||
CounterName = "% Processor Time",
|
||||
InstanceName = "_Total"
|
||||
};
|
||||
|
||||
return cpuCounter;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user