3

I have the following question:

In UWP, how can we get an overall CPU percentage usage, RAM usage,free RAM, Running process, etc? It's required for task manager in UWP.

Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
JVermeulen
  • 225
  • 4
  • 8

2 Answers2

7

Hi after doing some looking it doesn't seem as if you can get the device CPU, RAM and Free Ram or the Running Processes. You can get the CPU, memory as well as the memory limits for an application.

You can get these through the following ways:

RAM: This is accessed through the MemoryManager Class

MemoryManager.AppMemoryUsage 

And there are some other static members that will help you.

CPU: As for CPU this is retrieved using - Windows.System.Diagnostics.ProcessCpuUsage 

  • 2
    ProcessDiagnosticInfo.GetForCurrentProcess.CpuUsage.GetReport() returns UserTime and KernelTime as in cpu time, not percentage. How do you calculate them into cpu usage percentage? – Selim Balci Jan 16 '18 at 21:15
0

You can access the total system memory and CPU usage with the SystemDiagnosticInfo class.

var diagnosticInfo = SystemDiagnosticInfo.GetForCurrentSystem();

// Total physical RAM
ulong totalMemory = diagnosticInfo.MemoryUsage.GetReport().TotalPhysicalSizeInBytes;

var cpuUsage = diagnosticInfo.CpuUsage.GetReport();
// Total kernel/user/idle time since system start
var kernelTime = cpuUsage.KernelTime
var userTime = cpuUsage.UserTime
var idleTime = cpuUsage.IdleTime

To get CPU usage as a percentage, you need to take measurements at two different points in time (e.g. 100ms apart), then calculate (deltaKernelTime + deltaUserTime) / (deltaKernelTime + deltaUserTime + deltaIdleTime).