public static CpuUsage?Get(CpuUsageScope scope) { var platform = CrossInfo.ThePlatform; if (scope == CpuUsageScope.Process) { if (platform == CrossInfo.Platform.Linux || platform == CrossInfo.Platform.MacOSX) { return(LinuxResourceUsageReader.GetByProcess()); } else { return(WindowsCpuUsage.Get(CpuUsageScope.Process)); } } if (platform == CrossInfo.Platform.Linux) { return(LinuxResourceUsageReader.GetByThread()); } else if (platform == CrossInfo.Platform.MacOSX) { return(MacOsThreadInfo.GetByThread()); } else if (platform == CrossInfo.Platform.Windows) { // throw new NotImplementedException("CPU Usage in the scope of the thread is not yet implemented for Windows"); return(WindowsCpuUsage.Get(CpuUsageScope.Thread)); } throw new InvalidOperationException($"CPU usage in the scope of {scope} is a kind of an unknown on the {platform}"); }
public static PosixResourceUsage?GetByScope(CpuUsageScope scope) { int kernelScope = scope == CpuUsageScope.Process ? LinuxResourceUsageInterop.RUSAGE_SELF : LinuxResourceUsageInterop.RUSAGE_THREAD; return(LinuxResourceUsageReader.GetResourceUsageByScope(kernelScope)); }