aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/builtin-top.c
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-06-04 14:48:04 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-04 15:44:53 -0400
commit0f5486b5c71a831a713ce356d8d06822e3c7c379 (patch)
tree4c62fd39d7477ac333a954934cad52d300e5a010 /Documentation/perf_counter/builtin-top.c
parent62fc44536c14b5787531bac7417580fca54c88b4 (diff)
perf_counter: Sleep before refresh using poll in perf top
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>
Diffstat (limited to 'Documentation/perf_counter/builtin-top.c')
-rw-r--r--Documentation/perf_counter/builtin-top.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Documentation/perf_counter/builtin-top.c b/Documentation/perf_counter/builtin-top.c
index 31c00ba99b14..28cbde4b6e83 100644
--- a/Documentation/perf_counter/builtin-top.c
+++ b/Documentation/perf_counter/builtin-top.c
@@ -204,7 +204,7 @@ static void print_sym_table(void)
204 list_remove_active_sym(syme); 204 list_remove_active_sym(syme);
205 } 205 }
206 206
207 write(1, CONSOLE_CLEAR, strlen(CONSOLE_CLEAR)); 207 puts(CONSOLE_CLEAR);
208 208
209 printf( 209 printf(
210"------------------------------------------------------------------------------\n"); 210"------------------------------------------------------------------------------\n");
@@ -278,23 +278,21 @@ static void print_sym_table(void)
278 color_fprintf(stdout, color, "%4.1f%%", pcnt); 278 color_fprintf(stdout, color, "%4.1f%%", pcnt);
279 printf(" - %016llx : %s\n", sym->start, sym->name); 279 printf(" - %016llx : %s\n", sym->start, sym->name);
280 } 280 }
281
282 {
283 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
284
285 if (poll(&stdin_poll, 1, 0) == 1) {
286 printf("key pressed - exiting.\n");
287 exit(0);
288 }
289 }
290} 281}
291 282
292static void *display_thread(void *arg) 283static void *display_thread(void *arg)
293{ 284{
285 struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
286 int delay_msecs = delay_secs * 1000;
287
294 printf("PerfTop refresh period: %d seconds\n", delay_secs); 288 printf("PerfTop refresh period: %d seconds\n", delay_secs);
295 289
296 while (!sleep(delay_secs)) 290 do {
297 print_sym_table(); 291 print_sym_table();
292 } while (!poll(&stdin_poll, 1, delay_msecs) == 1);
293
294 printf("key pressed - exiting.\n");
295 exit(0);
298 296
299 return NULL; 297 return NULL;
300} 298}