From df35b8e5b82238c3e2102fab07afb501840cd089 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 12 Jun 2016 10:51:35 +0200 Subject: [PATCH] Disabled Bubbles for now, moved CPUUsage to Cpu class in Windows Profile --- .../InjectionModules/ArtemisModules.cs | 2 +- .../WindowsProfile/WindowsProfileDataModel.cs | 2 +- .../WindowsProfile/WindowsProfileModel.cs | 87 +++++++++---------- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/Artemis/Artemis/InjectionModules/ArtemisModules.cs b/Artemis/Artemis/InjectionModules/ArtemisModules.cs index 2ec4602f1..531797855 100644 --- a/Artemis/Artemis/InjectionModules/ArtemisModules.cs +++ b/Artemis/Artemis/InjectionModules/ArtemisModules.cs @@ -27,7 +27,7 @@ namespace Artemis.InjectionModules // Effects Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); + //Bind().To().InSingletonScope(); TODO: Performance Bind().To().InSingletonScope(); // Games diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs index c44c5a36a..be27cad22 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs @@ -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; } } diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs index 630f5bd01..03d1843ee 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -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 _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 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; }