From 1ef1639039b5600510ebcc4f54892e861bb3adb2 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Fri, 16 Jul 2021 17:09:56 -0300 Subject: [PATCH] dwarf_loader: Do not look for non-C DWARF attributes in C CUs Avoid looking for attributes that doesn't apply to the C language, such as DW_AT_virtuality (virtual, pure_virtual), DW_AT_accessibility (public, protected, private) and DW_AT_const_value. Looking for those attributes in class_member__new() makes libdw_find_attr() linearly search all attributes for a die, which appears on profiling. Before: $ perf stat -r5 pahole --btf_encode_detached=vmlinux.btf -j vmlinux Performance counter stats for 'pahole --btf_encode_detached=vmlinux.btf -j vmlinux' (5 runs): 11,239.99 msec task-clock:u # 2.921 CPUs utilized ( +- 0.08% ) 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 793,897 page-faults:u # 70.631 K/sec ( +- 0.00% ) 34,593,518,484 cycles:u # 3.078 GHz ( +- 0.05% ) 75,592,805,563 instructions:u # 2.19 insn per cycle ( +- 0.00% ) 17,923,046,622 branches:u # 1.595 G/sec ( +- 0.00% ) 131,080,371 branch-misses:u # 0.73% of all branches ( +- 0.18% ) 3.84794 +- 0.00327 seconds time elapsed ( +- 0.09% ) $ After: $ perf stat -r5 pahole --btf_encode_detached=vmlinux.btf -j vmlinux Performance counter stats for 'pahole --btf_encode_detached=vmlinux.btf -j vmlinux' (5 runs): 11,178.28 msec task-clock:u # 2.929 CPUs utilized ( +- 0.12% ) 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 793,890 page-faults:u # 71.021 K/sec ( +- 0.00% ) 34,378,886,265 cycles:u # 3.076 GHz ( +- 0.13% ) 75,523,849,140 instructions:u # 2.20 insn per cycle ( +- 0.12% ) 17,907,573,910 branches:u # 1.602 G/sec ( +- 0.12% ) 130,137,529 branch-misses:u # 0.73% of all branches ( +- 0.50% ) 3.8165 +- 0.0137 seconds time elapsed ( +- 0.36% ) $ Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index d6f3db4..7f4af98 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -860,7 +860,6 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu, if (member != NULL) { tag__init(&member->tag, cu, die); member->name = attr_string(die, DW_AT_name, conf); - member->const_value = attr_numeric(die, DW_AT_const_value); member->alignment = attr_numeric(die, DW_AT_alignment); Dwarf_Attribute attr; @@ -899,8 +898,12 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu, member->bit_hole = 0; member->bitfield_end = 0; member->visited = 0; - member->accessibility = attr_numeric(die, DW_AT_accessibility); - member->virtuality = attr_numeric(die, DW_AT_virtuality); + + if (!cu__is_c(cu)) { + member->accessibility = attr_numeric(die, DW_AT_accessibility); + member->const_value = attr_numeric(die, DW_AT_const_value); + member->virtuality = attr_numeric(die, DW_AT_virtuality); + } member->hole = 0; }