apps.plugin now properly sets the ceiling for guest time
Costa Tsaousis committed
Jul 27, 2016 at 12:47 UTC
14188326bf547a39600716685302f3fdd13b46ce
2 files changed
+18
-12
src/apps_plugin.c
+13
-4
@@ -949,7 +949,7 @@ unsigned long long global_gtime = 0;
949
int read_proc_stat() {
950
static char filename[FILENAME_MAX + 1] = "";
951
static procfile *ff = NULL;
952
- static unsigned long long utime_raw = 0, stime_raw = 0, gtime_raw = 0, ntime_raw = 0, collected_usec = 0, last_collected_usec = 0;
952
+ 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;
953
954
if(unlikely(!ff)) {
955
snprintfz(filename, FILENAME_MAX, "%s/proc/stat", host_prefix);
@@ -971,6 +971,7 @@ int read_proc_stat() {
971
utime_raw = strtoull(procfile_lineword(ff, 0, 1), NULL, 10);
972
global_utime = (utime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
973
974
+ // nice time, on user time
975
last = ntime_raw;
976
ntime_raw = strtoull(procfile_lineword(ff, 0, 2), NULL, 10);
977
global_utime += (ntime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
@@ -979,9 +980,17 @@ int read_proc_stat() {
980
stime_raw = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
981
global_stime = (stime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
982
982
- last = gtime_raw;
983
- gtime_raw = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
984
- global_gtime = (gtime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
983
+ last = gtime_raw;
984
+ gtime_raw = strtoull(procfile_lineword(ff, 0, 10), NULL, 10);
985
+ global_gtime = (gtime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
986
+
987
+ // guest nice time, on guest time
988
+ last = gntime_raw;
989
+ gntime_raw = strtoull(procfile_lineword(ff, 0, 11), NULL, 10);
990
+ global_gtime += (gntime_raw - last) * (1000000ULL * RATES_DETAIL) / (collected_usec - last_collected_usec);
991
+
992
+ // remove guest time from user time
993
+ global_utime -= (global_utime > global_gtime)?global_gtime:global_utime;
994
995
if(unlikely(global_iterations_counter == 1)) {
996
global_utime = 0;
src/proc_stat.c
+5
-8
@@ -75,14 +75,11 @@ int do_proc_stat(int update_every, unsigned long long dt) {
75
softirq = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
76
steal = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
77
78
- if(words >= 10) {
79
- guest = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
80
- user -= guest;
81
- }
82
- if(words >= 11) {
83
- guest_nice = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
84
- nice -= guest_nice;
85
- }
78
+ guest = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
79
+ user -= guest;
80
+
81
+ guest_nice = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
82
+ nice -= guest_nice;
83
84
char *title, *type, *context, *family;
85
long priority;