properly use guest time and children guest time in apps.plugin; fixes #729
Costa Tsaousis committed
Jul 27, 2016 at 12:29 UTC
3b9174a28c7febc7e43fe6ce0657d97dfe7bcd05
1 file changed
+54
-50
src/apps_plugin.c
+54
-50
@@ -708,85 +708,89 @@ int read_proc_pid_stat(struct pid_stat *p) {
708
p->stat_collected_usec = timems();
709
file_counter++;
710
711
- // parse the process name
712
- unsigned int i = 0;
711
+ // p->pid = atol(procfile_lineword(ff, 0, 0+i));
712
+
713
strncpyz(p->comm, procfile_lineword(ff, 0, 1), MAX_COMPARE_NAME);
714
715
- // p->pid = atol(procfile_lineword(ff, 0, 0+i));
716
- // comm is at 1
717
- // p->state = *(procfile_lineword(ff, 0, 2+i));
718
- p->ppid = (int32_t) atol(procfile_lineword(ff, 0, 3 + i));
719
- // p->pgrp = atol(procfile_lineword(ff, 0, 4+i));
720
- // p->session = atol(procfile_lineword(ff, 0, 5+i));
721
- // p->tty_nr = atol(procfile_lineword(ff, 0, 6+i));
722
- // p->tpgid = atol(procfile_lineword(ff, 0, 7+i));
723
- // p->flags = strtoull(procfile_lineword(ff, 0, 8+i), NULL, 10);
715
+ // p->state = *(procfile_lineword(ff, 0, 2));
716
+ p->ppid = (int32_t) atol(procfile_lineword(ff, 0, 3));
717
+ // p->pgrp = atol(procfile_lineword(ff, 0, 4));
718
+ // p->session = atol(procfile_lineword(ff, 0, 5));
719
+ // p->tty_nr = atol(procfile_lineword(ff, 0, 6));
720
+ // p->tpgid = atol(procfile_lineword(ff, 0, 7));
721
+ // p->flags = strtoull(procfile_lineword(ff, 0, 8), NULL, 10);
722
723
unsigned long long last;
724
725
last = p->minflt_raw;
728
- p->minflt_raw = strtoull(procfile_lineword(ff, 0, 9+i), NULL, 10);
726
+ p->minflt_raw = strtoull(procfile_lineword(ff, 0, 9), NULL, 10);
727
p->minflt = (p->minflt_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
728
729
last = p->cminflt_raw;
732
- p->cminflt_raw = strtoull(procfile_lineword(ff, 0, 10+i), NULL, 10);
730
+ p->cminflt_raw = strtoull(procfile_lineword(ff, 0, 10), NULL, 10);
731
p->cminflt = (p->cminflt_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
732
733
last = p->majflt_raw;
736
- p->majflt_raw = strtoull(procfile_lineword(ff, 0, 11+i), NULL, 10);
734
+ p->majflt_raw = strtoull(procfile_lineword(ff, 0, 11), NULL, 10);
735
p->majflt = (p->majflt_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
736
737
last = p->cmajflt_raw;
740
- p->cmajflt_raw = strtoull(procfile_lineword(ff, 0, 12+i), NULL, 10);
738
+ p->cmajflt_raw = strtoull(procfile_lineword(ff, 0, 12), NULL, 10);
739
p->cmajflt = (p->cmajflt_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
740
741
last = p->utime_raw;
744
- p->utime_raw = strtoull(procfile_lineword(ff, 0, 13+i), NULL, 10);
742
+ p->utime_raw = strtoull(procfile_lineword(ff, 0, 13), NULL, 10);
743
p->utime = (p->utime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
744
745
last = p->stime_raw;
748
- p->stime_raw = strtoull(procfile_lineword(ff, 0, 14+i), NULL, 10);
746
+ p->stime_raw = strtoull(procfile_lineword(ff, 0, 14), NULL, 10);
747
p->stime = (p->stime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
748
749
last = p->cutime_raw;
752
- p->cutime_raw = strtoull(procfile_lineword(ff, 0, 15+i), NULL, 10);
750
+ p->cutime_raw = strtoull(procfile_lineword(ff, 0, 15), NULL, 10);
751
p->cutime = (p->cutime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
752
753
last = p->cstime_raw;
756
- p->cstime_raw = strtoull(procfile_lineword(ff, 0, 16+i), NULL, 10);
754
+ p->cstime_raw = strtoull(procfile_lineword(ff, 0, 16), NULL, 10);
755
p->cstime = (p->cstime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
756
759
- // p->priority = strtoull(procfile_lineword(ff, 0, 17+i), NULL, 10);
760
- // p->nice = strtoull(procfile_lineword(ff, 0, 18+i), NULL, 10);
761
- p->num_threads = (int32_t) atol(procfile_lineword(ff, 0, 19 + i));
762
- // p->itrealvalue = strtoull(procfile_lineword(ff, 0, 20+i), NULL, 10);
763
- // p->starttime = strtoull(procfile_lineword(ff, 0, 21+i), NULL, 10);
764
- // p->vsize = strtoull(procfile_lineword(ff, 0, 22+i), NULL, 10);
765
- p->rss = strtoull(procfile_lineword(ff, 0, 23+i), NULL, 10);
766
- // p->rsslim = strtoull(procfile_lineword(ff, 0, 24+i), NULL, 10);
767
- // p->starcode = strtoull(procfile_lineword(ff, 0, 25+i), NULL, 10);
768
- // p->endcode = strtoull(procfile_lineword(ff, 0, 26+i), NULL, 10);
769
- // p->startstack = strtoull(procfile_lineword(ff, 0, 27+i), NULL, 10);
770
- // p->kstkesp = strtoull(procfile_lineword(ff, 0, 28+i), NULL, 10);
771
- // p->kstkeip = strtoull(procfile_lineword(ff, 0, 29+i), NULL, 10);
772
- // p->signal = strtoull(procfile_lineword(ff, 0, 30+i), NULL, 10);
773
- // p->blocked = strtoull(procfile_lineword(ff, 0, 31+i), NULL, 10);
774
- // p->sigignore = strtoull(procfile_lineword(ff, 0, 32+i), NULL, 10);
775
- // p->sigcatch = strtoull(procfile_lineword(ff, 0, 33+i), NULL, 10);
776
- // p->wchan = strtoull(procfile_lineword(ff, 0, 34+i), NULL, 10);
777
- // p->nswap = strtoull(procfile_lineword(ff, 0, 35+i), NULL, 10);
778
- // p->cnswap = strtoull(procfile_lineword(ff, 0, 36+i), NULL, 10);
779
- // p->exit_signal = atol(procfile_lineword(ff, 0, 37+i));
780
- // p->processor = atol(procfile_lineword(ff, 0, 38+i));
781
- // p->rt_priority = strtoul(procfile_lineword(ff, 0, 39+i), NULL, 10);
782
- // p->policy = strtoul(procfile_lineword(ff, 0, 40+i), NULL, 10);
783
- // p->delayacct_blkio_ticks = strtoull(procfile_lineword(ff, 0, 41+i), NULL, 10);
784
- p->gtime_raw = strtoull(procfile_lineword(ff, 0, 42+i), NULL, 10);
785
- p->cgtime_raw = strtoull(procfile_lineword(ff, 0, 43+i), NULL, 10);
786
-
787
- if(show_guest_time || p->gtime_raw || p->cgtime_raw) {
788
- p->utime_raw -= p->gtime_raw;
789
- p->cutime_raw -= p->cgtime_raw;
757
+ // p->priority = strtoull(procfile_lineword(ff, 0, 17), NULL, 10);
758
+ // p->nice = strtoull(procfile_lineword(ff, 0, 18), NULL, 10);
759
+ p->num_threads = (int32_t) atol(procfile_lineword(ff, 0, 19));
760
+ // p->itrealvalue = strtoull(procfile_lineword(ff, 0, 20), NULL, 10);
761
+ // p->starttime = strtoull(procfile_lineword(ff, 0, 21), NULL, 10);
762
+ // p->vsize = strtoull(procfile_lineword(ff, 0, 22), NULL, 10);
763
+ p->rss = strtoull(procfile_lineword(ff, 0, 23), NULL, 10);
764
+ // p->rsslim = strtoull(procfile_lineword(ff, 0, 24), NULL, 10);
765
+ // p->starcode = strtoull(procfile_lineword(ff, 0, 25), NULL, 10);
766
+ // p->endcode = strtoull(procfile_lineword(ff, 0, 26), NULL, 10);
767
+ // p->startstack = strtoull(procfile_lineword(ff, 0, 27), NULL, 10);
768
+ // p->kstkesp = strtoull(procfile_lineword(ff, 0, 28), NULL, 10);
769
+ // p->kstkeip = strtoull(procfile_lineword(ff, 0, 29), NULL, 10);
770
+ // p->signal = strtoull(procfile_lineword(ff, 0, 30), NULL, 10);
771
+ // p->blocked = strtoull(procfile_lineword(ff, 0, 31), NULL, 10);
772
+ // p->sigignore = strtoull(procfile_lineword(ff, 0, 32), NULL, 10);
773
+ // p->sigcatch = strtoull(procfile_lineword(ff, 0, 33), NULL, 10);
774
+ // p->wchan = strtoull(procfile_lineword(ff, 0, 34), NULL, 10);
775
+ // p->nswap = strtoull(procfile_lineword(ff, 0, 35), NULL, 10);
776
+ // p->cnswap = strtoull(procfile_lineword(ff, 0, 36), NULL, 10);
777
+ // p->exit_signal = atol(procfile_lineword(ff, 0, 37));
778
+ // p->processor = atol(procfile_lineword(ff, 0, 38));
779
+ // p->rt_priority = strtoul(procfile_lineword(ff, 0, 39), NULL, 10);
780
+ // p->policy = strtoul(procfile_lineword(ff, 0, 40), NULL, 10);
781
+ // p->delayacct_blkio_ticks = strtoull(procfile_lineword(ff, 0, 41), NULL, 10);
782
+
783
+ last = p->gtime_raw;
784
+ p->gtime_raw = strtoull(procfile_lineword(ff, 0, 42), NULL, 10);
785
+ p->gtime = (p->gtime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
786
+
787
+ last = p->cgtime_raw;
788
+ p->cgtime_raw = strtoull(procfile_lineword(ff, 0, 43), NULL, 10);
789
+ p->cgtime = (p->cgtime_raw - last) * (1000000ULL * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
790
+
791
+ if(show_guest_time || p->gtime || p->cgtime) {
792
+ p->utime -= (p->utime >= p->gtime )?p->gtime :p->utime;
793
+ p->cutime -= (p->cutime >= p->cgtime)?p->cgtime:p->cutime;
794
show_guest_time = 1;
795
}
796