cleanup file descriptors of killed processes
Costa Tsaousis (ktsaou) committed
May 24, 2014 at 05:22 UTC
6473e347cb9a798f1e5cd9a6c469ff81aaec7c7b
1 file changed
+23
-3
apps_plugin.c
+23
-3
@@ -197,6 +197,8 @@ struct target {
197
struct target *next;
198
} *target_root = NULL, *default_target = NULL;
199
200
+long targets = 0;
201
+
202
// find or create a target
203
// there are targets that are just agregated to other target (the second argument)
204
struct target *get_target(const char *id, struct target *target)
@@ -413,6 +415,8 @@ struct pid_stat {
415
struct pid_stat *next;
416
} *root = NULL, **all_pids;
417
418
+long pids = 0;
419
+
420
struct pid_stat *get_entry(pid_t pid)
421
{
422
if(all_pids[pid]) {
@@ -640,7 +644,9 @@ int update_from_proc(void)
644
struct pid_stat *p = NULL;
645
646
// mark them all as un-updated
647
+ pids = 0;
648
for(p = root; p ; p = p->next) {
649
+ pids++;
650
p->parent = NULL;
651
p->updated = 0;
652
p->childs = 0;
@@ -1066,8 +1072,11 @@ void update_statistics(void)
1072
#endif
1073
1074
// zero all the targets
1075
+ targets = 0;
1076
struct target *w;
1077
for (w = target_root; w ; w = w->next) {
1078
+ targets++;
1079
+
1080
w->fds = calloc(sizeof(int), all_files_len);
1081
if(!w->fds)
1082
fprintf(stderr, "apps.plugin: ERROR: cannot allocate memory for fds in %s\n", w->name);
@@ -1104,7 +1113,7 @@ void update_statistics(void)
1113
#ifdef INCLUDE_CHILDS
1114
if(debug) walk_down(0, 1);
1115
#endif
1107
-
1116
+
1117
// concentrate everything on the targets
1118
for(p = root; p ; p = p->next) {
1119
if(!p->target) {
@@ -1203,10 +1212,15 @@ void update_statistics(void)
1212
1213
// fprintf(stderr, "\n");
1214
// cleanup all un-updated processed (exited, killed, etc)
1206
- for(p = root, c = 0; p ; c++) {
1215
+ for(p = root; p ;) {
1216
if(!p->updated) {
1217
// fprintf(stderr, "\tEXITED %d %s [parent %d %s, target %s] utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->pid, p->comm, p->parent->pid, p->parent->comm, p->target->name, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
1218
1219
+ for(c = 0 ; c < p->fds_size ; c++) if(p->fds[c] > 0) {
1220
+ file_descriptor_not_used(p->fds[c]);
1221
+ p->fds[c] = 0;
1222
+ }
1223
+
1224
pid_t r = p->pid;
1225
p = p->next;
1226
del_entry(r);
@@ -1435,6 +1449,9 @@ void show_dimensions(void)
1449
1450
fprintf(stdout, "BEGIN netdata.apps_files %llu\n", usec);
1451
fprintf(stdout, "SET files = %llu\n", file_counter);
1452
+ fprintf(stdout, "SET pids = %ld\n", pids);
1453
+ fprintf(stdout, "SET fds = %d\n", all_files_len);
1454
+ fprintf(stdout, "SET targets = %ld\n", targets);
1455
fprintf(stdout, "END\n");
1456
1457
fflush(stdout);
@@ -1570,8 +1587,11 @@ void show_charts(void)
1587
fprintf(stdout, "DIMENSION user '' incremental 1 1000\n");
1588
fprintf(stdout, "DIMENSION system '' incremental 1 1000\n");
1589
1573
- fprintf(stdout, "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' netdata none line 10001 %d\n", update_every);
1590
+ fprintf(stdout, "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' netdata netdata line 10001 %d\n", update_every);
1591
fprintf(stdout, "DIMENSION files '' incremental-no-interpolation 1 1\n");
1592
+ fprintf(stdout, "DIMENSION pids '' absolute-no-interpolation 1 1\n");
1593
+ fprintf(stdout, "DIMENSION fds '' absolute-no-interpolation 1 1\n");
1594
+ fprintf(stdout, "DIMENSION targets '' absolute-no-interpolation 1 1\n");
1595
1596
fflush(stdout);
1597
}