Skip to content

Commit

Permalink
Improve logging (closes #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arinerron committed Oct 20, 2021
1 parent 8484eac commit ad6b9c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ int start_process(HeaptraceContext *ctx) {


void start_debugger(HeaptraceContext *ctx) {
log(COLOR_LOG "================================ " COLOR_LOG_BOLD "BEGIN HEAPTRACE" COLOR_LOG " ===============================\n" COLOR_RESET);
log(COLOR_LOG "================================ " COLOR_LOG_BOLD "BEGIN HEAPTRACE" COLOR_LOG " ===============================\n\n" COLOR_RESET);

if (OPT_ATTACH_PID) {
ctx->pid = OPT_ATTACH_PID;
Expand Down Expand Up @@ -639,9 +639,8 @@ void start_debugger(HeaptraceContext *ctx) {
}

if (show_banner) {
log(COLOR_LOG "================================================================================\n" COLOR_RESET);
log(COLOR_LOG "\n================================================================================\n" COLOR_RESET);
}
log("\n");

}

Expand Down
22 changes: 12 additions & 10 deletions src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ uint64_t get_oid(HeaptraceContext *ctx) {
void show_stats(HeaptraceContext *ctx) {
uint64_t unfreed_sum = count_unfreed_bytes(ctx->chunk_root);

if (unfreed_sum && OPT_VERBOSE) log(COLOR_LOG "------\n");
log(COLOR_LOG "Statistics:\n");
log("... mallocs count: " CNT "\n", ctx->malloc_count);
log("... callocs count: " CNT "\n", ctx->calloc_count);
log("... frees count: " CNT "\n", ctx->free_count);
log("... reallocs count: " CNT "\n", ctx->realloc_count);
log("... reallocarrays count: " CNT "\n" COLOR_RESET, ctx->reallocarray_count);
if (get_oid(ctx) || unfreed_sum) {
if (unfreed_sum && OPT_VERBOSE) log(COLOR_LOG "------\n");
log(COLOR_LOG "Statistics:\n");
if (ctx->malloc_count) log("... mallocs count: " CNT "\n", ctx->malloc_count);
if (ctx->calloc_count) log("... callocs count: " CNT "\n", ctx->calloc_count);
if (ctx->free_count) log("... frees count: " CNT "\n", ctx->free_count);
if (ctx->realloc_count) log("... reallocs count: " CNT "\n", ctx->realloc_count);
if (ctx->reallocarray_count) log("... reallocarrays count: " CNT "\n" COLOR_RESET, ctx->reallocarray_count);

if (unfreed_sum) {
log(COLOR_ERROR "... unfreed bytes: " SZ_ERR "\n", SZ_ARG(unfreed_sum));
if (unfreed_sum) {
log(COLOR_ERROR "... unfreed bytes: " SZ_ERR "\n", SZ_ARG(unfreed_sum));
}
}

log("%s", COLOR_RESET);
log(COLOR_RESET);
}
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int parse_args(int argc, char *argv[]) {

if (!OPT_ATTACH_PID && optind == argc) {
fatal("you must specify a binary to execute.\n");
show_help(argv);
log(COLOR_WARN "hint: run `%s --help` to see the help menu.\n" COLOR_RESET, argv[0]);
exit(1);
}

Expand Down

0 comments on commit ad6b9c7

Please # to comment.