diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2024-02-09 16:13:27 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2024-02-09 16:21:46 -0300 |
commit | 85bdd96404efca198ff441ab73513a6b3bb3a4e0 (patch) | |
tree | dff4f05af4e3ea7ebbd3c1408438f05136b9c83b | |
parent | 08fc8e3285733ec8f4e76656a11b1e9dcc412de1 (diff) | |
download | pahole-85bdd96404efca198ff441ab73513a6b3bb3a4e0.tar.gz |
fprintf: Print number of holes in class member types
In addition to paddings, a hole/unused space at the end, inform about
holes in the middle of the structs of non-pointer members.
For instance, for 'struct task_struct' in the Linux kernel we get this
extra info:
--- task_struct.before.c 2024-02-09 11:38:39.249638750 -0300
+++ task_struct.after.c 2024-02-09 16:19:34.221134835 -0300
@@ -29,6 +29,9 @@
/* --- cacheline 2 boundary (128 bytes) --- */
struct sched_entity se; /* 128 256 */
+
+ /* XXX last struct has 3 holes */
+
/* --- cacheline 6 boundary (384 bytes) --- */
struct sched_rt_entity rt; /* 384 48 */
struct sched_dl_entity dl; /* 432 224 */
@@ -100,6 +103,9 @@
/* --- cacheline 35 boundary (2240 bytes) was 16 bytes ago --- */
struct list_head tasks; /* 2256 16 */
struct plist_node pushable_tasks; /* 2272 40 */
+
+ /* XXX last struct has 1 hole */
+
/* --- cacheline 36 boundary (2304 bytes) was 8 bytes ago --- */
struct rb_node pushable_dl_tasks; /* 2312 24 */
struct mm_struct * mm; /* 2336 8 */
@@ -172,6 +178,9 @@
/* XXX last struct has 4 bytes of padding */
struct vtime vtime; /* 2744 48 */
+
+ /* XXX last struct has 1 hole */
+
/* --- cacheline 43 boundary (2752 bytes) was 40 bytes ago --- */
atomic_t tick_dep_mask; /* 2792 4 */
@@ -396,9 +405,12 @@
/* --- cacheline 145 boundary (9280 bytes) --- */
struct thread_struct thread __attribute__((__aligned__(64))); /* 9280 4416 */
+ /* XXX last struct has 1 hole */
+
/* size: 13696, cachelines: 214, members: 262 */
/* sum members: 13518, holes: 21, sum holes: 162 */
/* sum bitfield members: 82 bits, bit holes: 2, sum bit holes: 46 bits */
+ /* member types with holes: 4, total of those holes: 6 */
/* paddings: 6, sum paddings: 49 */
/* forced alignments: 2, forced holes: 2, sum forced holes: 88 */
};
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | dwarves_fprintf.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 6ba0e9fc..1169d359 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -1464,6 +1464,8 @@ out: struct member_types_holes { uint16_t nr_paddings; + uint16_t nr_with_holes; + uint16_t total_nr_holes; uint32_t sum_paddings; }; @@ -1473,6 +1475,8 @@ static size_t class__fprintf_member_type_holes(struct class *class, const struct { size_t printed = 0; uint16_t padding; + uint8_t nr_holes; + bool first = true; /* * We may not yet have looked for holes and paddings in this member's * struct type. @@ -1481,7 +1485,9 @@ static size_t class__fprintf_member_type_holes(struct class *class, const struct class__infer_packed_attributes(class, cu); padding = class->padding; - if (!padding) + nr_holes = class->nr_holes; + + if (!padding && !nr_holes) return 0; if (!(*newline)++) { @@ -1496,6 +1502,14 @@ static size_t class__fprintf_member_type_holes(struct class *class, const struct holes->sum_paddings += padding; printed += fprintf(fp, " %d byte%s of padding", padding, padding != 1 ? "s" : ""); + first = false; + } + + if (nr_holes) { + ++holes->nr_with_holes; + holes->total_nr_holes += nr_holes; + + printed += fprintf(fp, "%s %d hole%s", first ? "" : ",", nr_holes, nr_holes != 1 ? "s" : ""); } return printed + fprintf(fp, " */"); @@ -1859,6 +1873,11 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu, printed += fprintf(fp, "%.*s/* padding: %u */\n", cconf.indent, tabs, class->padding); + if (member_types_holes.nr_with_holes > 0) { + printed += fprintf(fp, "%.*s/* member types with holes: %u, total of those holes: %u */\n", + cconf.indent, tabs, + member_types_holes.nr_with_holes, member_types_holes.total_nr_holes); + } if (member_types_holes.nr_paddings > 0) printed += fprintf(fp, "%.*s/* paddings: %u, sum paddings: " "%u */\n", |