Skip to content

Commit

Permalink
perf_counter: Sleep before refresh using poll in perf top
Browse files Browse the repository at this point in the history
perf top is refreshed every delay_secs the thread runs in such
loop:

while (sleep(delay_secs)) {
	print_sym_table();
}

At the end of print_sym_table(), poll is used without sleep delay
to check if we have something from stdin.

It means that this check is done only every delay_secs, which can
be higher that 2 secs if the user defined a custom refresh rate.

We can drop sleep() here and directly use poll to wait between
refresh periods, so that the reaction after the user stops perf top
after typing "Enter" is immediate and doesn't suffer from the
delay_secs latency.

Nb: poll doesn't add any overhead that can parasite perf top measures
since it sleeps the entire timeout here.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <1244141284-7507-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Jun 4, 2009
1 parent 62fc445 commit 0f5486b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Documentation/perf_counter/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void print_sym_table(void)
list_remove_active_sym(syme);
}

write(1, CONSOLE_CLEAR, strlen(CONSOLE_CLEAR));
puts(CONSOLE_CLEAR);

printf(
"------------------------------------------------------------------------------\n");
Expand Down Expand Up @@ -278,23 +278,21 @@ static void print_sym_table(void)
color_fprintf(stdout, color, "%4.1f%%", pcnt);
printf(" - %016llx : %s\n", sym->start, sym->name);
}

{
struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };

if (poll(&stdin_poll, 1, 0) == 1) {
printf("key pressed - exiting.\n");
exit(0);
}
}
}

static void *display_thread(void *arg)
{
struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
int delay_msecs = delay_secs * 1000;

printf("PerfTop refresh period: %d seconds\n", delay_secs);

while (!sleep(delay_secs))
do {
print_sym_table();
} while (!poll(&stdin_poll, 1, delay_msecs) == 1);

printf("key pressed - exiting.\n");
exit(0);

return NULL;
}
Expand Down

0 comments on commit 0f5486b

Please sign in to comment.