winmr-api/Services/Scanners/AbstractCpuScanner.cs
2025-07-04 00:04:51 +03:00

25 lines
793 B
C#

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2024-2025 Gregory Lirent */
using WebmrAPI.Utils;
namespace WebmrAPI.Services.Scanners
{
public abstract class AbstractCpuScanner<T> : AbstractScanner<T> where T : new()
{
public static double CalcCpuUsage(double pTime, double elapsed)
{
double cpuUsage = 0;
if (elapsed > 0)
{
cpuUsage = (pTime / elapsed) / Environment.ProcessorCount * 100.0;
if (cpuUsage > 100.0) cpuUsage = 100.0;
}
return cpuUsage;
}
public AbstractCpuScanner(IScanProvider scanner, LazyConcurrentContainer<T> container)
: base(scanner, container) { }
}
}