int tmstats(Options* inOptions) /* ** As quick as possible, load the input file and report stats. */ { int retval = 0; tmreader* tmr = NULL; TMStats stats; memset(&stats, 0, sizeof(stats)); stats.mOptions = inOptions; stats.uMinTicks = 0xFFFFFFFFU; /* ** Need a tmreader. */ tmr = tmreader_new(inOptions->mProgramName, &stats); if(NULL != tmr) { int tmResult = 0; tmResult = tmreader_eventloop(tmr, inOptions->mInputName, tmEventHandler); if(0 == tmResult) { retval = __LINE__; ERROR_REPORT(retval, inOptions->mInputName, "Problem reading trace-malloc data."); } tmreader_destroy(tmr); tmr = NULL; if(0 == retval) { retval = report_stats(inOptions, &stats); } } else { retval = __LINE__; ERROR_REPORT(retval, inOptions->mProgramName, "Unable to obtain tmreader."); } return retval; }
int main(int argc, char **argv) { int i, j, rv; tmreader *tmr; FILE *fp; time_t start; handler_data data; program = *argv; handler_data_init(&data); tmr = tmreader_new(program, &data); if (!tmr) { perror(program); exit(1); } start = time(NULL); fprintf(stdout, "%s starting at %s", program, ctime(&start)); fflush(stdout); argc -= optind; argv += optind; if (argc == 0) { if (tmreader_eventloop(tmr, "-", my_tmevent_handler) <= 0) exit(1); } else { for (i = j = 0; i < argc; i++) { fp = fopen(argv[i], "r"); if (!fp) { fprintf(stderr, "%s: can't open %s: %s\n", program, argv[i], strerror(errno)); exit(1); } rv = tmreader_eventloop(tmr, argv[i], my_tmevent_handler); if (rv < 0) exit(1); if (rv > 0) j++; fclose(fp); } if (j == 0) exit(1); } if (!data.finished) { fprintf(stderr, "%s: log file incomplete\n", program); exit(1); } fprintf(stdout, "Leaks: %u bytes, %u allocations\n" "Maximum Heap Size: %u bytes\n" "%u bytes were allocated in %u allocations.\n", data.current_heapsize, data.current_allocations, data.max_heapsize, data.bytes_allocated, data.total_allocations); if (data.unmatched_frees != 0) fprintf(stdout, "Logged %u free (or realloc) calls for which we missed the " "original malloc.\n", data.unmatched_frees); handler_data_finish(&data); tmreader_destroy(tmr); exit(0); }