diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-06-06 17:10:43 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-06-07 03:32:44 -0400 |
commit | 2f01190aa62fe9dd0a98205927b9f09fd191c017 (patch) | |
tree | 255fe87e7645385dd4aec77d4299f06ddb1fd654 /tools | |
parent | 23b87116c7c4f73597965218b66041acbdb4e79f (diff) |
perf top: Wait for a minimal set of events before reading first snapshot
The first snapshot reading often occur before any events have
been read in the mapped perfcounter files.
Just wait until we have at least one event before starting the
snapshot, or the delay before the first set of entries to be
displayed may be long in case of low refresh rate.
Note: we could also use a semaphore to wait before
"print_entries" number of eveents is reached, but again this
value is tunable and we can't ensure we will even reach it.
Also we could base on a default mimimum set of entries for the
first refresh, say 15, but again, the minimal sample is
tunable, and we could end up displaying nothing until we have a
minimal default set of events, which can take some time in case
of high samples filters.
Hence this simple solution which partially covers the default
case.
[ Impact: fix display artifacts in perf top ]
Signed-off-by: Frederic Weisbecker <fweisbeec@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>
LKML-Reference: <1244322643-6447-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-top.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index f2e7312f85c9..fdc1d5863b01 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -420,7 +420,7 @@ static unsigned int mmap_read_head(struct mmap_data *md) | |||
420 | 420 | ||
421 | struct timeval last_read, this_read; | 421 | struct timeval last_read, this_read; |
422 | 422 | ||
423 | static void mmap_read(struct mmap_data *md) | 423 | static void mmap_read_counter(struct mmap_data *md) |
424 | { | 424 | { |
425 | unsigned int head = mmap_read_head(md); | 425 | unsigned int head = mmap_read_head(md); |
426 | unsigned int old = md->prev; | 426 | unsigned int old = md->prev; |
@@ -517,6 +517,16 @@ static void mmap_read(struct mmap_data *md) | |||
517 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; | 517 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; |
518 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 518 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
519 | 519 | ||
520 | static void mmap_read(void) | ||
521 | { | ||
522 | int i, counter; | ||
523 | |||
524 | for (i = 0; i < nr_cpus; i++) { | ||
525 | for (counter = 0; counter < nr_counters; counter++) | ||
526 | mmap_read_counter(&mmap_array[i][counter]); | ||
527 | } | ||
528 | } | ||
529 | |||
520 | static int __cmd_top(void) | 530 | static int __cmd_top(void) |
521 | { | 531 | { |
522 | struct perf_counter_attr *attr; | 532 | struct perf_counter_attr *attr; |
@@ -571,6 +581,11 @@ static int __cmd_top(void) | |||
571 | } | 581 | } |
572 | } | 582 | } |
573 | 583 | ||
584 | /* Wait for a minimal set of events before starting the snapshot */ | ||
585 | poll(event_array, nr_poll, 100); | ||
586 | |||
587 | mmap_read(); | ||
588 | |||
574 | if (pthread_create(&thread, NULL, display_thread, NULL)) { | 589 | if (pthread_create(&thread, NULL, display_thread, NULL)) { |
575 | printf("Could not create display thread.\n"); | 590 | printf("Could not create display thread.\n"); |
576 | exit(-1); | 591 | exit(-1); |
@@ -589,10 +604,7 @@ static int __cmd_top(void) | |||
589 | while (1) { | 604 | while (1) { |
590 | int hits = samples; | 605 | int hits = samples; |
591 | 606 | ||
592 | for (i = 0; i < nr_cpus; i++) { | 607 | mmap_read(); |
593 | for (counter = 0; counter < nr_counters; counter++) | ||
594 | mmap_read(&mmap_array[i][counter]); | ||
595 | } | ||
596 | 608 | ||
597 | if (hits == samples) | 609 | if (hits == samples) |
598 | ret = poll(event_array, nr_poll, 100); | 610 | ret = poll(event_array, nr_poll, 100); |