Re: [PATCH 2/2] perf record: mmap output file - v4

From: Ingo Molnar
Date: Mon Nov 11 2013 - 06:29:21 EST



* David Ahern <dsahern@xxxxxxxxx> wrote:

> When recording raw_syscalls for the entire system, e.g.,
> perf record -e raw_syscalls:*,sched:sched_switch -a -- sleep 1
>
> you end up with a negative feedback loop as perf itself calls write() fairly
> often. This patch handles the problem by mmap'ing the file in chunks of 64M at
> a time and copies events from the event buffers to the file avoiding write
> system calls.
>
> Before (with write syscall):
>
> perf record -o /tmp/perf.data -e raw_syscalls:*,sched:sched_switch -a -- sleep 1
> [ perf record: Woken up 0 times to write data ]
> [ perf record: Captured and wrote 81.843 MB /tmp/perf.data (~3575786 samples) ]
>
> After (using mmap):
>
> perf record -o /tmp/perf.data -e raw_syscalls:*,sched:sched_switch -a -- sleep 1
> [ perf record: Woken up 31 times to write data ]
> [ perf record: Captured and wrote 8.203 MB /tmp/perf.data (~358388 samples) ]
>
> In addition to perf-trace benefits using mmap lowers the overhead of
> perf-record. For example,
>
> perf stat -i -- perf record -g -o /tmp/perf.data openssl speed aes
>
> shows a drop in time, CPU cycles, and instructions all drop by more than a
> factor of 3. Jiri also ran a test that showed a big improvement.
>
> v4: Refactoring per Ingo's comments
>
> v3: Removed use of bytes_at_mmap_start at the stat() that set it
> Added user option to control the size of the mmap for writing file.
>
> v2: Removed msync call before munmap per Jiri's suggestion
>
> Signed-off-by: David Ahern <dsahern@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Mike Galbraith <efault@xxxxxx>
> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> ---
> tools/perf/Documentation/perf-record.txt | 5 +
> tools/perf/builtin-record.c | 155 +++++++++++++++++++++++++++++++
> 2 files changed, 160 insertions(+)

Looks very clean now!

Acked-by: Ingo Molnar <mingo@xxxxxxxxxx>

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/