perf record: Add "nodelay" mode, disabled by default

Sometimes there is a need to use perf in "live-log" mode. The problem
is, for seldom events, actual info output is largely delayed because
perf-record reads sample data in whole pages.

So for such scenarious, add flag for perf-record to go in "nodelay"
mode. To track e.g. what's going on in icmp_rcv while ping is running
Use it with something like this:

(1) $ perf probe -L icmp_rcv | grep -U8 '^ *43\>'
goto error;
}
38 if (!pskb_pull(skb, sizeof(*icmph)))
goto error;
icmph = icmp_hdr(skb);

43 ICMPMSGIN_INC_STATS_BH(net, icmph->type);
/*
* 18 is the highest 'known' ICMP type. Anything else is a mystery
*
* RFC 1122: 3.2.2 Unknown ICMP messages types MUST be silently
* discarded.
*/
50 if (icmph->type > NR_ICMP_TYPES)
goto error;

$ perf probe icmp_rcv:43 'type=icmph->type'

(2) $ cat trace-icmp.py
[...]
def trace_begin():
print "in trace_begin"

def trace_end():
print "in trace_end"

def probe__icmp_rcv(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
__probe_ip, type):
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)

print "__probe_ip=%u, type=%u\n" % \
(__probe_ip, type),
[...]

(3) $ perf record -a -D -e probe:icmp_rcv -o - | \
perf script -i - -s trace-icmp.py

Thanks to Peter Zijlstra for pointing how to do it.

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>, Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20110112140613.GA11698@tugrik.mns.mnsspb.ru>
Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by Kirill Smelkov and committed by Arnaldo Carvalho de Melo acac03fa 9710118b

+11
+3
tools/perf/Documentation/perf-record.txt
··· 61 61 -r:: 62 62 --realtime=:: 63 63 Collect data with this RT SCHED_FIFO priority. 64 + -D:: 65 + --no-delay:: 66 + Collect data without buffering. 64 67 -A:: 65 68 --append:: 66 69 Append to the output file to do incremental profiling.
+8
tools/perf/builtin-record.c
··· 49 49 static const char *output_name = "perf.data"; 50 50 static int group = 0; 51 51 static int realtime_prio = 0; 52 + static bool nodelay = false; 52 53 static bool raw_samples = false; 53 54 static bool sample_id_all_avail = true; 54 55 static bool system_wide = false; ··· 306 305 attr->sample_type |= PERF_SAMPLE_TIME; 307 306 attr->sample_type |= PERF_SAMPLE_RAW; 308 307 attr->sample_type |= PERF_SAMPLE_CPU; 308 + } 309 + 310 + if (nodelay) { 311 + attr->watermark = 0; 312 + attr->wakeup_events = 1; 309 313 } 310 314 311 315 attr->mmap = track; ··· 849 843 "record events on existing thread id"), 850 844 OPT_INTEGER('r', "realtime", &realtime_prio, 851 845 "collect data with this RT SCHED_FIFO priority"), 846 + OPT_BOOLEAN('D', "no-delay", &nodelay, 847 + "collect data without buffering"), 852 848 OPT_BOOLEAN('R', "raw-samples", &raw_samples, 853 849 "collect raw sample records from all opened counters"), 854 850 OPT_BOOLEAN('a', "all-cpus", &system_wide,