apps.plugin now properly tracks child resource usage into the application groups, users and user groups
Costa Tsaousis committed
Jun 29, 2016 at 23:47 UTC
d0cad08275fac3879453762928f1259e4fc91cbf
1 file changed
+27
-13
src/apps_plugin.c
+27
-13
@@ -1203,16 +1203,14 @@ int collect_data_for_all_processes_from_proc(void)
1203
// /proc/<pid>/stat
1204
1205
if(unlikely(read_proc_pid_stat(p))) {
1206
- error("Cannot process %s/proc/%d/stat", host_prefix, pid);
1207
-
1206
+ error("Cannot process %s/proc/%d/stat", host_prefix, pid);
1207
// there is no reason to proceed if we cannot get its status
1208
continue;
1209
}
1210
1211
// check its parent pid
1212
if(unlikely(p->ppid < 0 || p->ppid > pid_max)) {
1214
- error("Pid %d states invalid parent pid %d. Using 0.", pid, p->ppid);
1215
-
1213
+ error("Pid %d states invalid parent pid %d. Using 0.", pid, p->ppid);
1214
p->ppid = 0;
1215
}
1216
@@ -1332,22 +1330,38 @@ void link_all_processes_to_their_parents(void) {
1330
for(p = root_of_pids; p ; p = p->next) {
1331
// for each process found running
1332
1333
+ if(likely(p->new_entry && p->updated)) {
1334
+ // the first time we see an entry
1335
+ // we remove the exited children figures
1336
+ // to avoid spikes
1337
+ p->fix_cminflt += p->cminflt;
1338
+ p->fix_cmajflt += p->cmajflt;
1339
+ p->fix_cutime += p->cutime;
1340
+ p->fix_cstime += p->cstime;
1341
+ }
1342
+
1343
if(likely(p->ppid > 0 && all_pids[p->ppid])) {
1344
+ struct pid_stat *pp;
1345
// for valid processes
1346
1338
- if(unlikely(debug || (p->target && p->target->debug)))
1339
- fprintf(stderr, "apps.plugin: \tparent of %d (%s) is %d (%s)\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm);
1340
-
1341
- p->parent = all_pids[p->ppid];
1347
+ p->parent = pp = all_pids[p->ppid];
1348
p->parent->children_count++;
1349
1350
+ if(unlikely(debug || (p->target && p->target->debug)))
1351
+ fprintf(stderr, "apps.plugin: \tchild %d (%s, %s) has parent %d (%s, %s). Parent: utime=%llu, stime=%llu, minflt=%llu, majflt=%llu, cutime=%llu, cstime=%llu, cminflt=%llu, cmajflt=%llu, fix_cutime=%llu, fix_cstime=%llu, fix_cminflt=%llu, fix_cmajflt=%llu\n", p->pid, p->comm, p->updated?"running":"exited", pp->pid, pp->comm, pp->updated?"running":"exited", pp->utime, pp->stime, pp->minflt, pp->majflt, pp->cutime, pp->cstime, pp->cminflt, pp->cmajflt, pp->fix_cutime, pp->fix_cstime, pp->fix_cminflt, pp->fix_cmajflt);
1352
+
1353
if(unlikely(!p->updated)) {
1345
- struct pid_stat *pp = p;
1354
+ // this process has exit
1355
1347
- // find the first parent that
1348
- // has been updated
1349
- while(pp && !pp->updated)
1356
+ // find the first parent that has been updated
1357
+ while(pp && !pp->updated) {
1358
+ // we may have to forward link it to its parent
1359
+ if(unlikely(!pp->parent && pp->ppid > 0 && all_pids[pp->ppid]))
1360
+ pp->parent = all_pids[pp->ppid];
1361
+
1362
+ // check again for parent
1363
pp = pp->parent;
1364
+ }
1365
1366
if(likely(pp)) {
1367
// this is an exited child with a parent
@@ -1358,7 +1372,7 @@ void link_all_processes_to_their_parents(void) {
1372
pp->fix_cstime += p->stime + p->cstime + p->fix_cstime;
1373
1374
if(unlikely(debug))
1361
- fprintf(stderr, "apps.plugin: \tfixing child counters of %d (%s) to %d (%s). Fixes: cutime=%llu, cstime=%llu, cminflt=%llu, cmajflt=%llu\n", p->pid, p->comm, pp->pid, pp->comm, pp->fix_cutime, pp->fix_cstime, pp->fix_cminflt, pp->fix_cmajflt);
1375
+ fprintf(stderr, "apps.plugin: \tupdating child metrics of %d (%s, %s) to its parent %d (%s, %s). Parent has now: utime=%llu, stime=%llu, minflt=%llu, majflt=%llu, cutime=%llu, cstime=%llu, cminflt=%llu, cmajflt=%llu, fix_cutime=%llu, fix_cstime=%llu, fix_cminflt=%llu, fix_cmajflt=%llu\n", p->pid, p->comm, p->updated?"running":"exited", pp->pid, pp->comm, pp->updated?"running":"exited", pp->utime, pp->stime, pp->minflt, pp->majflt, pp->cutime, pp->cstime, pp->cminflt, pp->cmajflt, pp->fix_cutime, pp->fix_cstime, pp->fix_cminflt, pp->fix_cmajflt);
1376
}
1377
}
1378
}