Get CPU and RAM usage

前端 未结 2 2109
死守一世寂寞
死守一世寂寞 2020-12-29 09:09

I need to get the ram memory and CPU usage during execution of a process (the process can run sometimes and over 30 minutes). I am able to get the free RAM but the CPU usage

2条回答
  •  一个人的身影
    2020-12-29 10:12

    There is nothing wrong with your values.

    The reason you see differences with what task manager returns is that the "CPU usage" value is something computed for a given interval, i.e. between two NextValue() calls. If task manager "doesn't call its own NextValue" (if we simplify how it works) at the same time you do, you won't return the same results.

    Imagine the following scenario:

    Time 0: 0% actual CPU usage
    Time 1: 50% actual CPU usage
    Time 2: 70% actual CPU usage
    Time 3: 2% actual CPU usage
    Time 4: 100% actual CPU usage
    
    • If you check the value between Time 1 and Time 3, you'll return something based on "50% and 2%".
    • If task manager checks the value between Time 2 and Time 4, it'll return something different, i.e. a value based on "70% and 100%".

    You could try to spawn multiple processes of your own application, you should also see different results.

提交回复
热议问题