Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753163AbdHNQ3s (ORCPT ); Mon, 14 Aug 2017 12:29:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:51518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751482AbdHNQ3p (ORCPT ); Mon, 14 Aug 2017 12:29:45 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B48B2395C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Michael Petlan , Namhyung Kim , Thomas Richter , Wang Nan Subject: [PATCH 19/19] perf test shell: Add uprobes + backtrace ping test Date: Mon, 14 Aug 2017 13:27:41 -0300 Message-Id: <20170814162741.6101-20-acme@kernel.org> X-Mailer: git-send-email 2.13.4 In-Reply-To: <20170814162741.6101-1-acme@kernel.org> References: <20170814162741.6101-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3427 Lines: 95 From: Arnaldo Carvalho de Melo Installs a probe on libc's inet_pton function, that will use uprobes, then use 'perf trace' on a ping to localhost asking for just one packet with the a backtrace 3 levels deep, check that it is what we expect. This needs no debuginfo package, all is done using the libc ELF symtab and the CFI info in the binaries. Testing it: # perf test ping 61: probe libc's inet_pton & backtrace it with ping : Ok In verbose mode: # perf test -v ping 61: probe libc's inet_pton & backtrace it with ping : --- start --- test child forked, pid 1007 PING ::1(::1) 56 data bytes 64 bytes from ::1: icmp_seq=1 ttl=64 time=0.058 ms --- ::1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.058/0.058/0.058/0.000 ms 0.000 probe_libc:inet_pton:(7f75fce12a20)) __GI___inet_pton (/usr/lib64/libc-2.24.so) getaddrinfo (/usr/lib64/libc-2.24.so) _init (/usr/bin/ping) test child finished with 0 ---- end ---- probe libc's inet_pton & backtrace it with ping: Ok # Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Michael Petlan Cc: Namhyung Kim Cc: Thomas Richter Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-idrntt4nbg15aafu8hjmv7sk@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- .../perf/tests/shell/trace+probe_libc_inet_pton.sh | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 tools/perf/tests/shell/trace+probe_libc_inet_pton.sh diff --git a/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh new file mode 100755 index 000000000000..1b9a276e2ace --- /dev/null +++ b/tools/perf/tests/shell/trace+probe_libc_inet_pton.sh @@ -0,0 +1,40 @@ +# probe libc's inet_pton & backtrace it with ping + +# Installs a probe on libc's inet_pton function, that will use uprobes, +# then use 'perf trace' on a ping to localhost asking for just one packet +# with the a backtrace 3 levels deep, check that it is what we expect. +# This needs no debuginfo package, all is done using the libc ELF symtab +# and the CFI info in the binaries. + +# Arnaldo Carvalho de Melo , 2017 + +trace_libc_inet_pton_backtrace() { + idx=0 + expected[0]="PING.*bytes" + expected[1]="64 bytes from ::1.*" + expected[2]=".*ping statistics.*" + expected[3]=".*packets transmitted.*" + expected[4]="rtt min.*" + expected[5]="[0-9]+\.[0-9]+[[:space:]]+probe_libc:inet_pton:\([[:xdigit:]]+\)" + expected[6]=".*inet_pton[[:space:]]\(/usr/lib.*/libc-[0-9]+\.[0-9]+\.so\)$" + expected[7]="getaddrinfo[[:space:]]\(/usr/lib.*/libc-[0-9]+\.[0-9]+\.so\)$" + expected[8]=".*\(.*/bin/ping.*\)$" + + perf trace --no-syscalls -e probe_libc:inet_pton/max-stack=3/ ping -6 -c 1 ::1 |& grep -v ^$ | while read line ; do + echo $line + echo "$line" | egrep -q "${expected[$idx]}" + if [ $? -ne 0 ] ; then + printf "FAIL: expected backtrace entry %d \"%s\" got \"%s\"\n" $idx "${expected[$idx]}" "$line" + exit 1 + fi + let idx+=1 + [ $idx -eq 9 ] && break + done +} + +perf probe -q /lib64/libc-*.so inet_pton && \ +trace_libc_inet_pton_backtrace +err=$? +rm -f ${file} +perf probe -q -d probe_libc:inet_pton +exit $err -- 2.13.4