]> arthur.barton.de Git - netdata.git/commitdiff
apps.plugin now properly sets the ceiling for guest time
authorCosta Tsaousis <costa@tsaousis.gr>
Wed, 27 Jul 2016 09:47:47 +0000 (12:47 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Wed, 27 Jul 2016 09:47:47 +0000 (12:47 +0300)
src/apps_plugin.c
src/proc_stat.c

index 2da76acc1b9ded5a81a948ec87da8c7d7eed0549..797393e4064b9e37d316e0c756d60a294a9f5367 100644 (file)
@@ -949,7 +949,7 @@ unsigned long long global_gtime = 0;
 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);
@@ -971,6 +971,7 @@ int read_proc_stat() {
        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);
@@ -979,9 +980,17 @@ int read_proc_stat() {
        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;
index 13253f4e964084b136644af364c83f9559c4e344..a1e9c2f520c10fa72ca3658fd51a900f7601b0a9 100644 (file)
@@ -75,14 +75,11 @@ int do_proc_stat(int update_every, unsigned long long dt) {
                        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;