int main(int argc, char** argv) { if (argc != 2) { fprintf(stderr, "Expected one argument. Got %d.\n", argc); fprintf(stderr, "Usage: inspect-gui <trace file>\n"); return EXIT_FAILURE; } trace_t* trace = load_trace(argv[1]); trace_error_t error = get_trace_error(); if (error == TraceError_Invalid) { fprintf(stderr, "Invalid trace file: %s\n", get_trace_error_desc()); return EXIT_FAILURE; } else if (error == TraceError_UnableToOpen) { fprintf(stderr, "Unable to open trace file.\n"); return EXIT_FAILURE; } inspection_t* inspection = create_inspection(trace); inspect(inspection); inspector_t* inspector = create_inspector(inspection); for (size_t i = 0; i < inspection->frame_count; i++) for (size_t j = 0; j < inspection->frames[i].command_count; j++) seek_inspector(inspector, i, j); free_inspector(inspector); free_inspection(inspection); free_trace(trace); return EXIT_SUCCESS; }
int main(int argc, char** argv) { if (argc != 2) { fprintf(stderr, "Expected one argument. Got %d.\n", argc); fprintf(stderr, "Usage: inspect-gui <trace file>\n"); return EXIT_FAILURE; } trace_t* trace = load_trace(argv[1]); trace_error_t error = get_trace_error(); if (error == TraceError_Invalid) { fprintf(stderr, "Invalid trace file: %s\n", get_trace_error_desc()); return EXIT_FAILURE; } else if (error == TraceError_UnableToOpen) { fprintf(stderr, "Unable to open trace file.\n"); return EXIT_FAILURE; } inspection_t* inspection = create_inspection(trace); inspect(inspection); free_inspection(inspection); free_trace(trace); return EXIT_SUCCESS; }
/************** * Main routine **************/ int main(int argc, char **argv) { int i; char c; char **tracefiles = NULL; /* null-terminated array of trace file names */ int num_tracefiles = 0; /* the number of traces in that array */ trace_t *trace = NULL; /* stores a single trace file in memory */ range_t *ranges = NULL; /* keeps track of block extents for one trace */ stats_t *libc_stats = NULL;/* libc stats for each trace */ stats_t *mm_stats = NULL; /* mm (i.e. student) stats for each trace */ speed_t speed_params; /* input parameters to the xx_speed routines */ int run_libc = 0; /* If set, run libc malloc (set by -l) */ int autograder = 0; /* If set, emit summary info for autograder (-g) */ /* temporaries used to compute the performance index */ double secs, ops, util, avg_mm_util, avg_mm_throughput, p1, p2, perfindex; int numcorrect; /* * Read and interpret the command line arguments */ while ((c = getopt(argc, argv, "f:t:hvVgal")) != EOF) { switch (c) { case 'g': /* Generate summary info for the autograder */ autograder = 1; break; case 'f': /* Use one specific trace file only (relative to curr dir) */ num_tracefiles = 1; if ((tracefiles = realloc(tracefiles, 2*sizeof(char *))) == NULL) unix_error("ERROR: realloc failed in main"); strcpy(tracedir, "./"); tracefiles[0] = strdup(optarg); tracefiles[1] = NULL; break; case 't': /* Directory where the traces are located */ if (num_tracefiles == 1) /* ignore if -f already encountered */ break; strcpy(tracedir, optarg); if (tracedir[strlen(tracedir)-1] != '/') strcat(tracedir, "/"); /* path always ends with "/" */ break; case 'l': /* Run libc malloc */ run_libc = 1; break; case 'v': /* Print per-trace performance breakdown */ verbose = 1; break; case 'V': /* Be more verbose than -v */ verbose = 2; break; case 'h': /* Print this message */ usage(); exit(0); default: usage(); exit(1); } } /* * If no -f command line arg, then use the entire set of tracefiles * defined in default_traces[] */ if (tracefiles == NULL) { tracefiles = default_tracefiles; num_tracefiles = sizeof(default_tracefiles) / sizeof(char *) - 1; printf("Using default tracefiles in %s\n", tracedir); } /* Initialize the timing package */ init_fsecs(); /* * Optionally run and evaluate the libc malloc package */ if (run_libc) { if (verbose > 1) printf("\nTesting libc malloc\n"); /* Allocate libc stats array, with one stats_t struct per tracefile */ libc_stats = (stats_t *)calloc(num_tracefiles, sizeof(stats_t)); if (libc_stats == NULL) unix_error("libc_stats calloc in main failed"); /* Evaluate the libc malloc package using the K-best scheme */ for (i=0; i < num_tracefiles; i++) { trace = read_trace(tracedir, tracefiles[i]); libc_stats[i].ops = trace->num_ops; if (verbose > 1) printf("Checking libc malloc for correctness, "); libc_stats[i].valid = eval_libc_valid(trace, i); if (libc_stats[i].valid) { speed_params.trace = trace; if (verbose > 1) printf("and performance.\n"); libc_stats[i].secs = fsecs(eval_libc_speed, &speed_params); } free_trace(trace); } /* Display the libc results in a compact table */ if (verbose) { printf("\nResults for libc malloc:\n"); printresults(num_tracefiles, libc_stats); } } /* * Always run and evaluate the student's mm package */ if (verbose > 1) printf("\nTesting mm malloc\n"); /* Allocate the mm stats array, with one stats_t struct per tracefile */ mm_stats = (stats_t *)calloc(num_tracefiles, sizeof(stats_t)); if (mm_stats == NULL) unix_error("mm_stats calloc in main failed"); /* Initialize the simulated memory system in memlib.c */ mem_init(); /* Evaluate student's mm malloc package using the K-best scheme */ for (i=0; i < num_tracefiles; i++) { trace = read_trace(tracedir, tracefiles[i]); strncpy(mm_stats[i].trace_name, trace->trace_name, 1024); mm_stats[i].ops = trace->num_ops; if (verbose > 1) printf("Checking mm_malloc for correctness, "); mm_stats[i].valid = eval_mm_valid(trace, i, &ranges); if (mm_stats[i].valid) { if (verbose > 1) printf("efficiency, "); mm_stats[i].util = eval_mm_util(trace, i, &ranges); speed_params.trace = trace; speed_params.ranges = ranges; if (verbose > 1) printf("and performance.\n"); mm_stats[i].secs = fsecs(eval_mm_speed, &speed_params); } free_trace(trace); } /* Display the mm results in a compact table */ if (verbose) { printf("\nResults for mm malloc:\n"); printresults(num_tracefiles, mm_stats); printf("\n"); } /* * Accumulate the aggregate statistics for the student's mm package */ secs = 0; ops = 0; util = 0; numcorrect = 0; for (i=0; i < num_tracefiles; i++) { secs += mm_stats[i].secs; ops += mm_stats[i].ops; util += mm_stats[i].util; if (mm_stats[i].valid) numcorrect++; } avg_mm_util = util/num_tracefiles; /* * Compute and print the performance index */ if (errors == 0) { avg_mm_throughput = ops/secs; p1 = UTIL_WEIGHT * avg_mm_util; if (avg_mm_throughput > AVG_LIBC_THRUPUT) { p2 = (double)(1.0 - UTIL_WEIGHT); } else { p2 = ((double) (1.0 - UTIL_WEIGHT)) * (avg_mm_throughput/AVG_LIBC_THRUPUT); } perfindex = (p1 + p2)*100.0; printf("Perf index = %.0f (util) + %.0f (thru) = %.0f/100\n", p1*100, p2*100, perfindex); } else { /* There were errors */ perfindex = 0.0; printf("Terminated with %d errors\n", errors); } if (autograder) { printf("correct:%d\n", numcorrect); printf("perfidx:%.0f\n", perfindex); } exit(0); }