|
74 | 74 | #include <linux/err.h>
|
75 | 75 | #include <linux/filter.h>
|
76 | 76 | #include <linux/kernel.h>
|
| 77 | +#include <linux/list_sort.h> |
77 | 78 | #include <linux/random.h>
|
78 | 79 | #include <linux/stringify.h>
|
79 | 80 | #include <linux/time64.h>
|
@@ -4312,34 +4313,38 @@ static unsigned long thread__nr_events(struct thread_trace *ttrace)
|
4312 | 4313 | return ttrace ? ttrace->nr_events : 0;
|
4313 | 4314 | }
|
4314 | 4315 |
|
4315 |
| -DEFINE_RESORT_RB(threads, |
4316 |
| - (thread__nr_events(thread__priv(a->thread)) < |
4317 |
| - thread__nr_events(thread__priv(b->thread))), |
4318 |
| - struct thread *thread; |
4319 |
| -) |
| 4316 | +static int trace_nr_events_cmp(void *priv __maybe_unused, |
| 4317 | + const struct list_head *la, |
| 4318 | + const struct list_head *lb) |
4320 | 4319 | {
|
4321 |
| - entry->thread = rb_entry(nd, struct thread_rb_node, rb_node)->thread; |
| 4320 | + struct thread_list *a = list_entry(la, struct thread_list, list); |
| 4321 | + struct thread_list *b = list_entry(lb, struct thread_list, list); |
| 4322 | + unsigned long a_nr_events = thread__nr_events(thread__priv(a->thread)); |
| 4323 | + unsigned long b_nr_events = thread__nr_events(thread__priv(b->thread)); |
| 4324 | + |
| 4325 | + if (a_nr_events != b_nr_events) |
| 4326 | + return a_nr_events < b_nr_events ? -1 : 1; |
| 4327 | + |
| 4328 | + /* Identical number of threads, place smaller tids first. */ |
| 4329 | + return thread__tid(a->thread) < thread__tid(b->thread) |
| 4330 | + ? -1 |
| 4331 | + : (thread__tid(a->thread) > thread__tid(b->thread) ? 1 : 0); |
4322 | 4332 | }
|
4323 | 4333 |
|
4324 | 4334 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
|
4325 | 4335 | {
|
4326 | 4336 | size_t printed = trace__fprintf_threads_header(fp);
|
4327 |
| - struct rb_node *nd; |
4328 |
| - int i; |
4329 |
| - |
4330 |
| - for (i = 0; i < THREADS__TABLE_SIZE; i++) { |
4331 |
| - DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i); |
| 4337 | + LIST_HEAD(threads); |
4332 | 4338 |
|
4333 |
| - if (threads == NULL) { |
4334 |
| - fprintf(fp, "%s", "Error sorting output by nr_events!\n"); |
4335 |
| - return 0; |
4336 |
| - } |
| 4339 | + if (machine__thread_list(trace->host, &threads) == 0) { |
| 4340 | + struct thread_list *pos; |
4337 | 4341 |
|
4338 |
| - resort_rb__for_each_entry(nd, threads) |
4339 |
| - printed += trace__fprintf_thread(fp, threads_entry->thread, trace); |
| 4342 | + list_sort(NULL, &threads, trace_nr_events_cmp); |
4340 | 4343 |
|
4341 |
| - resort_rb__delete(threads); |
| 4344 | + list_for_each_entry(pos, &threads, list) |
| 4345 | + printed += trace__fprintf_thread(fp, pos->thread, trace); |
4342 | 4346 | }
|
| 4347 | + thread_list__delete(&threads); |
4343 | 4348 | return printed;
|
4344 | 4349 | }
|
4345 | 4350 |
|
|
0 commit comments