]> git.cworth.org Git - fips/blobdiff - metrics.c
Print reports every 15 frames rather than every 60
[fips] / metrics.c
index 71fe82da1b3d5ff06cf6dd94aa541f14f0b38a33..eede09b3729886fcdff33780b416b832130e0c51 100644 (file)
--- a/metrics.c
+++ b/metrics.c
@@ -191,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 {
@@ -265,9 +262,6 @@ metrics_info_init (void)
        GLuint *group_ids;
        metrics_info_t *info = &current_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));
@@ -306,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 = &current_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 *
@@ -508,6 +533,7 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size)
 
        context_t *ctx = &current_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)
@@ -561,7 +587,7 @@ accumulate_program_metrics (metrics_op_t op, GLuint *result, GLuint size)
                        break;
                }
 
-               ctx->op_metrics[op].counters[group_index][counter_index] += value;
+               metrics->counters[group_index][counter_index] += value;
        }
 }
 
@@ -636,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,
@@ -748,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;
+                       }
                }
        }
 
@@ -776,13 +821,14 @@ metrics_exit (void)
        if (verbose)
                printf ("fips: terminating\n");
 
-       metrics_info_fini (&current_context.metrics_info);
+       metrics_info_fini ();
 }
 
 
 void
 metrics_end_frame (void)
 {
+       context_t *ctx = &current_context;
        static int initialized = 0;
        static struct timeval tv_start, tv_now;
 
@@ -798,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;
@@ -813,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;
@@ -853,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 +