Commit cbb5cf7ff6b298beacfe23db3386335b0b9c0a2d

Authored by Tom Zanussi
Committed by Frederic Weisbecker
1 parent 537b60d178

perf: Use read() instead of lseek() in trace_event_read.c:skip()

This is a small fix for a problem affecting live-mode, introduced
recently:

root@tropicana:~# perf trace rwtop
perf trace started with Perl
script /root/libexec/perf-core/scripts/perl/rwtop.pl

  Fatal: did not read header event

commit d00a47cce569a3e660a8c9de5d57af28d6a9f0f7 added a skip()
function to skip over e.g. header_page, but this doesn't work for
live mode.  This patch re-implements skip() to use read() instead of
lseek() to fix that.

Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1273032130.6383.28.camel@tropicana>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>

Showing 1 changed file with 13 additions and 6 deletions Side-by-side Diff

tools/perf/util/trace-event-read.c
... ... @@ -53,12 +53,6 @@
53 53 static ssize_t calc_data_size;
54 54 static bool repipe;
55 55  
56   -/* If it fails, the next read will report it */
57   -static void skip(int size)
58   -{
59   - lseek(input_fd, size, SEEK_CUR);
60   -}
61   -
62 56 static int do_read(int fd, void *buf, int size)
63 57 {
64 58 int rsize = size;
... ... @@ -96,6 +90,19 @@
96 90 calc_data_size += r;
97 91  
98 92 return r;
  93 +}
  94 +
  95 +/* If it fails, the next read will report it */
  96 +static void skip(int size)
  97 +{
  98 + char buf[BUFSIZ];
  99 + int r;
  100 +
  101 + while (size) {
  102 + r = size > BUFSIZ ? BUFSIZ : size;
  103 + read_or_die(buf, r);
  104 + size -= r;
  105 + };
99 106 }
100 107  
101 108 static unsigned int read4(void)