]> git.cworth.org Git - fips/commitdiff
Add a pointer to metrics_info_t from metrics_t
authorCarl Worth <cworth@cworth.org>
Mon, 4 Nov 2013 22:27:31 +0000 (14:27 -0800)
committerCarl Worth <cworth@cworth.org>
Mon, 4 Nov 2013 22:27:31 +0000 (14:27 -0800)
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
metrics.c
metrics.h

index 892c696d8db49891d5438c64cbf4ea5a220d9b19..ccaa96a3bd4c13d20cfa181dbaf3c2c9656cf6d8 100644 (file)
--- 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;
 }
index 0a69e58bd88867b10f081661c34c17f23639d8ad..47df1e0cf4a7071f5186b24c04cf95898da92311 100644 (file)
--- 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;
index 7baa9cb5aeb25cc460c29ec7b782f5d2bf96f4b4..230d668422cc702ee61b8c0da6fe0096e19bf4ce 100644 (file)
--- 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
  *