Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbZIYTPO (ORCPT ); Fri, 25 Sep 2009 15:15:14 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752223AbZIYTPN (ORCPT ); Fri, 25 Sep 2009 15:15:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49991 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752477AbZIYTPK (ORCPT ); Fri, 25 Sep 2009 15:15:10 -0400 From: Masami Hiramatsu Subject: [RFC PATCH tracing/kprobes 5/5] perf: kprobe command supports without libdwarf To: Frederic Weisbecker , Steven Rostedt , Ingo Molnar , lkml Cc: systemtap , DLE , Masami Hiramatsu , Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Steven Rostedt , Mike Galbraith , Paul Mackerras , Peter Zijlstra , Christoph Hellwig , Ananth N Mavinakayanahalli , Jim Keniston , "Frank Ch. Eigler" Date: Fri, 25 Sep 2009 12:16:11 -0700 Message-ID: <20090925191610.12939.53677.stgit@omoto> In-Reply-To: <20090925191424.12939.91503.stgit@omoto> References: <20090925191424.12939.91503.stgit@omoto> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7493 Lines: 232 Enables perf-kprobe even if libdwarf is installed. If libdwarf is not found, perf-kprobe just disables dwarf support. Users can use perf-kprobe to set up new events by using kprobe_events format. Signed-off-by: Masami Hiramatsu Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Arnaldo Carvalho de Melo Cc: Steven Rostedt Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Christoph Hellwig Cc: Ananth N Mavinakayanahalli Cc: Jim Keniston Cc: Frank Ch. Eigler --- tools/perf/Makefile | 6 +++--- tools/perf/builtin-kprobe.c | 42 +++++++++++++++++++++++++++++++++------- tools/perf/perf.c | 2 -- tools/perf/util/probe-finder.h | 2 ++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 1379e3f..3b0307a 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -385,6 +385,7 @@ BUILTIN_OBJS += builtin-stat.o BUILTIN_OBJS += builtin-timechart.o BUILTIN_OBJS += builtin-top.o BUILTIN_OBJS += builtin-trace.o +BUILTIN_OBJS += builtin-kprobe.o PERFLIBS = $(LIB_FILE) @@ -420,13 +421,12 @@ ifneq ($(shell sh -c "(echo '\#include '; echo 'int main(void) { Elf * endif ifneq ($(shell sh -c "(echo '\#include '; echo '\#include '; echo 'int main(void) { Dwarf_Debug dbg; Dwarf_Error err; dwarf_init(0, DW_DLC_READ, 0, 0, &dbg, &err); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -ldwarf -lelf -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y) - msg := $(warning No libdwarf.h found, disables kprobe support. Please install libdwarf-dev/libdwarf-devel); + msg := $(warning No libdwarf.h found, disables dwarf support. Please install libdwarf-dev/libdwarf-devel); + BASIC_CFLAGS += -DNO_LIBDWARF else EXTLIBS += -lelf -ldwarf LIB_H += util/probe-finder.h LIB_OBJS += util/probe-finder.o - BUILTIN_OBJS += builtin-kprobe.o - BASIC_CFLAGS += -DSUPPORT_DWARF endif ifdef NO_DEMANGLE diff --git a/tools/perf/builtin-kprobe.c b/tools/perf/builtin-kprobe.c index 9e4596b..d8ae476 100644 --- a/tools/perf/builtin-kprobe.c +++ b/tools/perf/builtin-kprobe.c @@ -53,6 +53,7 @@ const char *default_search_path[NR_SEARCH_PATH] = { static struct { char *vmlinux; char *release; + int need_dwarf; int nr_probe; struct probe_point probes[MAX_PROBES]; char *events[MAX_PROBES]; @@ -132,21 +133,27 @@ static int parse_probepoint(const struct option *opt __used, debug("symbol:%s file:%s offset:%d\n", pp->function, pp->file, pp->offset); } + if (pp->file) + session.need_dwarf = 1; pp->nr_args = argc - 1; if (pp->nr_args > 0) { pp->args = (char **)malloc(sizeof(char *) * pp->nr_args); memcpy(pp->args, &argv[1], sizeof(char *) * pp->nr_args); } - if (retp) - for (i = 0; i < pp->nr_args; i++) - if (is_c_varname(pp->args[i])) + for (i = 0; i < pp->nr_args; i++) + if (is_c_varname(pp->args[i])) { + if (retp) semantic_error("You can't specify local" " variable for kretprobe"); + session.need_dwarf = 1; + } + debug("%d arguments\n", pp->nr_args); return 0; } +#ifndef NO_LIBDWARF static int open_default_vmlinux(void) { struct utsname uts; @@ -176,6 +183,7 @@ static int open_default_vmlinux(void) } return fd; } +#endif static const char * const kprobe_usage[] = { "perf kprobe [] -P PROBEDEF [-P PROBEDEF ...]", @@ -183,11 +191,17 @@ static const char * const kprobe_usage[] = { }; static const struct option options[] = { +#ifndef NO_LIBDWARF OPT_STRING('k', "vmlinux", &session.vmlinux, "file", "vmlinux/module pathname"), OPT_STRING('r', "release", &session.release, "rel", "kernel release"), +#endif OPT_CALLBACK('P', "probe", NULL, +#ifdef NO_LIBDWARF + "p|r:[GRP/]NAME,FUNC[+OFFS],ARG[,ARG,...]", +#else "p|r:[GRP/]NAME,FUNC[+OFFS][@SRC]|@SRC:LINE,ARG[,ARG,...]", +#endif "probe point definition, where\n" "\t\tp:\tkprobe probe\n" "\t\tr:\tkretprobe probe\n" @@ -195,9 +209,13 @@ static const struct option options[] = { "\t\tNAME:\tEvent name\n" "\t\tFUNC:\tFunction name\n" "\t\tOFFS:\tOffset from function entry (in byte)\n" +#ifdef NO_LIBDWARF + "\t\tARG:\tProbe argument (only \n" +#else "\t\tSRC:\tSource code path\n" "\t\tLINE:\tLine number\n" "\t\tARG:\tProbe argument (local variable name or\n" +#endif "\t\t\tkprobe-tracer argument format is supported.)\n", parse_probepoint), OPT_END() @@ -237,7 +255,7 @@ static int synthesize_probepoint(struct probe_point *pp) int cmd_kprobe(int argc, const char **argv, const char *prefix __used) { - int i, j, fd, ret, need_dwarf = 0; + int i, j, fd, ret; struct probe_point *pp; char buf[MAX_CMDLEN]; @@ -246,18 +264,26 @@ int cmd_kprobe(int argc, const char **argv, const char *prefix __used) if (argc || session.nr_probe == 0) usage_with_options(kprobe_usage, options); - /* Synthesize return probes */ +#ifdef NO_LIBDWARF + if (session.need_dwarf) + semantic_error("Dwarf-analysis is not supported"); +#endif + + /* Synthesize probes without dwarf */ for (j = 0; j < session.nr_probe; j++) { +#ifndef NO_LIBDWARF if (session.events[j][0] != 'r') { - need_dwarf = 1; + session.need_dwarf = 1; continue; } +#endif ret = synthesize_probepoint(&session.probes[j]); if (ret < 0) semantic_error("probe point is too long."); } - if (!need_dwarf) +#ifndef NO_LIBDWARF + if (!session.need_dwarf) goto setup_probes; if (session.vmlinux) @@ -286,6 +312,8 @@ int cmd_kprobe(int argc, const char **argv, const char *prefix __used) close(fd); setup_probes: +#endif /* !NO_LIBDWARF */ + /* Settng up probe points */ snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path); fd = open(buf, O_WRONLY, O_APPEND); diff --git a/tools/perf/perf.c b/tools/perf/perf.c index c073924..dd77faf 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -295,9 +295,7 @@ static void handle_internal_command(int argc, const char **argv) { "version", cmd_version, 0 }, { "trace", cmd_trace, 0 }, { "sched", cmd_sched, 0 }, -#ifdef SUPPORT_DWARF { "kprobe", cmd_kprobe, 0 }, -#endif }; unsigned int i; static const char ext[] = STRIP_EXTENSION; diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index af920de..306810c 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h @@ -44,6 +44,7 @@ struct probe_point { char *probes[MAX_PROBES]; /* Output buffers (will be allocated)*/ }; +#ifndef NO_LIBDWARF extern int find_probepoint(int fd, struct probe_point *pp); #include @@ -64,5 +65,6 @@ struct probe_finder { char *buf; /* Current output buffer */ int len; /* Length of output buffer */ }; +#endif /* NO_LIBDWARF */ #endif /*_PROBE_FINDER_H */ -- Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: mhiramat@redhat.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/