1
0
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:
SpoinkyNL 2016-06-12 10:51:35 +02:00
parent 13e298a9e8
commit df35b8e5b8
3 changed files with 41 additions and 50 deletions

View File

@ -27,7 +27,7 @@ namespace Artemis.InjectionModules
// Effects // Effects
Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<AudioVisualizerViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<TypeWaveViewModel>().InSingletonScope();
Bind<EffectViewModel>().To<BubblesViewModel>().InSingletonScope(); //Bind<EffectViewModel>().To<BubblesViewModel>().InSingletonScope(); TODO: Performance
Bind<EffectViewModel>().To<WindowsProfileViewModel>().InSingletonScope(); Bind<EffectViewModel>().To<WindowsProfileViewModel>().InSingletonScope();
// Games // Games

View File

@ -18,6 +18,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
public class CpuDataModel public class CpuDataModel
{ {
public int TotalUsage { get; set; }
public int Core1Usage { get; set; } public int Core1Usage { get; set; }
public int Core2Usage { get; set; } public int Core2Usage { get; set; }
public int Core3Usage { get; set; } public int Core3Usage { get; set; }
@ -30,7 +31,6 @@ namespace Artemis.Modules.Effects.WindowsProfile
public class PerformanceDataModel public class PerformanceDataModel
{ {
public int CPUUsage { get; set; }
public int RAMUsage { get; set; } public int RAMUsage { get; set; }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Managers; using Artemis.Managers;
@ -8,15 +9,34 @@ 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 internal static class PerformanceInfo
{ {
[DllImport("psapi.dll", SetLastError = true)] [DllImport("psapi.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [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)] [StructLayout(LayoutKind.Sequential)]
public struct PerformanceInformation public struct PerformanceInformation
@ -36,45 +56,16 @@ namespace Artemis.Modules.Effects.WindowsProfile
public int ProcessCount; public int ProcessCount;
public int ThreadCount; 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 PerformanceCounter _overallCpu;
private SpotifyLocalAPI _spotify; private SpotifyLocalAPI _spotify;
private bool _spotifySetupBusy; private bool _spotifySetupBusy;
private bool _triedCpuFix;
public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings) public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings)
: base(mainManager, new WindowsProfileDataModel()) : base(mainManager, new WindowsProfileDataModel())
@ -119,20 +110,19 @@ namespace Artemis.Modules.Effects.WindowsProfile
_cores.Add(null); _cores.Add(null);
coreCount++; coreCount++;
} }
_overallCPU = GetOverallPerformanceCounter(); _overallCpu = GetOverallPerformanceCounter();
} }
catch (InvalidOperationException) catch (InvalidOperationException)
{ {
_logger.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator."); _logger.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator.");
} }
} }
private void UpdateCpu(WindowsProfileDataModel dataModel) private void UpdateCpu(WindowsProfileDataModel dataModel)
{ {
if (_cores == null || _overallCPU == null) if (_cores == null || _overallCpu == null)
return; return;
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
_cpuFrames++; _cpuFrames++;
if (_cpuFrames < 16) if (_cpuFrames < 16)
@ -159,14 +149,14 @@ namespace Artemis.Modules.Effects.WindowsProfile
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 //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(); var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
Int64 tot = PerformanceInfo.GetTotalMemoryInMiB(); var tot = PerformanceInfo.GetTotalMemoryInMiB();
decimal percentFree = ((decimal)phav / (decimal)tot) * 100; var percentFree = phav/(decimal) tot*100;
decimal percentOccupied = 100 - percentFree; var percentOccupied = 100 - percentFree;
dataModel.Performance.RAMUsage = (int)percentOccupied; dataModel.Performance.RAMUsage = (int) percentOccupied;
} }
public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets) public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets)
@ -176,11 +166,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
public static PerformanceCounter GetOverallPerformanceCounter() public static PerformanceCounter GetOverallPerformanceCounter()
{ {
PerformanceCounter cpuCounter = new PerformanceCounter(); var cpuCounter = new PerformanceCounter
{
cpuCounter.CategoryName = "Processor"; CategoryName = "Processor",
cpuCounter.CounterName = "% Processor Time"; CounterName = "% Processor Time",
cpuCounter.InstanceName = "_Total"; InstanceName = "_Total"
};
return cpuCounter; return cpuCounter;
} }