X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=metrics.c;h=eede09b3729886fcdff33780b416b832130e0c51;hb=40729d306204edbc29675e78b5641efe19566dd7;hp=d9dd3a0b3faef6ff600f6a6a487c9f639def47ec;hpb=583e41faf104e7a7ee168761361c8c64aa3c5462;p=fips diff --git a/metrics.c b/metrics.c index d9dd3a0..eede09b 100644 --- a/metrics.c +++ b/metrics.c @@ -163,15 +163,6 @@ metrics_group_info_init (metrics_group_info_t *group, GLuint id) GL_COUNTER_TYPE_AMD, &group->counter_types[i]); - /* We assume that all peformance counters are made - * available as uint32 values. The code calling - * CONSUME in accumulate_program_metrics will need to - * be extended to accomodate other counter values. */ - if (group->counter_types[i] != GL_UNSIGNED_INT) { - fprintf (stderr, "fips: Internal error: No support for non-uint counter values\n"); - exit (1); - } - glGetPerfMonitorCounterStringAMD (group->id, group->counter_ids[i], 0, &length, NULL); @@ -200,9 +191,6 @@ metrics_group_info_fini (metrics_group_info_t *group) free (group->name); } -static void -metrics_info_fini (metrics_info_t *info); - /* A helper function, part of metrics_info_init below. */ typedef enum { @@ -274,9 +262,6 @@ metrics_info_init (void) GLuint *group_ids; metrics_info_t *info = ¤t_context.metrics_info; - if (info->initialized) - metrics_info_fini (info); - glGetPerfMonitorGroupsAMD ((int *) &info->num_groups, 0, NULL); group_ids = xmalloc (info->num_groups * sizeof (GLuint)); @@ -315,20 +300,51 @@ metrics_info_init (void) info->initialized = 1; } -static void -metrics_info_fini (metrics_info_t *info) +void +metrics_info_fini (void) { + context_t *ctx = ¤t_context; + metrics_info_t *info = &ctx->metrics_info; unsigned i; + timer_query_t *timer, *timer_next; + monitor_t *monitor, *monitor_next; + + if (! info->initialized) + return; + + for (timer = ctx->timer_head; + timer; + timer = timer_next) + { + timer_next = timer->next; + free (timer); + } + ctx->timer_head = NULL; + ctx->timer_tail = NULL; + + for (monitor = ctx->monitor_head; + monitor; + monitor = monitor_next) + { + monitor_next = monitor->next; + free (monitor); + } + ctx->monitor_head = NULL; + ctx->monitor_tail = NULL; for (i = 0; i < info->num_groups; i++) metrics_group_info_fini (&info->groups[i]); free (info->groups); + info->groups = NULL; for (i = 0; i < info->num_shader_stages; i++) free (info->stages[i].name); free (info->stages); + info->stages = NULL; + + info->initialized = 0; } static const char * @@ -517,6 +533,7 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size) context_t *ctx = ¤t_context; metrics_info_t *info = &ctx->metrics_info; + op_metrics_t *metrics = ctx_get_op_metrics (ctx, op); unsigned char *p = (unsigned char *) result; while (p < ((unsigned char *) result) + size) @@ -524,12 +541,11 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size) GLuint group_id, group_index; GLuint counter_id, counter_index; metrics_group_info_t *group; - uint32_t value; + double value; unsigned i; CONSUME (group_id); CONSUME (counter_id); - CONSUME (value); for (i = 0; i < info->num_groups; i++) { if (info->groups[i].id == group_id) @@ -546,7 +562,32 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size) counter_index = i; assert (counter_index < group->num_counters); - ctx->op_metrics[op].counters[group_index][counter_index] += value; + switch (group->counter_types[counter_index]) + { + uint uint_value; + uint64_t uint64_value; + float float_value; + case GL_UNSIGNED_INT: + CONSUME (uint_value); + value = uint_value; + break; + case GL_UNSIGNED_INT64_AMD: + CONSUME (uint64_value); + value = uint64_value; + break; + case GL_PERCENTAGE_AMD: + case GL_FLOAT: + CONSUME (float_value); + value = float_value; + break; + default: + fprintf (stderr, "fips: Warning: Unknown counter value type (%d)\n", + group->counter_types[counter_index]); + value = 0.0; + break; + } + + metrics->counters[group_index][counter_index] += value; } } @@ -621,7 +662,11 @@ print_per_stage_metrics (context_t *ctx, printf (" "); } - printf (" %cS:", per_stage->stage->name[0]); + + if (per_stage->stage) + printf (" %cS:", per_stage->stage->name[0]); + else + printf (" :"); printf ("\t%7.2f ms (%4.1f%%)", per_stage->time_ns / 1e6, @@ -733,15 +778,30 @@ print_program_metrics (void) per_stage = &sorted[i * num_shader_stages + j]; per_stage->metrics = op; - per_stage->stage = &info->stages[j]; - if (op_cycles) + + if (op_cycles) { + per_stage->stage = &info->stages[j]; per_stage->time_ns = op->time_ns * (stage_cycles / op_cycles); - else - per_stage->time_ns = 0.0; - if (stage_cycles) + } else { + /* If we don't have any per-stage cycle counts + * for this operation, then use the first + * stage as a placeholder for all the time, + * but NULL-ify the stage info so that the + * report doesn't lie about this time being + * from any particular stage. */ + per_stage->stage = NULL; + if (j == 0) { + per_stage->time_ns = op->time_ns; + } else { + per_stage->time_ns = 0.0; + } + } + + if (stage_cycles) { per_stage->active = active_cycles / stage_cycles; - else + } else { per_stage->active = 0.0; + } } } @@ -761,13 +821,14 @@ metrics_exit (void) if (verbose) printf ("fips: terminating\n"); - metrics_info_fini (¤t_context.metrics_info); + metrics_info_fini (); } void metrics_end_frame (void) { + context_t *ctx = ¤t_context; static int initialized = 0; static struct timeval tv_start, tv_now; @@ -783,7 +844,7 @@ metrics_end_frame (void) gettimeofday (&tv_now, NULL); /* Consume all timer queries that are ready. */ - timer_query_t *timer = current_context.timer_head; + timer_query_t *timer = ctx->timer_head; while (timer) { GLuint available, elapsed; @@ -798,18 +859,18 @@ metrics_end_frame (void) accumulate_program_time (timer->op, elapsed); - current_context.timer_head = timer->next; - if (current_context.timer_head == NULL) - current_context.timer_tail = NULL; + ctx->timer_head = timer->next; + if (ctx->timer_head == NULL) + ctx->timer_tail = NULL; glDeleteQueries (1, &timer->id); free (timer); - timer = current_context.timer_head; + timer = ctx->timer_head; } /* And similarly for all performance monitors that are ready. */ - monitor_t *monitor = current_context.monitor_head; + monitor_t *monitor = ctx->monitor_head; while (monitor) { GLuint available, result_size, *result; @@ -838,17 +899,17 @@ metrics_end_frame (void) free (result); - current_context.monitor_head = monitor->next; - if (current_context.monitor_head == NULL) - current_context.monitor_tail = NULL; + ctx->monitor_head = monitor->next; + if (ctx->monitor_head == NULL) + ctx->monitor_tail = NULL; glDeletePerfMonitorsAMD (1, &monitor->id); free (monitor); - monitor = current_context.monitor_head; + monitor = ctx->monitor_head; } - if (frames % 60 == 0) { + if (frames % 15 == 0) { double fps; fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec +