When I now sum up the values for all processes and compare it to the overall calculated CPU usage, I receive a slightly higher value for the aggregated value most of the time (although the values are quite close for all different CPU loads).Ĭan anyone explain to me, what's the reason for that? Are there any CPU resources that are used by more than one process and thus accounted twice or more in my accumlation? Or am I simply missing something here? I can not find any further hint in the Linux man page for the proc file system ( ) as well. When I now calculate this sum and divide it by the total amount of jiffies in the analyzed interval, I would assume the formula for one process to be processCPUUsage = ((process_utime_aft - process_utime_bef) + (process_stime_aft - process_stime_bef)) / ((user_aft - user_bef) + (nice_aft - nice_bef) + (system_aft - system_bef) + (idle_aft - idle_bef)) * 100 %Īccording to How to calculate the CPU usage of a process by PID in Linux from C? the used jiffies for a single process can be calculated by adding utime and stime from /proc/$/stat (column 14 and 15 in this file). On multi core systems (and some Linux versions) the second number is the sum of the idle time accumulated by each CPU. The formula would be totalCPUUsage = ((user_aft - user_bef) + (nice_aft - nice_bef) + (system_aft - system_bef)) / If you now sample the values at two points in time and compare the values for user, nice, system and idle at the two time points, you can calculate the average CPU usage in this interval. For now the CPU I am using is multi-cored (2 cores).Īccording to How to determine CPU and memory consumption from inside a process? it is possible to calculate all "jiffies" available in the system since startup using the values for "cpu" in /proc/stat. My assumption would be that the sum of all process CPU times would be equal to the total value for the whole CPU. The programm should be designed and implemented in C++. Seconds process has been running: seconds uptime - pstime Usage: cpuusage putime 1000 / seconds print: cpuusage / 10 '. putime total time process has been using the CPU. pstime process start time measured in seconds from boot. The pgi+ib stime, utime and cpu can’t be right.I need to calculate the overall CPU usage of my Linux device over some time (1-5 seconds) and a list of processes with their respective CPU usage times. ps calculates CPU usage in the following manner: uptime total time system has been running. In all cases, I used the vendor-provided libs (Intel Cluster Studio, PGI Cluster Dev Kit). I’ve tested several versions: compiled w/ gnu, intel and pgi compilers, w/out and w/ IB support (mpich or mvapich). The times are dead wrong, and the problem is observed with more than one code - I’ve built and ran the High Performance Computing Linpack Benchmark (HPL) ver 2.0
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |