From 778d86ef913e3c4fa3618232c6f34f0655e92dd2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 4 Nov 2013 14:27:31 -0800 Subject: [PATCH] Add a pointer to metrics_info_t from metrics_t This removes one common use of context_t from the metrics.c code, so we're one step closer to have clean interfaces here, (rather than everybody reaching into a global context_ structure). --- context.c | 2 +- metrics.c | 23 +++++++++++++++-------- metrics.h | 7 +++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/context.c b/context.c index 892c696..ccaa96a 100644 --- a/context.c +++ b/context.c @@ -37,7 +37,7 @@ context_create (fips_api_t api, void *system_context_id) fips_dispatch_init (api); metrics_info_init (&ctx->metrics_info); - ctx->metrics = metrics_create (); + ctx->metrics = metrics_create (&ctx->metrics_info); return ctx; } diff --git a/metrics.c b/metrics.c index 0a69e58..47df1e0 100644 --- a/metrics.c +++ b/metrics.c @@ -69,6 +69,11 @@ typedef struct op_metrics struct metrics { + /* Description of all available peformance counters, counter + * groups, their names and IDs, etc. */ + metrics_info_t *info; + + /* The current operation being measured. */ metrics_op_t op; /* GL_TIME_ELAPSED query for which glEndQuery has not yet @@ -96,12 +101,14 @@ struct metrics }; metrics_t * -metrics_create (void) +metrics_create (metrics_info_t *info) { metrics_t *metrics; metrics = xmalloc (sizeof (metrics_t)); + metrics->info = info; + metrics->op = 0; metrics->timer_begun_id = 0; @@ -231,12 +238,12 @@ metrics_counter_start (void) glGenPerfMonitorsAMD (1, &metrics->monitor_begun_id); - for (i = 0; i < ctx->metrics_info.num_groups; i++) + for (i = 0; i < metrics->info->num_groups; i++) { metrics_group_info_t *group; int num_counters; - group = &ctx->metrics_info.groups[i]; + group = &metrics->info->groups[i]; num_counters = group->num_counters; if (group->max_active_counters < group->num_counters) @@ -335,7 +342,7 @@ metrics_get_current_op (void) static void op_metrics_init (context_t *ctx, op_metrics_t *metrics, metrics_op_t op) { - metrics_info_t *info = &ctx->metrics_info; + metrics_info_t *info = ctx->metrics->info; unsigned i, j; metrics->op = op; @@ -384,7 +391,7 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size) p += sizeof(var); context_t *ctx = context_get_current (); - metrics_info_t *info = &ctx->metrics_info; + metrics_info_t *info = ctx->metrics->info; op_metrics_t *metrics = ctx_get_op_metrics (ctx, op); unsigned char *p = (unsigned char *) result; @@ -494,7 +501,7 @@ print_per_stage_metrics (context_t *ctx, per_stage_metrics_t *per_stage, double total) { - metrics_info_t *info = &ctx->metrics_info; + metrics_info_t *info = ctx->metrics->info; op_metrics_t *metric = per_stage->metrics; metrics_group_info_t *group; const char *op_string; @@ -576,7 +583,7 @@ print_program_metrics (void) { context_t *ctx = context_get_current (); metrics_t *metrics = ctx->metrics; - metrics_info_t *info = &ctx->metrics_info; + metrics_info_t *info = metrics->info; unsigned num_shader_stages = info->num_shader_stages; per_stage_metrics_t *sorted, *per_stage; double total_time, op_cycles; @@ -679,7 +686,7 @@ metrics_exit (void) { context_t *ctx = context_get_current (); metrics_t *metrics = ctx->metrics; - metrics_info_t *info = &ctx->metrics_info; + metrics_info_t *info = metrics->info; unsigned i, j; timer_query_t *timer, *timer_next; monitor_t *monitor, *monitor_next; diff --git a/metrics.h b/metrics.h index 7baa9cb..230d668 100644 --- a/metrics.h +++ b/metrics.h @@ -22,6 +22,8 @@ #ifndef METRICS_H #define METRICS_H +#include "metrics-info.h" + typedef enum { METRICS_OP_ACCUM, @@ -52,9 +54,10 @@ typedef enum typedef struct metrics metrics_t; -/* Create a new metrics_t object for tracking metrics. */ +/* Create a new metrics_t object for tracking metrics, given the + * pre-initialized metrics_info_t* describing available counters. */ metrics_t * -metrics_create (void); +metrics_create (metrics_info_t *info); /* Free all internal resources of a metrics_t * -- 2.43.0