Display CPU usage on a UI Slider or Text
I'm not sure if this is possible so I'm just going to put this out there. Is there a way to display your actual CPU usage on either a UI slider or Text or both?
Comment
Answer by KnightRiderGuy · Jul 29, 2017 at 02:52 AM
I have tried this but can't seem to get it to do anything but display a CPU value of 100% and a ram value of 0MB, I'm using a mac, does this only work on Windows?
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using UnityEngine.UI;
public class ProfilingScript : MonoBehaviour
{
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
public Text cpuText;
public Text ramText;
void Start()
{
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
}
void Update()
{
print(getCurrentCpuUsage());
//cpuText.text = cpuCounter;
cpuText.text = "CPU: " + getCurrentCpuUsage ();
print(getAvailableRAM());
ramText.text = "RAM: " + getAvailableRAM ();
}
public string getCurrentCpuUsage(){
return cpuCounter.NextValue()+"%";
}
public string getAvailableRAM(){
return ramCounter.NextValue()+"MB";
}
}
Your answer
Follow this Question
Related Questions
Text Objects do Lerp 0 Answers
UI Text created from C# Script 0 Answers
How to do Ammo UI in Unity 5.3.4?,How to do Ammo UI in Unity 5 1 Answer
ui.text string matching doesn't work 0 Answers
[HELP] To show wave number on a zombie survival game. 0 Answers