From 2926b5a9207c28986f449a322761e4103f4c28e7 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 22 Oct 2013 16:30:34 -0700 Subject: [PATCH] Un-nest an inner loop while printing program metrics Before we add more code to complicate the way we print performance counters, it helps to have this code in its own function, (where we can safely use 'i' instead of 'j' for loop-control variable, etc.). --- metrics.c | 71 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/metrics.c b/metrics.c index 1e2e018..64f1dcc 100644 --- a/metrics.c +++ b/metrics.c @@ -391,13 +391,49 @@ time_compare(const void *in_a, const void *in_b, void *arg) return 0; } +static void +print_op_metrics (op_metrics_t *metric, double total) +{ + const char *op_string; + unsigned i; + + /* Since we sparsely fill the array based on program + * id, many "programs" have no time. + */ + if (metric->time_ns == 0.0) + return; + + op_string = metrics_op_string (metric->op); + + printf ("%s", op_string); + if (metric->op >= METRICS_OP_SHADER) { + printf (" %d:", metric->op - METRICS_OP_SHADER); + } else { + printf (":"); + for (i = strlen (op_string); i < 20; i++) + printf (" "); + } + + printf ("\t%7.2f ms (% 2.1f%%)", + metric->time_ns / 1e6, + metric->time_ns / total * 100); + + printf ("["); + for (i = 0; i < metric->num_counters; i++) { + if (metric->counters[i] == 0.0) + continue; + printf ("%d: %.2f ms ", i, metric->counters[i] / 1e6); + } + printf ("]\n"); +} + static void print_program_metrics (void) { context_t *ctx = ¤t_context; int *sorted; /* Sorted indices into the ctx->op_metrics */ double total = 0; - unsigned i, j; + unsigned i; /* Make a sorted list of the operations by time used, and figure * out the total so we can print percentages. @@ -410,37 +446,8 @@ print_program_metrics (void) qsort_r(sorted, ctx->num_op_metrics, sizeof(*sorted), time_compare, ctx->op_metrics); - for (i = 0; i < ctx->num_op_metrics; i++) { - const char *op_string; - op_metrics_t *metric =&ctx->op_metrics[sorted[i]]; - - /* Since we sparsely fill the array based on program - * id, many "programs" have no time. - */ - if (metric->time_ns == 0.0) - continue; - - op_string = metrics_op_string (metric->op); - - printf ("%s", op_string); - if (metric->op >= METRICS_OP_SHADER) { - printf (" %d:", metric->op - METRICS_OP_SHADER); - } else { - printf (":"); - for (j = strlen (op_string); j < 20; j++) - printf (" "); - } - printf ("\t%7.2f ms (% 2.1f%%)", - metric->time_ns / 1e6, - metric->time_ns / total * 100); - printf ("["); - for (j = 0; j < metric->num_counters; j++) { - if (metric->counters[j] == 0.0) - continue; - printf ("%d: %.2f ms ", j, metric->counters[j] / 1e6); - } - printf ("]\n"); - } + for (i = 0; i < ctx->num_op_metrics; i++) + print_op_metrics (&ctx->op_metrics[sorted[i]], total); } /* Called at program exit */ -- 2.43.0