- Home /
Question by
MrSaw · Mar 24, 2019 at 10:39 AM ·
c#scripting problemperformancememory usagecpu usage
PerformanceCounters return 0MB RAM and %100 CPU in Unity
When i use PerformanceCounter in unity, they return 0mb free RAM and %100 cpu usage. If i use same codes on Visual Studio project, it works. How can i allow this code to get system's information in Unity? I need to get free RAM and CPU usage on the computer. Unity's profiler doesn't shows free memory. Here is the .dll file which i wrote.
using System;
using System.Diagnostics;
namespace MemCu
{
public class Profilers
{
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
string mem;
string cpu;
public string ProfileCpu()
{
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
cpu = Convert.ToString(cpuCounter.NextValue());
return cpu;
}
public string ProfileMem()
{
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
mem = Convert.ToString(ramCounter.NextValue());
return mem;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Question about C# parameters 2 Answers
How to use PerformanceCounter(C#) in Unity 0 Answers
Multiple Cars not working 1 Answer
Tracking cpu usage and memory for Web Player 1 Answer
Distribute terrain in zones 3 Answers