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; }
int main(int argc, char **argv) { int opt, sprofdiff = 0; #ifdef DEBUG /* disable buffering so the output mixes correctly */ setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); #endif /* parse arguments */ while ((opt = getopt(argc, argv, "b:dp:s:")) != -1) { switch (opt) { case 'b': /* additional binary specified */ binary_add(optarg); break; case 'd': /* generate output for sprofdiff */ sprofdiff = 1; break; case 'p': /* minimum percentage specified */ minimum_perc = atof(optarg); if (minimum_perc < 0 || minimum_perc > 100) { fprintf(stderr, "error: cut-off percentage " "makes no sense: %g\n", minimum_perc); exit(1); } break; case 's': /* source tree directory specified */ src_path = optarg; break; default: usage(argv[0]); } } /* load samples */ if (optind >= argc) usage(argv[0]); for (; optind < argc; optind++) { struct endpoint_info *e; load_trace(argv[optind]); for(e = endpoints; e; e = e->next) e->seen = 0; } /* print report */ if (sprofdiff) { print_diff(); } else { print_report(); } return 0; }
/* Example main function that invokes mymalloc and myfree. */ int main(int argc, char *argv[]) { pthread_t threads[MAX_THREADS]; long tid; int err = 0; struct timeval start, end; double diff; FILE *fp; if(argc != 2) { printf("Usage: %s trace_file\n", argv[0]); exit(1); } if((fp = fopen(argv[1], "r")) == NULL) { perror("Trace file open:"); exit(1); } int num_threads = load_trace(fp); if (pthread_mutex_init(&mywait, NULL)) { fprintf(stderr, "Error: mutex initialization failed.\n"); return 1; } // start_heap = sbrk(0); mm_init(); gettimeofday(&start, NULL); for (tid = 0; tid < num_threads; tid++) { err = pthread_create(&threads[tid], NULL, dowork, (void *)tid); if (err) { fprintf(stderr, "Error: pthread_create failed on dowork thread %li.\n", tid); return 1; } } for (tid = 0; tid < num_threads; tid++) { err = pthread_join(threads[tid], NULL); if(err) { fprintf(stderr, "Error: pthread_join failed on thread %li.\n", tid); } } gettimeofday(&end, NULL); diff = 1000000 *(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec); fprintf(stdout, "Time: %dus\n", (int)diff); fprintf(stdout, "Max heap extent: %ld\n", (long int)(max_heap - start_heap)); return 0; }
void run_test(int nargs, char* args[]) { if (nargs < 2) { return; } struct timespec start, end; char* dbname = args[1]; drop_buffer_cache(); trace_loader_t loader; load_trace(&loader, args[2], atoi(args[3])); struct MetaDB mdb; metadb_init(&mdb, dbname); enable_monitor_thread(&mdb); clock_gettime(CLOCK_MONOTONIC, &start); get_metric(); if (strcmp(args[4], "create") == 0) { run_create(mdb, &loader, atoi(args[5])); } else { run_query(mdb, &loader, atoi(args[5]), atoi(args[6]), atoi(args[7])); } clock_gettime(CLOCK_MONOTONIC, &end); disable_monitor_thread(); metadb_close(mdb); get_metric(); uint64_t timeElapsed = timespecDiff(&end, &start); timeElapsed = timespecDiff(&end, &start); printf("%s.%d %d %.1f \n", args[4], num_test, (int) time(NULL), timeElapsed/1.0); destroy_trace_loader(&loader); drop_buffer_cache(); }
/* Simple test for malloc and free. We will want a proper test driver */ int main(int argc, char **argv) { int opt; int pr = 0; struct sigaction newact; /* fill in newact */ newact.sa_handler = handle_seg; newact.sa_flags = 0; sigaction(SIGSEGV, &newact, NULL); while ((opt = getopt(argc, argv, "p")) != -1) { switch (opt) { case 'p': pr = 1; break; default: /* '?' */ fprintf(stderr, "Usage: %s [-p ] tracefile\n", argv[0]); exit(EXIT_FAILURE); } } if(optind >= argc) { fprintf(stderr, "Usage: %s [-p ] tracefile\n", argv[0]); exit(EXIT_FAILURE); } char *tracefile = argv[optind]; mem_init(SIZE); char *ptrs[MAXOPS]; int i; /* Call my malloc 4 times */ //ptrs[i] = smalloc(num_bytes); //write_to_mem(num_bytes, ptrs[i], i); FILE *fp = fopen(tracefile, "r"); if(!fp) { fprintf(stderr, "Usage: driver [-p] <tracefile>\n"); exit(1); } load_trace(fp); fclose(fp); for(i = 0; i < num_ops; i++) { switch(trace[i].type) { case 'm': ptrs[trace[i].index] = smalloc(trace[i].size); if(pr) { printf("smalloc block %d addr %p size %d\n", trace[i].index, ptrs[trace[i].index], trace[i].size); } if(!ptrs[trace[i].index]) { fprintf(stderr, "Error: smalloc returned NULL index=%d, size=%d\n", trace[i].index, trace[i].size); } // check for valid pointer if((ptrs[trace[i].index] < (char *)mem) || (ptrs[trace[i].index] + trace[i].size) > ((char *)mem + SIZE)) { fprintf(stderr, "Error: malloc block %d addr %p size %d heap overflow\n", trace[i].index, ptrs[trace[i].index], trace[i].size); } else { write_to_mem(trace[i].size, ptrs[trace[i].index],trace[i].index); } break; case 'f': if(pr) { printf("sfree block %d addr %p\n", trace[i].index, ptrs[trace[i].index]); } if(sfree(ptrs[trace[i].index])) { fprintf(stderr, "Error: free block %d addr %p\n", trace[i].index, ptrs[trace[i].index]); } break; default : fprintf(stderr, "ERROR: bad type of instruction %c for block %d\n", trace[i].type, trace[i].index); } } if(pr) { printf("Total free mem: %d\n", total_space(freelist)); printf("Total allocated mem: %d\n", total_space(allocated_list)); printf("List of allocated blocks:\n"); print_allocated(); printf("List of free blocks:\n"); print_free(); printf("Contents of allocated memory:\n"); print_mem(); } else { printf("Total free mem: %d\n", total_space(freelist)); printf("Total allocated mem: %d\n", total_space(allocated_list)); printf("Number of allocated blocks: %d\n", num_blocks(allocated_list)); } mem_clean(); return 0; }
// Example main function that invokes mymalloc and myfree int main(int argc, char *argv[]) { // Parse arguments and open trace file FILE *fp; char option; int err; while ((option = getopt(argc, argv, "f:dt")) != -1) { switch (option) { case 'f': if ((fp = fopen(optarg, "r")) == NULL) { perror("Trace file open:"); } break; case 'd': debug = 1; break; case 't': touch_memory = 1; break; default: usage(argv); } } if (fp == NULL) { usage(argv); } // Load the trace int num_threads = load_trace(fp); // Remember heap starting position start_heap = sbrk(0); // Call heap initialization function err = mymalloc_init(); if (err) { fprintf(stderr, "Error: mymalloc_init failed"); return 1; } // Start needed number of threads to replay the trace; measure time pthread_t threads[MAX_THREADS]; long tid; struct timeval start, end; gettimeofday(&start, NULL); for (tid = 0; tid < num_threads; tid++) { err = pthread_create(&threads[tid], NULL, dowork, (void *)tid); if (err) { fprintf(stderr, "Error: pthread_create failed on thread %li.\n", tid); return 1; } } // Wait for all the threads to finish for (tid = 0; tid < num_threads; tid++) { err = pthread_join(threads[tid], NULL); if (err) { fprintf(stderr, "Error: pthread_join failed on thread %li.\n", tid); } } gettimeofday(&end, NULL); // Output execution time and max heap size double diff = 1000000 *(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec); fprintf(stdout, "Time: %f\n", diff); fprintf(stdout, "Max heap extent: %ld\n", max_heap - start_heap); return 0; }