minor fixes
Costa Tsaousis (ktsaou) committed
Mar 30, 2015 at 00:15 UTC
2b2bbe5cfa7c2df549b487bfc96cd4e7ac2a2d71
1 file changed
+31
-29
src/plugins.d/apps_plugin.c
+31
-29
@@ -52,17 +52,17 @@ struct allocations {
52
size_t allocated_max;
53
} allocations = { 0, 0, 0 };
54
55
-#define MALLOC_MARK (size_t)(0x0BADCAFE)
56
-#define MALLOC_PREFIX (sizeof(size_t) * 2)
57
-#define MALLOC_SUFFIX (sizeof(size_t))
55
+#define MALLOC_MARK (uint32_t)(0x0BADCAFE)
56
+#define MALLOC_PREFIX (sizeof(uint32_t) * 2)
57
+#define MALLOC_SUFFIX (sizeof(uint32_t))
58
#define MALLOC_OVERHEAD (MALLOC_PREFIX + MALLOC_SUFFIX)
59
60
void *mark_allocation(void *allocated_ptr, size_t size_without_overheads) {
61
- size_t *real_ptr = (size_t *)allocated_ptr;
61
+ uint32_t *real_ptr = (uint32_t *)allocated_ptr;
62
real_ptr[0] = MALLOC_MARK;
63
real_ptr[1] = size_without_overheads;
64
65
- size_t *end_ptr = (size_t *)(allocated_ptr + MALLOC_PREFIX + size_without_overheads);
65
+ uint32_t *end_ptr = (uint32_t *)(allocated_ptr + MALLOC_PREFIX + size_without_overheads);
66
end_ptr[0] = MALLOC_MARK;
67
68
// fprintf(stderr, "MEMORY_POINTER: Allocated at %p, returning %p.\n", allocated_ptr, (void *)(allocated_ptr + MALLOC_PREFIX));
@@ -71,7 +71,7 @@ void *mark_allocation(void *allocated_ptr, size_t size_without_overheads) {
71
}
72
73
void *check_allocation(const char *file, int line, const char *function, void *marked_ptr, size_t *size_without_overheads_ptr) {
74
- size_t *real_ptr = (size_t *)(marked_ptr - MALLOC_PREFIX);
74
+ uint32_t *real_ptr = (uint32_t *)(marked_ptr - MALLOC_PREFIX);
75
76
// fprintf(stderr, "MEMORY_POINTER: Checking pointer at %p, real %p for %s/%u@%s.\n", marked_ptr, (void *)(marked_ptr - MALLOC_PREFIX), function, line, file);
77
@@ -79,7 +79,7 @@ void *check_allocation(const char *file, int line, const char *function, void *m
79
80
size_t size = real_ptr[1];
81
82
- size_t *end_ptr = (size_t *)(marked_ptr + size);
82
+ uint32_t *end_ptr = (uint32_t *)(marked_ptr + size);
83
if(end_ptr[0] != MALLOC_MARK) fatal("MEMORY: suffix MARK of allocation with size %zu is not valid for %s/%u@%s.", size, function, line, file);
84
85
if(size_without_overheads_ptr) *size_without_overheads_ptr = size;
@@ -552,11 +552,11 @@ struct pid_stat {
552
struct pid_stat *parent;
553
struct pid_stat *prev;
554
struct pid_stat *next;
555
-} *root = NULL, **all_pids;
555
+} *root_of_pids = NULL, **all_pids;
556
557
-long pids = 0;
557
+long all_pids_count = 0;
558
559
-struct pid_stat *get_entry(pid_t pid)
559
+struct pid_stat *get_pid_entry(pid_t pid)
560
{
561
if(all_pids[pid]) {
562
all_pids[pid]->new_entry = 0;
@@ -574,22 +574,22 @@ struct pid_stat *get_entry(pid_t pid)
574
error("apps.plugin: ERROR: Cannot allocate %ld bytes of memory", (unsigned long)(sizeof(int) * 100));
575
else all_pids[pid]->fds_size = 100;
576
577
- if(root) root->prev = all_pids[pid];
578
- all_pids[pid]->next = root;
579
- root = all_pids[pid];
577
+ if(root_of_pids) root_of_pids->prev = all_pids[pid];
578
+ all_pids[pid]->next = root_of_pids;
579
+ root_of_pids = all_pids[pid];
580
581
all_pids[pid]->new_entry = 1;
582
583
return all_pids[pid];
584
}
585
586
-void del_entry(pid_t pid)
586
+void del_pid_entry(pid_t pid)
587
{
588
if(!all_pids[pid]) return;
589
590
if(debug) fprintf(stderr, "apps.plugin: process %d %s exited, deleting it.\n", pid, all_pids[pid]->comm);
591
592
- if(root == all_pids[pid]) root = all_pids[pid]->next;
592
+ if(root_of_pids == all_pids[pid]) root_of_pids = all_pids[pid]->next;
593
if(all_pids[pid]->next) all_pids[pid]->next->prev = all_pids[pid]->prev;
594
if(all_pids[pid]->prev) all_pids[pid]->prev->next = all_pids[pid]->next;
595
@@ -598,6 +598,8 @@ void del_entry(pid_t pid)
598
all_pids[pid] = NULL;
599
}
600
601
+// ----------------------------------------------------------------------------
602
+
603
#ifdef INCLUDE_CHILDS
604
// print a tree view of all processes
605
int walk_down(pid_t pid, int level) {
@@ -610,7 +612,7 @@ int walk_down(pid_t pid, int level) {
612
b[level+1] = '-';
613
b[level+2] = '\0';
614
613
- for(p = root; p ; p = p->next) {
615
+ for(p = root_of_pids; p ; p = p->next) {
616
if(p->ppid == pid) {
617
ret += walk_down(p->pid, level+1);
618
}
@@ -870,9 +872,9 @@ int update_from_proc(void)
872
struct pid_stat *p = NULL;
873
874
// mark them all as un-updated
873
- pids = 0;
874
- for(p = root; p ; p = p->next) {
875
- pids++;
875
+ all_pids_count = 0;
876
+ for(p = root_of_pids; p ; p = p->next) {
877
+ all_pids_count++;
878
p->parent = NULL;
879
p->updated = 0;
880
p->childs = 0;
@@ -913,7 +915,7 @@ int update_from_proc(void)
915
buffer[bytes] = '\0';
916
if(debug) fprintf(stderr, "apps.plugin: READ stat: %s", buffer);
917
916
- p = get_entry(pid);
918
+ p = get_pid_entry(pid);
919
if(!p) continue;
920
921
int parsed = sscanf(buffer,
@@ -1173,7 +1175,7 @@ void update_statistics(void)
1175
struct pid_stat *p = NULL;
1176
1177
// link all parents and update childs count
1176
- for(p = root; p ; p = p->next) {
1178
+ for(p = root_of_pids; p ; p = p->next) {
1179
if(p->ppid > 0 && p->ppid <= pid_max && all_pids[p->ppid]) {
1180
if(debug || (p->target && p->target->debug)) fprintf(stderr, "apps.plugin: \tparent of %d %s is %d %s\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm);
1181
@@ -1188,7 +1190,7 @@ void update_statistics(void)
1190
int found = 1;
1191
while(found) {
1192
found = 0;
1191
- for(p = root; p ; p = p->next) {
1193
+ for(p = root_of_pids; p ; p = p->next) {
1194
// if this process does not have any childs, and
1195
// is not already merged, and
1196
// its parent has childs waiting to be merged, and
@@ -1215,7 +1217,7 @@ void update_statistics(void)
1217
// init goes always to default target
1218
if(all_pids[1]) all_pids[1]->target = default_target;
1219
1218
- for(p = root; p ; p = p->next) {
1220
+ for(p = root_of_pids; p ; p = p->next) {
1221
// if the process is not merged itself
1222
// then is is a top level process
1223
if(!p->merged && !p->target) p->target = default_target;
@@ -1234,7 +1236,7 @@ void update_statistics(void)
1236
found = 1;
1237
while(found) {
1238
found = 0;
1237
- for(p = root; p ; p = p->next) {
1239
+ for(p = root_of_pids; p ; p = p->next) {
1240
if(!p->target && p->merged && p->parent && p->parent->target) {
1241
p->target = p->parent->target;
1242
found++;
@@ -1245,7 +1247,7 @@ void update_statistics(void)
1247
#ifdef INCLUDE_CHILDS
1248
// for each killed process, remove its values from the parents
1249
// sums (we had already added them in a previous loop)
1248
- for(p = root; p ; p = p->next) {
1250
+ for(p = root_of_pids; p ; p = p->next) {
1251
if(p->updated) continue;
1252
1253
if(debug) fprintf(stderr, "apps.plugin: UNMERGING %d %s\n", p->pid, p->comm);
@@ -1341,7 +1343,7 @@ void update_statistics(void)
1343
#endif
1344
1345
// concentrate everything on the targets
1344
- for(p = root; p ; p = p->next) {
1346
+ for(p = root_of_pids; p ; p = p->next) {
1347
if(!p->target) {
1348
error("apps.plugin: ERROR: pid %d %s was left without a target!", p->pid, p->comm);
1349
continue;
@@ -1438,7 +1440,7 @@ void update_statistics(void)
1440
1441
// fprintf(stderr, "\n");
1442
// cleanup all un-updated processed (exited, killed, etc)
1441
- for(p = root; p ;) {
1443
+ for(p = root_of_pids; p ;) {
1444
if(!p->updated) {
1445
// 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);
1446
@@ -1449,7 +1451,7 @@ void update_statistics(void)
1451
1452
pid_t r = p->pid;
1453
p = p->next;
1452
- del_entry(r);
1454
+ del_pid_entry(r);
1455
}
1456
else p = p->next;
1457
}
@@ -1675,7 +1677,7 @@ void show_dimensions(void)
1677
1678
fprintf(stdout, "BEGIN netdata.apps_files %llu\n", usec);
1679
fprintf(stdout, "SET files = %llu\n", file_counter);
1678
- fprintf(stdout, "SET pids = %ld\n", pids);
1680
+ fprintf(stdout, "SET pids = %ld\n", all_pids_count);
1681
fprintf(stdout, "SET fds = %d\n", all_files_len);
1682
fprintf(stdout, "SET targets = %ld\n", targets);
1683
fprintf(stdout, "END\n");