How can I write CPU usage on screen?
This returns 0 on 1st frame and 100 on every other. is there other way to get CPU usage in script?
using UnityEngine; using System.Collections; using System.Diagnostics;
public class PerformanceCheck : MonoBehaviour { System.Diagnostics.PerformanceCounter cpuCounter;
void Start()
{
System.Diagnostics.PerformanceCounterCategory.Exists("PerformanceCounter");
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", Process.GetCurrentProcess().ProcessName);
/*cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";*/
}
void OnGUI()
{
GUI.Label(new Rect(10, 10, 100, 20), "CPU: " + getCurrentCpuUsage());
}
public string getCurrentCpuUsage()
{
return cpuCounter.NextValue() + "%";
}
}
Answer by DenisTribouillois · Jul 20, 2016 at 02:14 PM
Hello, you should check this thread :
http://answers.unity3d.com/questions/506736/measure-cpu-and-memory-load-in-code.html
Answer by unity_Gf9sAXj5a0VNOg · Dec 18, 2017 at 08:18 AM
Have a look into this example, I hope it will help.
Your answer
Follow this Question
Related Questions
How to make basic non hostile ai that runs around? 0 Answers
Can You help me Fix This? (Infinite level Generator) 0 Answers
The location of the object by points 0 Answers
GTA 2 Movement Script 1 Answer