diff --git a/src/common.c b/src/common.c index 19e4d27..74055e9 100644 --- a/src/common.c +++ b/src/common.c @@ -126,3 +126,78 @@ perf_measure_cpu_fixed(perf_rate_func f, int iterations) { return iterations / measure_cpu_time(f, iterations); } + +void +print_table_header(bool csv, char* column_1, char* column_2, char* column_3, char* column_4) +{ + if (csv) { + printf(" %3s, %-51s, %8s, %5s\n", column_1, column_2, column_3, column_4); + } else { // Markdown + printf("\n| %3s | %-51s | %8s | %5s |\n", column_1, column_2, column_3, column_4); + printf("| --: | --------------------------------------------------- | -------: | -----: |\n"); + } +} + +void +print_table_row(bool csv, bool color, unsigned int number, const char* name, uint64_t result, const char* ratio_color, double ratio) +{ + if (csv) + printf(" %3u, %-51s, %s%8"PRIu64"%s, %s%5.1f%%%s\n", + number, + name, + color ? COLOR_CYAN : "", + result, + color ? COLOR_RESET : "", + color ? ratio_color : "", + ratio, + color ? COLOR_RESET : ""); + else + printf("| %3u | %-51s | %s%8"PRIu64"%s | %s%5.1f%%%s |\n", + number, + name, + color ? COLOR_CYAN : "", + result, + color ? COLOR_RESET : "", + color ? ratio_color : "", + ratio, + color ? COLOR_RESET : ""); + return; +} + +void +print_table_row_unsupported(bool csv, bool color, unsigned int number, const char* name, const char* driver_name) +{ + if (csv) + printf(" %3u, %-51s, %s%8s%s, %ssmh %s%s\n", + number, + name, + color ? COLOR_YELLOW : "", + "Unsupported", + color ? COLOR_RESET : "", + color ? COLOR_YELLOW : "", + driver_name, + color ? COLOR_RESET : ""); + else + printf("| %3u | %-51s | %s%8s%s | %ssmh %s%s |\n", + number, + name, + color ? COLOR_YELLOW : "", + "Unsupported", + color ? COLOR_RESET : "", + color ? COLOR_YELLOW : "", + driver_name, + color ? COLOR_RESET : ""); + return; +} + +void +print_warning(bool csv, bool color, char* warning) +{ + if (csv) + fprintf(stderr, " !!!, %s%-51s%s, !!!!!!!!, !!!!!!\n", + COLOR_YELLOW, warning, COLOR_RESET); + else + fprintf(stderr, "| !!! | %s%-51s%s | !!!!!!!! | !!!!!! |\n", + COLOR_YELLOW, warning, COLOR_RESET); +} + diff --git a/src/common.h b/src/common.h index 5f22bc8..30cc82b 100644 --- a/src/common.h +++ b/src/common.h @@ -22,6 +22,14 @@ #ifndef COMMON_H #define COMMON_H +#include + +#define COLOR_RESET "\033[0m" +#define COLOR_RED "\033[31m" +#define COLOR_GREEN "\033[1;32m" +#define COLOR_YELLOW "\033[1;33m" +#define COLOR_CYAN "\033[1;36m" + typedef void (*perf_rate_func)(unsigned count); double @@ -33,5 +41,17 @@ perf_measure_cpu_fixed(perf_rate_func f, int iterations); double perf_measure_gpu_rate(perf_rate_func f, double minDuration); +void +print_table_header(bool csv, char* column_1, char* column_2, char* column_3, char* column_4); + +void +print_table_row(bool csv, bool color, unsigned int number, const char* name, uint64_t result, const char* ratio_color, double ratio); + +void +print_table_row_unsupported(bool csv, bool color, unsigned int number, const char* name, const char* driver_name); + +void +print_warning(bool csv, bool color, char* warning); + #endif /* COMMON_H */ diff --git a/src/vkoverhead.c b/src/vkoverhead.c index 2293bde..06df099 100644 --- a/src/vkoverhead.c +++ b/src/vkoverhead.c @@ -247,6 +247,7 @@ static double duration = 1.0; static int fixed_iteration_count = 0; static int test_no = -1; static int start_no = -1; +static bool csv = false; static bool color = true; static bool submit_only = false; static bool draw_only = false; @@ -2690,12 +2691,6 @@ setup(void) init_dyn_att(&dyn_att_multirt[i]); } -#define COLOR_RESET "\033[0m" -#define COLOR_RED "\033[31m" -#define COLOR_GREEN "\033[1;32m" -#define COLOR_YELLOW "\033[1;33m" -#define COLOR_CYAN "\033[1;36m" - static void setup_submit(void) { @@ -2804,8 +2799,7 @@ perf_run(unsigned case_idx, double base_rate, double duration) if (strstr(p->name, "zerovram")) { if (!fixed_iteration_count) { /* these tests can't naturally terminate themselves */ - fprintf(stderr, "| --- | %szerovram tests must be used with -fixed%s | -------- | ------ |\n", - COLOR_YELLOW, COLOR_RESET); + print_warning(csv, color, "zerovram tests must be used with -fixed"); unsupported = true; } else { is_zerovram = true; @@ -2853,29 +2847,12 @@ perf_run(unsigned case_idx, double base_rate, double duration) name[i] = 0; break; } - printf("| %3u | %s %s | %s%8"PRIu64"%s | %s%sunsupported (smh %s)%s |\n", - case_idx, p->name, - space, - color ? COLOR_CYAN : "", - r, - color ? COLOR_RESET : "", - "", - color ? ratio_color : "", - name, - color ? COLOR_RESET : ""); + print_table_row_unsupported(csv, color, case_idx, p->name, name); } else { if (output_only) printf("%5"PRIu64"\n", r); else - printf("| %3u | %s %s | %s%8"PRIu64"%s | %s%5.1f%%%s |\n", - case_idx, p->name, - space, - color ? COLOR_CYAN : "", - r, - color ? COLOR_RESET : "", - color ? ratio_color : "", - 100 * ratio, - color ? COLOR_RESET : ""); + print_table_row(csv, color, case_idx, p->name, r, ratio_color, 100 * ratio); } return rate; } @@ -2965,6 +2942,8 @@ parse_args(int argc, const char **argv) if (argv[i][0] != '-') continue; const char *arg = &argv[i][1]; + if (!strcmp(arg, "csv")) + csv = true; if (!strcmp(arg, "test")) next_arg_is_test_no = true; if (!strcmp(arg, "start")) @@ -2996,7 +2975,7 @@ parse_args(int argc, const char **argv) printf(" %3u, %s\n", i + (unsigned)(ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit) + ARRAY_SIZE(cases_descriptor)), cases_misc[i].name); exit(0); } else if (!strcmp(arg, "help") || !strcmp(arg, "h")) { - fprintf(stderr, "vkoverhead [-list] [-test/start TESTNUM] [-duration SECONDS] [-nocolor] [-output-only] [-draw-only] [-submit-only] [-descriptor-only] [-misc-only] [-fixed ITERATIONS]\n"); + fprintf(stderr, "vkoverhead [-list] [-test/start TESTNUM] [-duration SECONDS] [-nocolor] [-output-only] [-draw-only] [-submit-only] [-descriptor-only] [-misc-only] [-fixed ITERATIONS] [-csv]\n"); exit(0); } } @@ -3249,8 +3228,7 @@ main(int argc, char *argv[]) } /* be conservative: require only half of total vram */ if (avail_vram < vram_size / 2) { - fprintf(stderr, "| --- | %sDisabling zerovam tests: half of total vram required%s | -------- | ------ |\n", - COLOR_YELLOW, COLOR_RESET); + print_warning(csv, color, "Disabling zerovam tests: half of total vram required"); dev->info.have_EXT_memory_budget = false; } } @@ -3317,21 +3295,18 @@ main(int argc, char *argv[]) MAX2((int)strlen(dev->info.driver_props.driverInfo), 11), dev->info.driver_props.driverInfo ); } - if (!submit_only && !descriptor_only && !misc_only && !output_only && start_no < (int)ARRAY_SIZE(cases_draw)) - printf("\n| # | Draw Tests | Kop/s | %% relative to 'draw' |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + if (!submit_only && !descriptor_only && !misc_only && !output_only && start_no < (int)ARRAY_SIZE(cases_draw)) { + print_table_header(csv, "#", "Draw Tests", "1000op/s", "% relative to 'draw'"); + } double base_rate = 0; if (test_no > -1) { if (!output_only) { if (!draw_only && !descriptor_only && !misc_only) - printf("\n| # | Submit Tests | op/s | %% |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Submit Tests", "op/s", "% relative to 'submit_noop"); if (!draw_only && !submit_only && !descriptor_only) - printf("\n| # | Descriptor Tests | Kop/s | %% |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Descriptor Tests", "1000op/s", "% relative to 'descriptor_noop'"); if (!draw_only && !submit_only && !misc_only) - printf("\n| # | Misc Tests | Kop/s (besides zerovram) | %% (ignore) |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Misc Tests", "1000op/s (besides zerovram)", "% (ignore)"); } perf_run(test_no, base_rate, duration); } else { @@ -3345,8 +3320,7 @@ main(int argc, char *argv[]) } if (!draw_only && !descriptor_only && !misc_only && start_no < (int)(ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit))) { if (!output_only) - printf("\n| # | Submit Tests | op/s | %% relative to 'submit_noop' |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Submit Tests", "op/s", "% relative to 'submit_noop"); base_rate = perf_run(ARRAY_SIZE(cases_draw), 0, duration); unsigned start = start_no == -1 ? 1 : (start_no - ARRAY_SIZE(cases_draw)); for (unsigned i = start; i < ARRAY_SIZE(cases_submit); i++) @@ -3361,8 +3335,7 @@ main(int argc, char *argv[]) } if (!draw_only && !submit_only && !misc_only && start_no < (int)(ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit) + ARRAY_SIZE(cases_descriptor))) { if (!output_only) - printf("\n| # | Descriptor Tests | Kop/s | %% relative to 'descriptor_noop' |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Descriptor Tests", "1000op/s", "% relative to 'descriptor_noop'"); base_rate = perf_run(ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit), 0, duration); unsigned start = start_no == -1 ? 1 : (start_no - (ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit))); for (unsigned i = start; i < ARRAY_SIZE(cases_descriptor); i++) @@ -3372,8 +3345,7 @@ main(int argc, char *argv[]) } if (!draw_only && !submit_only && !descriptor_only) { if (!output_only) - printf("\n| # | Misc Tests | Kop/s (besides zerovram) | %% (ignore) |\n" - "| --: | --------------------------------------------------- | -------: | -----: |\n"); + print_table_header(csv, "#", "Misc Tests", "1000op/s (besides zerovram)", "% (ignore)"); base_rate = 0; unsigned start = start_no == -1 ? 1 : (start_no - (ARRAY_SIZE(cases_draw) + ARRAY_SIZE(cases_submit) + ARRAY_SIZE(cases_descriptor))); for (unsigned i = start; i < ARRAY_SIZE(cases_misc); i++) @@ -3383,6 +3355,6 @@ main(int argc, char *argv[]) } } - printf("\n"); + printf("\n"); return 0; }