perf evlist: Make event_copy local to mmaps

I am getting segfaults *after* the time sorting of perf samples where
the event type is off the charts:

(gdb) bt
\#0  0x0807b1b2 in hists__inc_nr_events (hists=0x80a99c4, type=1163281902) at util/hist.c:1225
\#1  0x08070795 in perf_session_deliver_event (session=0x80a9b90, event=0xf7a6aff8, sample=0xffffc318, tool=0xffffc520,
    file_offset=0) at util/session.c:884
\#2  0x0806f9b9 in flush_sample_queue (s=0x80a9b90, tool=0xffffc520) at util/session.c:555
\#3  0x0806fc53 in process_finished_round (tool=0xffffc520, event=0x0, session=0x80a9b90) at util/session.c:645

This is bizarre because the event has already been processed once --
before it was added to the samples queue -- and the event was found to
be sane at that time.

There seem to be 2 causes:

1. perf_evlist__mmap_read updates the read location even though there
are outstanding references to events sitting in the mmap buffers via the
ordered samples queue.

2. There is a single evlist->event_copy for all evlist entries.
event_copy is used to handle an event wrapping at the mmap buffer
boundary.

This patch addresses the second problem - making event_copy local to
each perf_mmap. With this change my highly repeatable use case no longer
fails.

The first problem is much more complicated and will be the subject of a
future patch.

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1360098762-61827-1-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
perf evlist: restore some methods removed in an earlier cleanup

e60fc847 removed the perf_evlist__add_tracepoints and helpers, but
they are useful for kvm's upcoming live mode.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf evlist: move tracepoint processing code to evlist.c

Code move only; no functional changes.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf evlist: add initialzation function for tracepoints

Handles initializations typically done as part of processing the file
header and HEADER_TRACING_DATA event.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf session: export a few functions for event processing

Allows kvm live mode to reuse the event processing and ordered samples
processing used by the perf-report path.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf top: move CONSOLE_CLEAR to header file

For use with kvm-live mode.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: remove typecast in init_kvm_event_record

Not needed after changing i to unsigned int.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: handle realloc failures

Save previous pointer and free on failure.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: add braces around multi-line statements

Multi-line statements should have braces. Improves readability.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: split out tracepoints from record args

Needed by kvm live command. Make record_args a local while we are
messing with the args.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: total count is a u64, print as so

remove cast and use proper type in format.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: only process events for vcpus of interest

Minimizing processing overhead for each sample - which becomes important
for the upcoming live mode when it has to deal with 100+k events per
second.

Signed-off-by: David Ahern <dsahern@gmail.com>
perf kvm: add live mode

perf kvm stat currently requires back to back record and report
commands to see stats. e.g,.

  perf kvm stat record -p $pid -- sleep 1
  perf kvm stat report

This is rather inconvenvient for on box monitoring of a VM. This
patch introduces a 'live' mode that in effect combines the record
plus report into one command. e.g., to monitor a single VM:

  perf kvm stat live -p $pid

Same stats options for the record+report path work with the live mode.
Display rate defaults to 1 and can be changed using the -d option.

Signed-off-by: David Ahern <dsahern@gmail.com>