c# - In Unity3D, PerformanceCounter always returns 0 -


this has been asked question , i've tried solutions prescribed in other questions applicable scenario (like initial value being expected 0, repeatedly calling nextvalue() allow performancecounter gather more data, etc.).

now i'm wondering if there's prescribed way of using class unity stopping me making work.

testing on android devices , editor, getcpuusage() , getramusage() methods print out 0, though these functions called every frame.

how can make performancecounter work in unity? alternatively, if known issue, there alternative solutions can produce same desired result of displaying onscreen memory and/or cpu usage of app?

code snippet:

public class performancecounterdisplay : monobehaviour {     private performancecounter _cpucounter;     private performancecounter _ramcounter;      [serializefield]     private text _cpucountertext;      [serializefield]     private text _ramcountertext;      void start()     {         _cpucounter = new performancecounter("process", "% processor time", "_total");         _ramcounter = new performancecounter("memory", "available mbytes", "_total");         _cpucountertext.text = getcpuusage();         _ramcountertext.text = getramusage();     }      void update()     {         _cpucountertext.text = getcpuusage();         _ramcountertext.text = getramusage();     }      public string getcpuusage()     {         try         {             return "cpu: " + _cpucounter.nextvalue() + "%";         }         catch (exception eh)         {             debug.logerror("cannot infomation pc's cpu");         }         return "";     }      public string getramusage()     {         try         {             return "ram: " + _ramcounter.nextvalue() + "mb";         }         catch (exception eh)         {             debug.logerror("cannot infomation pc's ram");         }         return "";     } } 


Comments