Skip to content

Commit

Permalink
Add and use new print functions; add CSV support back as a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertychouskie committed Sep 26, 2023
1 parent 5943008 commit 8e8d82e
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 46 deletions.
75 changes: 75 additions & 0 deletions src/common.c
Expand Up @@ -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);
}

20 changes: 20 additions & 0 deletions src/common.h
Expand Up @@ -22,6 +22,14 @@
#ifndef COMMON_H
#define COMMON_H

#include <inttypes.h>

#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
Expand All @@ -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 */

64 changes: 18 additions & 46 deletions src/vkoverhead.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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++)
Expand All @@ -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++)
Expand All @@ -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++)
Expand All @@ -3383,6 +3355,6 @@ main(int argc, char *argv[])
}
}

printf("\n");
printf("\n");
return 0;
}

0 comments on commit 8e8d82e

Please sign in to comment.