Changeset 60029df in mainline
- Timestamp:
- 2019-01-03T09:49:54Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a362c16
- Parents:
- 043d464f
- Location:
- uspace/app/perf
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/perf/Makefile
r043d464f r60029df 35 35 SOURCES = \ 36 36 benchlist.c \ 37 csv.c \ 37 38 perf.c \ 38 39 ipc/ns_ping.c \ -
uspace/app/perf/perf.c
r043d464f r60029df 36 36 37 37 #include <assert.h> 38 #include <getopt.h> 38 39 #include <math.h> 39 40 #include <stdio.h> … … 43 44 #include <time.h> 44 45 #include <errno.h> 46 #include <str_error.h> 45 47 #include <perf.h> 46 48 #include <types/casting.h> 49 #include "benchlist.h" 50 #include "csv.h" 47 51 #include "perf.h" 48 #include "benchlist.h"49 52 50 53 #define MIN_DURATION_SECS 10 … … 55 58 benchmark_t *bench, uint64_t workload_size) 56 59 { 60 csv_report_add_entry(stopwatch, run_index, bench, workload_size); 61 57 62 usec_t duration_usec = NSEC2USEC(stopwatch_get_nanos(stopwatch)); 58 63 … … 282 287 283 288 for (size_t i = 0; i < benchmark_count; i++) 284 printf("%-*s %s\n", (int) len, benchmarks[i]->name, benchmarks[i]->desc); 285 286 printf("%-*s Run all benchmarks\n", (int) len, "*"); 289 printf(" %-*s %s\n", (int) len, benchmarks[i]->name, benchmarks[i]->desc); 290 291 printf(" %-*s Run all benchmarks\n", (int) len, "*"); 292 } 293 294 static void print_usage(const char *progname) 295 { 296 printf("Usage: %s [options] <benchmark>\n", progname); 297 printf("-h, --help " 298 "Print this help and exit\n"); 299 printf("-o, --output filename.csv " 300 "Store machine-readable data in filename.csv\n"); 301 printf("<benchmark> is one of the following:\n"); 302 list_benchmarks(); 287 303 } 288 304 289 305 int main(int argc, char *argv[]) 290 306 { 291 if (argc < 2) { 292 printf("Usage:\n\n"); 293 printf("%s <benchmark>\n\n", argv[0]); 294 list_benchmarks(); 295 return 0; 296 } 297 298 if (str_cmp(argv[1], "*") == 0) { 299 return run_benchmarks(); 300 } 301 302 for (size_t i = 0; i < benchmark_count; i++) { 303 if (str_cmp(argv[1], benchmarks[i]->name) == 0) { 304 return (run_benchmark(benchmarks[i]) ? 0 : -1); 305 } 306 } 307 308 printf("Unknown benchmark \"%s\"\n", argv[1]); 309 return -2; 307 const char *short_options = "ho:"; 308 struct option long_options[] = { 309 { "help", optional_argument, NULL, 'h' }, 310 { "output", required_argument, NULL, 'o' }, 311 { 0, 0, NULL, 0 } 312 }; 313 314 char *csv_output_filename = NULL; 315 316 int opt = 0; 317 while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) { 318 switch (opt) { 319 case 'h': 320 print_usage(*argv); 321 return 0; 322 case 'o': 323 csv_output_filename = optarg; 324 break; 325 case -1: 326 default: 327 break; 328 } 329 } 330 331 if (optind + 1 != argc) { 332 print_usage(*argv); 333 fprintf(stderr, "Error: specify one benchmark to run or * for all.\n"); 334 return -3; 335 } 336 337 const char *benchmark = argv[optind]; 338 339 if (csv_output_filename != NULL) { 340 errno_t rc = csv_report_open(csv_output_filename); 341 if (rc != EOK) { 342 fprintf(stderr, "Failed to open CSV report '%s': %s\n", 343 csv_output_filename, str_error(rc)); 344 return -4; 345 } 346 } 347 348 int exit_code = 0; 349 350 if (str_cmp(benchmark, "*") == 0) { 351 exit_code = run_benchmarks(); 352 } else { 353 bool benchmark_exists = false; 354 for (size_t i = 0; i < benchmark_count; i++) { 355 if (str_cmp(benchmark, benchmarks[i]->name) == 0) { 356 benchmark_exists = true; 357 exit_code = run_benchmark(benchmarks[i]) ? 0 : -1; 358 break; 359 } 360 } 361 if (!benchmark_exists) { 362 printf("Unknown benchmark \"%s\"\n", benchmark); 363 exit_code = -2; 364 } 365 } 366 367 csv_report_close(); 368 369 return exit_code; 310 370 } 311 371
Note:
See TracChangeset
for help on using the changeset viewer.