X-Git-Url: https://git.cworth.org/git?p=fips;a=blobdiff_plain;f=metrics.c;h=9c2e080860d44ae75b1f19dd64367c586b984c7a;hp=6704572533a41b901fa93cf481d731c23f408707;hb=HEAD;hpb=b0e640a505171550746af20e940076c579a0e638 diff --git a/metrics.c b/metrics.c index 6704572..9c2e080 100644 --- a/metrics.c +++ b/metrics.c @@ -153,22 +153,26 @@ metrics_fini (metrics_t *metrics) metrics->timer_head = NULL; metrics->timer_tail = NULL; - if (metrics->monitor_begun_id) { - glEndPerfMonitorAMD (metrics->monitor_begun_id); - glDeletePerfMonitorsAMD (1, &metrics->monitor_begun_id); - metrics->monitor_begun_id = 0; - } + if (metrics->info->have_perfmon) { + + if (metrics->monitor_begun_id) { + glEndPerfMonitorAMD (metrics->monitor_begun_id); + glDeletePerfMonitorsAMD (1, &metrics->monitor_begun_id); + metrics->monitor_begun_id = 0; + } + + for (monitor = metrics->monitor_head; + monitor; + monitor = monitor_next) + { + glDeletePerfMonitorsAMD (1, &monitor->id); + monitor_next = monitor->next; + free (monitor); + } + metrics->monitor_head = NULL; + metrics->monitor_tail = NULL; - for (monitor = metrics->monitor_head; - monitor; - monitor = monitor_next) - { - glDeletePerfMonitorsAMD (1, &monitor->id); - monitor_next = monitor->next; - free (monitor); } - metrics->monitor_head = NULL; - metrics->monitor_tail = NULL; metrics->monitors_in_flight = 0; } @@ -231,9 +235,18 @@ metrics_counter_start (metrics_t *metrics) { unsigned i; - /* Initialize the timer_query and monitor objects */ + /* Initialize the timer_query object. */ glGenQueries (1, &metrics->timer_begun_id); + /* Most everything else in this function is + * performance-monitor related. If we don't have that + * extension, just start the timer query and be done. */ + if (! metrics->info->have_perfmon) { + glBeginQuery (GL_TIME_ELAPSED, metrics->timer_begun_id); + return; + } + + /* Initialize the performance-monitor object */ glGenPerfMonitorsAMD (1, &metrics->monitor_begun_id); for (i = 0; i < metrics->info->num_groups; i++) @@ -273,7 +286,9 @@ metrics_counter_stop (metrics_t *metrics) /* Stop the current timer and monitor. */ glEndQuery (GL_TIME_ELAPSED); - glEndPerfMonitorAMD (metrics->monitor_begun_id); + + if (metrics->info->have_perfmon) + glEndPerfMonitorAMD (metrics->monitor_begun_id); /* Add these IDs to our lists of outstanding queries and * monitors so the results can be collected later. */ @@ -291,19 +306,21 @@ metrics_counter_stop (metrics_t *metrics) metrics->timer_head = timer; } - /* Create a new performance-monitor query */ - monitor = xmalloc (sizeof (monitor_t)); + if (metrics->info->have_perfmon) { + /* Create a new performance-monitor query */ + monitor = xmalloc (sizeof (monitor_t)); - monitor->op = metrics->op; - monitor->id = metrics->monitor_begun_id; - monitor->next = NULL; + monitor->op = metrics->op; + monitor->id = metrics->monitor_begun_id; + monitor->next = NULL; - if (metrics->monitor_tail) { - metrics->monitor_tail->next = monitor; - metrics->monitor_tail = monitor; - } else { - metrics->monitor_tail = monitor; - metrics->monitor_head = monitor; + if (metrics->monitor_tail) { + metrics->monitor_tail->next = monitor; + metrics->monitor_tail = monitor; + } else { + metrics->monitor_tail = monitor; + metrics->monitor_head = monitor; + } } metrics->monitors_in_flight++; @@ -388,7 +405,7 @@ accumulate_program_metrics (metrics_t *metrics, metrics_op_t op, GLuint group_id, group_index; GLuint counter_id, counter_index; metrics_group_info_t *group; - double value; + double value = 0.0; unsigned i; CONSUME (group_id); @@ -579,7 +596,10 @@ print_program_metrics (metrics_t *metrics) /* Make a sorted list of the per-stage operations by time * used, and figure out the total so we can print percentages. */ - num_sorted = metrics->num_op_metrics * num_shader_stages; + if (num_shader_stages) + num_sorted = metrics->num_op_metrics * num_shader_stages; + else + num_sorted = metrics->num_op_metrics; sorted = xmalloc (sizeof (*sorted) * num_sorted); @@ -595,6 +615,14 @@ print_program_metrics (metrics_t *metrics) /* Also, find total cycles in all stages of this op. */ op_cycles = 0.0; + if (num_shader_stages == 0) { + per_stage = &sorted[i]; + per_stage->metrics = op; + per_stage->stage = NULL; + per_stage->time_ns = op->time_ns; + per_stage->active = 0.0; + } + for (j = 0; j < num_shader_stages; j++) { /* Active cycles */ group_index = info->stages[j].active_group_index; @@ -689,6 +717,9 @@ metrics_collect_available (metrics_t *metrics) timer = metrics->timer_head; } + if (! metrics->info->have_perfmon) + return; + /* And similarly for all performance monitors that are ready. */ monitor_t *monitor = metrics->monitor_head; @@ -733,6 +764,12 @@ metrics_collect_available (metrics_t *metrics) } } +static void +metrics_exit (void) +{ + if (verbose) + printf ("fips: terminating\n"); +} void metrics_end_frame (metrics_t *metrics) @@ -742,6 +779,7 @@ metrics_end_frame (metrics_t *metrics) if (! initialized) { gettimeofday (&tv_start, NULL); + atexit (metrics_exit); if (getenv ("FIPS_VERBOSE")) verbose = 1; initialized = 1;