diff options
author | Namhyung Kim <namhyung@kernel.org> | 2024-08-21 09:54:07 +0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2024-08-21 17:29:56 +0300 |
commit | 4a32a97268d304d5708f1212c4a4d0e1dd3246dd (patch) | |
tree | 602bc0c2b036b0a43df35d0e08f8a9c8186c7b54 /tools/perf/util/annotate-data.c | |
parent | 922ec313f061cf75157d8e93fe16bc6397f6ea25 (diff) | |
download | linux-4a32a97268d304d5708f1212c4a4d0e1dd3246dd.tar.xz |
perf annotate-data: Prefer struct/union over base type
Sometimes a compound type can have a single field and the size is the
same as the base type. But it's still preferred as struct or union
could carry more information than the base type.
Also put a slight priority on the typedef for the same reason.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240821065408.285548-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate-data.c')
-rw-r--r-- | tools/perf/util/annotate-data.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index e5589268cb42..bc65264084d8 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -404,6 +404,13 @@ static bool is_pointer_type(Dwarf_Die *type_die) return tag == DW_TAG_pointer_type || tag == DW_TAG_array_type; } +static bool is_compound_type(Dwarf_Die *type_die) +{ + int tag = dwarf_tag(type_die); + + return tag == DW_TAG_structure_type || tag == DW_TAG_union_type; +} + /* returns if Type B has better information than Type A */ static bool is_better_type(Dwarf_Die *type_a, Dwarf_Die *type_b) { @@ -433,7 +440,18 @@ static bool is_better_type(Dwarf_Die *type_a, Dwarf_Die *type_b) dwarf_aggregate_size(type_b, &size_b) < 0) return false; - return size_a < size_b; + if (size_a != size_b) + return size_a < size_b; + + /* struct or union is preferred */ + if (is_compound_type(type_a) != is_compound_type(type_b)) + return is_compound_type(type_b); + + /* typedef is preferred */ + if (dwarf_tag(type_b) == DW_TAG_typedef) + return true; + + return false; } /* The type info will be saved in @type_die */ |