From: Marcin Ślusarz Date: Wed, 10 Jun 2020 13:58:59 +0000 (+0200) Subject: intel/perf: export performance counters sorted by [group|set] and name X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a777b25350cce0a97243405fa129eca386aecda2;p=mesa.git intel/perf: export performance counters sorted by [group|set] and name It's a lot easier to deal with them in RenderDoc when they are in some meaningful order. Signed-off-by: Marcin Ślusarz Reviewed-by: Lionel Landwerlin Part-of: --- diff --git a/src/intel/perf/gen_perf.c b/src/intel/perf/gen_perf.c index 4f95b0a84af..ba1b4f8b127 100644 --- a/src/intel/perf/gen_perf.c +++ b/src/intel/perf/gen_perf.c @@ -476,6 +476,22 @@ get_register_queries_function(const struct gen_device_info *devinfo) return NULL; } +static int +gen_perf_compare_counter_names(const void *v1, const void *v2) +{ + const struct gen_perf_query_counter *c1 = v1; + const struct gen_perf_query_counter *c2 = v2; + + return strcmp(c1->name, c2->name); +} + +static void +sort_query(struct gen_perf_query_info *q) +{ + qsort(q->counters, q->n_counters, sizeof(q->counters[0]), + gen_perf_compare_counter_names); +} + static void load_pipeline_statistic_metrics(struct gen_perf_config *perf_cfg, const struct gen_device_info *devinfo) @@ -560,6 +576,8 @@ load_pipeline_statistic_metrics(struct gen_perf_config *perf_cfg, } query->data_size = sizeof(uint64_t) * query->n_counters; + + sort_query(query); } static int @@ -591,11 +609,31 @@ i915_get_sseu(int drm_fd, struct drm_i915_gem_context_param_sseu *sseu) gen_ioctl(drm_fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &arg); } +static inline int +compare_str_or_null(const char *s1, const char *s2) +{ + if (s1 == NULL && s2 == NULL) + return 0; + if (s1 == NULL) + return -1; + if (s2 == NULL) + return 1; + + return strcmp(s1, s2); +} + static int -compare_counters(const void *_c1, const void *_c2) +compare_counter_categories_and_names(const void *_c1, const void *_c2) { - const struct gen_perf_query_counter_info *c1 = _c1, *c2 = _c2; - return strcmp(c1->counter->symbol_name, c2->counter->symbol_name); + const struct gen_perf_query_counter_info *c1 = (const struct gen_perf_query_counter_info *)_c1; + const struct gen_perf_query_counter_info *c2 = (const struct gen_perf_query_counter_info *)_c2; + + /* pipeline counters don't have an assigned category */ + int r = compare_str_or_null(c1->counter->category, c2->counter->category); + if (r) + return r; + + return strcmp(c1->counter->name, c2->counter->name); } static void @@ -658,7 +696,7 @@ build_unique_counter_list(struct gen_perf_config *perf) sizeof(counter_infos[0]), perf->n_counters); qsort(perf->counter_infos, perf->n_counters, sizeof(perf->counter_infos[0]), - compare_counters); + compare_counter_categories_and_names); } static bool @@ -707,6 +745,8 @@ static void load_oa_metrics(struct gen_perf_config *perf, int fd, const struct gen_device_info *devinfo) { + int existing_queries = perf->n_queries; + perf_register_oa_queries_t oa_register = get_register_queries_function(devinfo); perf->oa_metrics_table = @@ -726,6 +766,10 @@ load_oa_metrics(struct gen_perf_config *perf, int fd, } else { add_all_metrics(perf, devinfo); } + + /* sort counters in each individual group created by this function by name */ + for (int i = existing_queries; i < perf->n_queries; ++i) + sort_query(&perf->queries[i]); } struct gen_perf_registers * @@ -1040,6 +1084,15 @@ gen_perf_query_result_clear(struct gen_perf_query_result *result) result->hw_id = OA_REPORT_INVALID_CTX_ID; /* invalid */ } +static int +gen_perf_compare_query_names(const void *v1, const void *v2) +{ + const struct gen_perf_query_info *q1 = v1; + const struct gen_perf_query_info *q2 = v2; + + return strcmp(q1->name, q2->name); +} + void gen_perf_init_metrics(struct gen_perf_config *perf_cfg, const struct gen_device_info *devinfo, @@ -1051,9 +1104,16 @@ gen_perf_init_metrics(struct gen_perf_config *perf_cfg, gen_perf_register_mdapi_statistic_query(perf_cfg, devinfo); } - if (oa_metrics_available(perf_cfg, drm_fd, devinfo)) { + bool oa_metrics = oa_metrics_available(perf_cfg, drm_fd, devinfo); + if (oa_metrics) load_oa_metrics(perf_cfg, drm_fd, devinfo); - build_unique_counter_list(perf_cfg); + + /* sort query groups by name */ + qsort(perf_cfg->queries, perf_cfg->n_queries, + sizeof(perf_cfg->queries[0]), gen_perf_compare_query_names); + + build_unique_counter_list(perf_cfg); + + if (oa_metrics) gen_perf_register_mdapi_oa_query(perf_cfg, devinfo); - } }