int read_proc_stat() {
static char filename[FILENAME_MAX + 1] = "";
static procfile *ff = NULL;
- static unsigned long long utime_raw = 0, stime_raw = 0, gtime_raw = 0, ntime_raw = 0, collected_usec = 0, last_collected_usec = 0;
+ static unsigned long long utime_raw = 0, stime_raw = 0, gtime_raw = 0, gntime_raw = 0, ntime_raw = 0, collected_usec = 0, last_collected_usec = 0;
if(unlikely(!ff)) {
snprintfz(filename, FILENAME_MAX, "%s/proc/stat", host_prefix);
utime_raw = strtoull(procfile_lineword(ff, 0, 1), NULL, 10);
global_utime = (utime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
+ // nice time, on user time
last = ntime_raw;
ntime_raw = strtoull(procfile_lineword(ff, 0, 2), NULL, 10);
global_utime += (ntime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
stime_raw = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
global_stime = (stime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
- last = gtime_raw;
- gtime_raw = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
- global_gtime = (gtime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
+ last = gtime_raw;
+ gtime_raw = strtoull(procfile_lineword(ff, 0, 10), NULL, 10);
+ global_gtime = (gtime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
+
+ // guest nice time, on guest time
+ last = gntime_raw;
+ gntime_raw = strtoull(procfile_lineword(ff, 0, 11), NULL, 10);
+ global_gtime += (gntime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
+
+ // remove guest time from user time
+ global_utime -= (global_utime > global_gtime)?global_gtime:global_utime;
if(unlikely(global_iterations_counter == 1)) {
global_utime = 0;
softirq = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
steal = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
- if(words >= 10) {
- guest = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
- user -= guest;
- }
- if(words >= 11) {
- guest_nice = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
- nice -= guest_nice;
- }
+ guest = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
+ user -= guest;
+
+ guest_nice = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
+ nice -= guest_nice;
char *title, *type, *context, *family;
long priority;