[PATCH 3/3] perf annotate-data: Show first-level children by default in TUI

From: Namhyung Kim
Date: Mon Aug 12 2024 - 15:45:30 EST


Now default is to fold everything but it only shows the name of the
top-level data type which is not very useful. Instead just expand the
top level entry so that it can show the layout at a higher level.

Annotate type: 'struct task_struct' (4 samples)
Percent Offset Size Field
- 100.00 0 9792 struct task_struct { ◆
+ 0.50 0 24 struct thread_info thread_info; ▒
0.00 24 4 unsigned int __state; ▒
0.00 32 8 void* stack; ▒
+ 0.00 40 4 refcount_t usage; ▒
0.00 44 4 unsigned int flags; ▒
0.00 48 4 unsigned int ptrace; ▒
0.00 52 4 int on_cpu; ▒
+ 0.00 56 16 struct __call_single_node wake_entry; ▒
0.00 72 4 unsigned int wakee_flips; ▒
0.00 80 8 long unsigned int wakee_flip_decay_ts;▒
0.00 88 8 struct task_struct* last_wakee; ▒
0.00 96 4 int recent_used_cpu; ▒
0.00 100 4 int wake_cpu; ▒
0.00 104 4 int on_rq; ▒
0.00 108 4 int prio; ▒
0.00 112 4 int static_prio; ▒
0.00 116 4 int normal_prio; ▒
0.00 120 4 unsigned int rt_priority; ▒
+ 0.00 128 256 struct sched_entity se; ▒
+ 0.00 384 48 struct sched_rt_entity rt; ▒
+ 0.00 432 224 struct sched_dl_entity dl; ▒
0.00 656 8 struct sched_class* sched_class; ▒
...

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/ui/browsers/annotate-data.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate-data.c b/tools/perf/ui/browsers/annotate-data.c
index a5c5ad63425e..f563a3bb072c 100644
--- a/tools/perf/ui/browsers/annotate-data.c
+++ b/tools/perf/ui/browsers/annotate-data.c
@@ -596,9 +596,17 @@ int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evsel,
}

ret = annotated_data_browser__collect_entries(&browser);
- if (ret == 0)
- ret = annotated_data_browser__run(&browser, evsel, hbt);
+ if (ret < 0)
+ goto out;

+ /* To get the top and current entry */
+ browser__refresh(&browser.b);
+ /* Show the first-level child entries by default */
+ annotated_data_browser__toggle_fold(&browser, /*recursive=*/false);
+
+ ret = annotated_data_browser__run(&browser, evsel, hbt);
+
+out:
annotated_data_browser__delete_entries(&browser);

return ret;
--
2.46.0.76.ge559c4bf1a-goog