Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Measuring CPU usage from code

Discussion in 'Scripting' started by bartofzo, Oct 15, 2018.

  1. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
    Hi,

    I'm building a game server in Unity and I want to measure the % of CPU usage by the process in order to determine how many processes I can run simultaneously.
    I want to to this via code, not the Unity profiler since I'm running it on a remote server.

    I've searched the web but none of the stuff I've found worked for me. They all boil down to using
    System.Diagnostics.PerformanceCounter like here:

    https://answers.unity.com/questions/506736/measure-cpu-and-memory-load-in-code.html

    But on my macbook pro the CPU usage returned is always 100%.

    Any other ways? Thanks.
     
  2. AdamRamberg

    AdamRamberg

    Joined:
    Dec 8, 2016
    Posts:
    22
    Maybe this answer can help you?
     
  3. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
    That is the same link that I posted. Which doesn't work for Unity.