Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dend committed Jul 18, 2021
1 parent 69e8eba commit 86f73b4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Deck.Surf.SDK.Interfaces;
using Deck.Surf.SDK.Models;
using System;
using System.Diagnostics;

namespace Deck.Surf.Plugin.Barn.Commands
Expand Down
9 changes: 6 additions & 3 deletions src/Deck.Surf/Deck.Surf.Plugin.Barn/Commands/ShowCPUUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Timers;

namespace Deck.Surf.Plugin.Barn.Commands
{
[CompatibleWith(DeviceModel.XL)]
class ShowCPUUsage : IDSCommand
{
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";

public string Name => "Launch Application";
public string Description => "Launches an application on the machine.";

Expand All @@ -37,9 +40,9 @@ public void ExecuteOnActivation(CommandMapping mappedCommand, ConnectedDevice ma

private static int GetCPUUsage()
{
PerformanceCounter perfCounter = new("Processor", "% Processor Time", "_Total");
PerformanceCounter perfCounter = new(CategoryName, CounterName, InstanceName);
// Dummy call because PerformanceCounter will always start with zero.
var inspectionDummy = perfCounter.NextValue();
perfCounter.NextValue();
Thread.Sleep(1000);
var targetCPUUsage = (int)Math.Round(perfCounter.NextValue());
return targetCPUUsage;
Expand Down
2 changes: 1 addition & 1 deletion src/Deck.Surf/Deck.Surf.Plugin.Barn/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "The CPU function is only expected to work on Windows.", Scope = "member", Target = "~M:Deck.Surf.Plugin.Barn.Commands.ShowCPUUsage.GetCPUUsage~System.UInt32")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "CPU function should only be used in Windows.", Scope = "member", Target = "~M:Deck.Surf.Plugin.Barn.Commands.ShowCPUUsage.GetCPUUsage~System.Int32")]

0 comments on commit 86f73b4

Please sign in to comment.