Skip to content

Commit 5807806

Browse files
committed
perf top tui: Wait till the first sample to refresh the screen.
Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 374cfe5 commit 5807806

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

tools/perf/builtin-top.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static struct perf_top top = {
7272
.target_tid = -1,
7373
.active_symbols = LIST_HEAD_INIT(top.active_symbols),
7474
.active_symbols_lock = PTHREAD_MUTEX_INITIALIZER,
75+
.active_symbols_cond = PTHREAD_COND_INITIALIZER,
7576
.freq = 1000, /* 1 KHz */
7677
};
7778

@@ -577,7 +578,17 @@ static void handle_keypress(struct perf_session *session, int c)
577578

578579
static void *display_thread_tui(void *arg __used)
579580
{
580-
perf_top__tui_browser(&top);
581+
int err = 0;
582+
pthread_mutex_lock(&top.active_symbols_lock);
583+
while (list_empty(&top.active_symbols)) {
584+
err = pthread_cond_wait(&top.active_symbols_cond,
585+
&top.active_symbols_lock);
586+
if (err)
587+
break;
588+
}
589+
pthread_mutex_unlock(&top.active_symbols_lock);
590+
if (!err)
591+
perf_top__tui_browser(&top);
581592
exit_browser(0);
582593
exit(0);
583594
return NULL;
@@ -776,8 +787,14 @@ static void perf_event__process_sample(const union perf_event *event,
776787
syme->count[evsel->idx]++;
777788
record_precise_ip(syme, evsel->idx, ip);
778789
pthread_mutex_lock(&top.active_symbols_lock);
779-
if (list_empty(&syme->node) || !syme->node.next)
790+
if (list_empty(&syme->node) || !syme->node.next) {
791+
static bool first = true;
780792
__list_insert_active_sym(syme);
793+
if (first) {
794+
pthread_cond_broadcast(&top.active_symbols_cond);
795+
first = false;
796+
}
797+
}
781798
pthread_mutex_unlock(&top.active_symbols_lock);
782799
}
783800
}

tools/perf/util/top.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct perf_top {
3535
*/
3636
struct list_head active_symbols;
3737
pthread_mutex_t active_symbols_lock;
38+
pthread_cond_t active_symbols_cond;
3839
u64 samples;
3940
u64 kernel_samples, us_samples;
4041
u64 exact_samples;

0 commit comments

Comments
 (0)