diff options
Diffstat (limited to 'malloc/memusagestat.c')
-rw-r--r-- | malloc/memusagestat.c | 346 |
1 files changed, 174 insertions, 172 deletions
diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c index 01af517fd2..8ac7ab91c8 100644 --- a/malloc/memusagestat.c +++ b/malloc/memusagestat.c @@ -53,24 +53,24 @@ /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = { - { "output", 'o', N_("FILE"), 0, N_("Name output file") }, - { "string", 's', N_("STRING"), 0, N_("Title string used in output graphic") }, - { "time", 't', NULL, 0, N_("\ + { "output", 'o', N_ ("FILE"), 0, N_ ("Name output file") }, + { "string", 's', N_ ("STRING"), 0, N_ ("Title string used in output graphic") }, + { "time", 't', NULL, 0, N_ (" \ Generate output linear to time (default is linear to number of function calls)\ ") }, { "total", 'T', NULL, 0, - N_("Also draw graph for total memory consumption") }, - { "x-size", 'x', N_("VALUE"), 0, - N_("Make output graphic VALUE pixels wide") }, - { "y-size", 'y', "VALUE", 0, N_("Make output graphic VALUE pixels high") }, + N_ ("Also draw graph for total memory consumption") }, + { "x-size", 'x', N_ ("VALUE"), 0, + N_ ("Make output graphic VALUE pixels wide") }, + { "y-size", 'y', "VALUE", 0, N_ ("Make output graphic VALUE pixels high") }, { NULL, 0, NULL, 0, NULL } }; /* Short description of program. */ -static const char doc[] = N_("Generate graphic from memory profiling data"); +static const char doc[] = N_ ("Generate graphic from memory profiling data"); /* Strings for arguments in help texts. */ -static const char args_doc[] = N_("DATAFILE [OUTFILE]"); +static const char args_doc[] = N_ ("DATAFILE [OUTFILE]"); /* Prototype for option handler. */ static error_t parse_opt (int key, char *arg, struct argp_state *state); @@ -152,7 +152,7 @@ main (int argc, char *argv[]) if (remaining >= argc || remaining + 2 < argc) { argp_help (&argp, stdout, ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR, - program_invocation_short_name); + program_invocation_short_name); exit (1); } @@ -197,21 +197,21 @@ main (int argc, char *argv[]) if (maxsize_heap == 0 && maxsize_stack == 0) { /* The program aborted before memusage was able to write the - information about the maximum heap and stack use. Repair - the file now. */ + information about the maximum heap and stack use. Repair + the file now. */ struct entry next; while (1) - { - if (read (fd, &next, sizeof (next)) == 0) - break; - if (next.heap > maxsize_heap) - maxsize_heap = next.heap; - if (next.stack > maxsize_stack) - maxsize_stack = next.stack; - if (maxsize_heap + maxsize_stack > maxsize_total) - maxsize_total = maxsize_heap + maxsize_stack; - } + { + if (read (fd, &next, sizeof (next)) == 0) + break; + if (next.heap > maxsize_heap) + maxsize_heap = next.heap; + if (next.stack > maxsize_stack) + maxsize_stack = next.stack; + if (maxsize_heap + maxsize_stack > maxsize_total) + maxsize_total = maxsize_heap + maxsize_stack; + } headent[0].stack = maxsize_total; headent[1].heap = maxsize_heap; @@ -227,7 +227,7 @@ main (int argc, char *argv[]) if (also_total) { /* We use one scale and since we also draw the total amount of - memory used we have to adapt the maximum. */ + memory used we have to adapt the maximum. */ maxsize_heap = maxsize_total; maxsize_stack = maxsize_total; } @@ -292,145 +292,145 @@ main (int argc, char *argv[]) } gdImageString (im_out, gdFontSmall, 38, ysize - 14, (unsigned char *) "0", - blue); + blue); snprintf (buf, sizeof (buf), heap_format, 0); gdImageString (im_out, gdFontSmall, maxsize_heap < 1024 ? 32 : 26, - ysize - 26, (unsigned char *) buf, red); + ysize - 26, (unsigned char *) buf, red); snprintf (buf, sizeof (buf), stack_format, 0); gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26, - (unsigned char *) buf, green); + (unsigned char *) buf, green); if (string != NULL) gdImageString (im_out, gdFontLarge, (xsize - strlen (string) * 8) / 2, - 2, (unsigned char *) string, green); + 2, (unsigned char *) string, green); gdImageStringUp (im_out, gdFontSmall, 1, ysize / 2 - 10, - (unsigned char *) "allocated", red); + (unsigned char *) "allocated", red); gdImageStringUp (im_out, gdFontSmall, 11, ysize / 2 - 10, - (unsigned char *) "memory", red); + (unsigned char *) "memory", red); gdImageStringUp (im_out, gdFontSmall, xsize - 39, ysize / 2 - 10, - (unsigned char *) "used", green); + (unsigned char *) "used", green); gdImageStringUp (im_out, gdFontSmall, xsize - 27, ysize / 2 - 10, - (unsigned char *) "stack", green); + (unsigned char *) "stack", green); snprintf (buf, sizeof (buf), heap_format, maxsize_heap / heap_scale); gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, 14, - (unsigned char *) buf, red); + (unsigned char *) buf, red); snprintf (buf, sizeof (buf), stack_format, maxsize_stack / stack_scale); gdImageString (im_out, gdFontSmall, xsize - 37, 14, - (unsigned char *) buf, green); + (unsigned char *) buf, green); for (line = 1; line <= 3; ++line) { if (maxsize_heap > 0) - { - cnt = (((ysize - 40) * (maxsize_heap / 4 * line / heap_scale)) - / (maxsize_heap / heap_scale)); - gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40, - ysize - 20 - cnt, red); - snprintf (buf, sizeof (buf), heap_format, - maxsize_heap / 4 * line / heap_scale); - gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, - ysize - 26 - cnt, (unsigned char *) buf, red); - } + { + cnt = (((ysize - 40) * (maxsize_heap / 4 * line / heap_scale)) + / (maxsize_heap / heap_scale)); + gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40, + ysize - 20 - cnt, red); + snprintf (buf, sizeof (buf), heap_format, + maxsize_heap / 4 * line / heap_scale); + gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6, + ysize - 26 - cnt, (unsigned char *) buf, red); + } else - cnt = 0; + cnt = 0; if (maxsize_stack > 0) - cnt2 = (((ysize - 40) * (maxsize_stack / 4 * line / stack_scale)) - / (maxsize_stack / stack_scale)); + cnt2 = (((ysize - 40) * (maxsize_stack / 4 * line / stack_scale)) + / (maxsize_stack / stack_scale)); else - cnt2 = 0; + cnt2 = 0; if (cnt != cnt2) - gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40, - ysize - 20 - cnt2, green); + gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40, + ysize - 20 - cnt2, green); snprintf (buf, sizeof (buf), stack_format, maxsize_stack / 4 * line / - stack_scale); + stack_scale); gdImageString (im_out, gdFontSmall, xsize - 37, ysize - 26 - cnt2, - (unsigned char *) buf, green); + (unsigned char *) buf, green); } snprintf (buf, sizeof (buf), "%llu", (unsigned long long) total); gdImageString (im_out, gdFontSmall, xsize - 50, ysize - 14, - (unsigned char *) buf, blue); + (unsigned char *) buf, blue); if (!time_based) { uint64_t previously = start_time; gdImageString (im_out, gdFontSmall, 40 + (xsize - 32 * 6 - 80) / 2, - ysize - 12, - (unsigned char *) "# memory handling function calls", - blue); + ysize - 12, + (unsigned char *) "# memory handling function calls", + blue); last_stack = last_heap = last_total = ysize - 20; for (cnt = 1; cnt <= total; ++cnt) - { - struct entry entry; - size_t new[2]; - uint64_t now; - - read (fd, &entry, sizeof (entry)); - - now = ((uint64_t) entry.time_high) << 32 | entry.time_low; - - if ((((previously - start_time) * 100) / total_time) % 10 < 5) - gdImageFilledRectangle (im_out, - 40 + ((cnt - 1) * (xsize - 80)) / total, - ysize - 19, - 39 + (cnt * (xsize - 80)) / total, - ysize - 14, yellow); - previously = now; - - if (also_total && maxsize_heap > 0) - { - size_t new3; - - new3 = (ysize - 20) - ((((unsigned long long int) (ysize - 40)) - * (entry.heap + entry.stack)) - / maxsize_heap); - gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, - last_total, - 40 + ((xsize - 80) * cnt) / total, new3, - black); - last_total = new3; - } - - if (maxsize_heap > 0) - { - new[0] = ((ysize - 20) - - ((((unsigned long long int) (ysize - 40)) - * entry.heap) / maxsize_heap)); - gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, - last_heap, 40 + ((xsize - 80) * cnt) / total, - new[0], red); - last_heap = new[0]; - } - - if (maxsize_stack > 0) - { - new[1] = ((ysize - 20) - - ((((unsigned long long int) (ysize - 40)) - * entry.stack) / maxsize_stack)); - gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, - last_stack, 40 + ((xsize - 80) * cnt) / total, - new[1], green); - last_stack = new[1]; - } - } + { + struct entry entry; + size_t new[2]; + uint64_t now; + + read (fd, &entry, sizeof (entry)); + + now = ((uint64_t) entry.time_high) << 32 | entry.time_low; + + if ((((previously - start_time) * 100) / total_time) % 10 < 5) + gdImageFilledRectangle (im_out, + 40 + ((cnt - 1) * (xsize - 80)) / total, + ysize - 19, + 39 + (cnt * (xsize - 80)) / total, + ysize - 14, yellow); + previously = now; + + if (also_total && maxsize_heap > 0) + { + size_t new3; + + new3 = (ysize - 20) - ((((unsigned long long int) (ysize - 40)) + * (entry.heap + entry.stack)) + / maxsize_heap); + gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, + last_total, + 40 + ((xsize - 80) * cnt) / total, new3, + black); + last_total = new3; + } + + if (maxsize_heap > 0) + { + new[0] = ((ysize - 20) + - ((((unsigned long long int) (ysize - 40)) + * entry.heap) / maxsize_heap)); + gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, + last_heap, 40 + ((xsize - 80) * cnt) / total, + new[0], red); + last_heap = new[0]; + } + + if (maxsize_stack > 0) + { + new[1] = ((ysize - 20) + - ((((unsigned long long int) (ysize - 40)) + * entry.stack) / maxsize_stack)); + gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total, + last_stack, 40 + ((xsize - 80) * cnt) / total, + new[1], green); + last_stack = new[1]; + } + } cnt = 0; while (cnt < total) - { - gdImageLine (im_out, 40 + ((xsize - 80) * cnt) / total, ysize - 20, - 40 + ((xsize - 80) * cnt) / total, ysize - 15, blue); - cnt += MAX (1, total / 20); - } + { + gdImageLine (im_out, 40 + ((xsize - 80) * cnt) / total, ysize - 20, + 40 + ((xsize - 80) * cnt) / total, ysize - 15, blue); + cnt += MAX (1, total / 20); + } gdImageLine (im_out, xsize - 40, ysize - 20, xsize - 40, ysize - 15, - blue); + blue); } else { @@ -438,67 +438,67 @@ main (int argc, char *argv[]) size_t last_xpos = 40; gdImageString (im_out, gdFontSmall, 40 + (xsize - 39 * 6 - 80) / 2, - ysize - 12, - (unsigned char *) "\ + ysize - 12, + (unsigned char *) " \ # memory handling function calls / time", blue); for (cnt = 0; cnt < 20; cnt += 2) - gdImageFilledRectangle (im_out, - 40 + (cnt * (xsize - 80)) / 20, ysize - 19, - 39 + ((cnt + 1) * (xsize - 80)) / 20, - ysize - 14, yellow); + gdImageFilledRectangle (im_out, + 40 + (cnt * (xsize - 80)) / 20, ysize - 19, + 39 + ((cnt + 1) * (xsize - 80)) / 20, + ysize - 14, yellow); last_stack = last_heap = last_total = ysize - 20; for (cnt = 1; cnt <= total; ++cnt) - { - struct entry entry; - size_t new[2]; - size_t xpos; - uint64_t now; - - read (fd, &entry, sizeof (entry)); - - now = ((uint64_t) entry.time_high) << 32 | entry.time_low; - xpos = 40 + ((xsize - 80) * (now - start_time)) / total_time; - - if (cnt == next_tick) - { - gdImageLine (im_out, xpos, ysize - 20, xpos, ysize - 15, blue); - next_tick += MAX (1, total / 20); - } - - if (also_total && maxsize_heap > 0) - { - size_t new3; - - new3 = (ysize - 20) - ((((unsigned long long int) (ysize - 40)) - * (entry.heap + entry.stack)) - / maxsize_heap); - gdImageLine (im_out, last_xpos, last_total, xpos, new3, black); - last_total = new3; - } - - if (maxsize_heap > 0) - { - new[0] = ((ysize - 20) - - ((((unsigned long long int) (ysize - 40)) - * entry.heap) / maxsize_heap)); - gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red); - last_heap = new[0]; - } - - if (maxsize_stack > 0) - { - new[1] = ((ysize - 20) - - ((((unsigned long long int) (ysize - 40)) - * entry.stack) / maxsize_stack)); - gdImageLine (im_out, last_xpos, last_stack, xpos, new[1], - green); - last_stack = new[1]; - } - - last_xpos = xpos; - } + { + struct entry entry; + size_t new[2]; + size_t xpos; + uint64_t now; + + read (fd, &entry, sizeof (entry)); + + now = ((uint64_t) entry.time_high) << 32 | entry.time_low; + xpos = 40 + ((xsize - 80) * (now - start_time)) / total_time; + + if (cnt == next_tick) + { + gdImageLine (im_out, xpos, ysize - 20, xpos, ysize - 15, blue); + next_tick += MAX (1, total / 20); + } + + if (also_total && maxsize_heap > 0) + { + size_t new3; + + new3 = (ysize - 20) - ((((unsigned long long int) (ysize - 40)) + * (entry.heap + entry.stack)) + / maxsize_heap); + gdImageLine (im_out, last_xpos, last_total, xpos, new3, black); + last_total = new3; + } + + if (maxsize_heap > 0) + { + new[0] = ((ysize - 20) + - ((((unsigned long long int) (ysize - 40)) + * entry.heap) / maxsize_heap)); + gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red); + last_heap = new[0]; + } + + if (maxsize_stack > 0) + { + new[1] = ((ysize - 20) + - ((((unsigned long long int) (ysize - 40)) + * entry.stack) / maxsize_stack)); + gdImageLine (im_out, last_xpos, last_stack, xpos, new[1], + green); + last_stack = new[1]; + } + + last_xpos = xpos; + } } /* Write out the result. */ @@ -537,12 +537,12 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'x': xsize = atoi (arg); if (xsize == 0) - xsize = XSIZE; + xsize = XSIZE; break; case 'y': ysize = atoi (arg); if (ysize == 0) - ysize = XSIZE; + ysize = XSIZE; break; default: return ARGP_ERR_UNKNOWN; @@ -563,8 +563,10 @@ more_help (int key, const char *text, void *input) if (asprintf (&tp, gettext ("\ For bug reporting instructions, please see:\n\ %s.\n"), REPORT_BUGS_TO) < 0) - return NULL; + return NULL; + return tp; + default: break; } |