Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 218644
b: refs/heads/master
c: cf6eb48
h: refs/heads/master
v: v3
  • Loading branch information
Masami Hiramatsu authored and Arnaldo Carvalho de Melo committed Oct 21, 2010
1 parent 6e71073 commit 862bcbf
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 106 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 632941c4f8fbd5b90dcb1672cd0422dfd7332bc9
refs/heads/master: cf6eb489e5c04c8f8d5fd7bf90b8346c987688bc
7 changes: 7 additions & 0 deletions trunk/tools/perf/Documentation/perf-probe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ or
'perf probe' --list
or
'perf probe' --line='FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]'
or
'perf probe' --vars='PROBEPOINT'

DESCRIPTION
-----------
Expand Down Expand Up @@ -57,6 +59,11 @@ OPTIONS
Show source code lines which can be probed. This needs an argument
which specifies a range of the source code. (see LINE SYNTAX for detail)

-V::
--vars=::
Show available local variables at given probe point. The argument
syntax is same as PROBE SYNTAX, but NO ARGs.

-f::
--force::
Forcibly add events with existing name.
Expand Down
61 changes: 54 additions & 7 deletions trunk/tools/perf/builtin-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ static struct {
bool list_events;
bool force_add;
bool show_lines;
bool show_vars;
bool mod_events;
int nevents;
struct perf_probe_event events[MAX_PROBES];
struct strlist *dellist;
struct line_range line_range;
int max_probe_points;
} params;


/* Parse an event definition. Note that any error must die. */
static int parse_probe_event(const char *str)
{
Expand Down Expand Up @@ -92,6 +93,7 @@ static int parse_probe_event_argv(int argc, const char **argv)
len = 0;
for (i = 0; i < argc; i++)
len += sprintf(&buf[len], "%s ", argv[i]);
params.mod_events = true;
ret = parse_probe_event(buf);
free(buf);
return ret;
Expand All @@ -100,16 +102,18 @@ static int parse_probe_event_argv(int argc, const char **argv)
static int opt_add_probe_event(const struct option *opt __used,
const char *str, int unset __used)
{
if (str)
if (str) {
params.mod_events = true;
return parse_probe_event(str);
else
} else
return 0;
}

static int opt_del_probe_event(const struct option *opt __used,
const char *str, int unset __used)
{
if (str) {
params.mod_events = true;
if (!params.dellist)
params.dellist = strlist__new(true, NULL);
strlist__add(params.dellist, str);
Expand All @@ -130,6 +134,25 @@ static int opt_show_lines(const struct option *opt __used,

return ret;
}

static int opt_show_vars(const struct option *opt __used,
const char *str, int unset __used)
{
struct perf_probe_event *pev = &params.events[params.nevents];
int ret;

if (!str)
return 0;

ret = parse_probe_event(str);
if (!ret && pev->nargs != 0) {
pr_err(" Error: '--vars' doesn't accept arguments.\n");
return -EINVAL;
}
params.show_vars = true;

return ret;
}
#endif

static const char * const probe_usage[] = {
Expand All @@ -139,6 +162,7 @@ static const char * const probe_usage[] = {
"perf probe --list",
#ifdef DWARF_SUPPORT
"perf probe --line 'LINEDESC'",
"perf probe --vars 'PROBEPOINT'",
#endif
NULL
};
Expand Down Expand Up @@ -180,6 +204,9 @@ static const struct option options[] = {
OPT_CALLBACK('L', "line", NULL,
"FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
"Show source code lines.", opt_show_lines),
OPT_CALLBACK('V', "vars", NULL,
"FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
"Show accessible variables on PROBEDEF", opt_show_vars),
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
"file", "vmlinux pathname"),
OPT_STRING('s', "source", &symbol_conf.source_prefix,
Expand Down Expand Up @@ -217,14 +244,18 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
usage_with_options(probe_usage, options);

if (params.list_events) {
if (params.nevents != 0 || params.dellist) {
if (params.mod_events) {
pr_err(" Error: Don't use --list with --add/--del.\n");
usage_with_options(probe_usage, options);
}
if (params.show_lines) {
pr_err(" Error: Don't use --list with --line.\n");
usage_with_options(probe_usage, options);
}
if (params.show_vars) {
pr_err(" Error: Don't use --list with --vars.\n");
usage_with_options(probe_usage, options);
}
ret = show_perf_probe_events();
if (ret < 0)
pr_err(" Error: Failed to show event list. (%d)\n",
Expand All @@ -234,9 +265,13 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)

#ifdef DWARF_SUPPORT
if (params.show_lines) {
if (params.nevents != 0 || params.dellist) {
pr_warning(" Error: Don't use --line with"
" --add/--del.\n");
if (params.mod_events) {
pr_err(" Error: Don't use --line with"
" --add/--del.\n");
usage_with_options(probe_usage, options);
}
if (params.show_vars) {
pr_err(" Error: Don't use --line with --vars.\n");
usage_with_options(probe_usage, options);
}

Expand All @@ -245,6 +280,18 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
pr_err(" Error: Failed to show lines. (%d)\n", ret);
return ret;
}
if (params.show_vars) {
if (params.mod_events) {
pr_err(" Error: Don't use --vars with"
" --add/--del.\n");
usage_with_options(probe_usage, options);
}
ret = show_available_vars(params.events, params.nevents,
params.max_probe_points);
if (ret < 0)
pr_err(" Error: Failed to show vars. (%d)\n", ret);
return ret;
}
#endif

if (params.dellist) {
Expand Down
72 changes: 72 additions & 0 deletions trunk/tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,72 @@ int show_line_range(struct line_range *lr)
return ret;
}

static int show_available_vars_at(int fd, struct perf_probe_event *pev,
int max_vls)
{
char *buf;
int ret, i;
struct str_node *node;
struct variable_list *vls = NULL, *vl;

buf = synthesize_perf_probe_point(&pev->point);
if (!buf)
return -EINVAL;
pr_debug("Searching variables at %s\n", buf);

ret = find_available_vars_at(fd, pev, &vls, max_vls);
if (ret > 0) {
/* Some variables were found */
fprintf(stdout, "Available variables at %s\n", buf);
for (i = 0; i < ret; i++) {
vl = &vls[i];
/*
* A probe point might be converted to
* several trace points.
*/
fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol,
vl->point.offset);
free(vl->point.symbol);
if (vl->vars) {
strlist__for_each(node, vl->vars)
fprintf(stdout, "\t\t%s\n", node->s);
strlist__delete(vl->vars);
} else
fprintf(stdout, "(No variables)\n");
}
free(vls);
} else
pr_err("Failed to find variables at %s (%d)\n", buf, ret);

free(buf);
return ret;
}

/* Show available variables on given probe point */
int show_available_vars(struct perf_probe_event *pevs, int npevs,
int max_vls)
{
int i, fd, ret = 0;

ret = init_vmlinux();
if (ret < 0)
return ret;

fd = open_vmlinux();
if (fd < 0) {
pr_warning("Failed to open debuginfo file.\n");
return fd;
}

setup_pager();

for (i = 0; i < npevs && ret >= 0; i++)
ret = show_available_vars_at(fd, &pevs[i], max_vls);

close(fd);
return ret;
}

#else /* !DWARF_SUPPORT */

static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
Expand Down Expand Up @@ -409,6 +475,12 @@ int show_line_range(struct line_range *lr __unused)
return -ENOSYS;
}

int show_available_vars(struct perf_probe_event *pevs __unused,
int npevs __unused, int max_probe_points __unused)
{
pr_warning("Debuginfo-analysis is not supported.\n");
return -ENOSYS;
}
#endif

int parse_line_range_desc(const char *arg, struct line_range *lr)
Expand Down
8 changes: 8 additions & 0 deletions trunk/tools/perf/util/probe-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ struct line_range {
struct list_head line_list; /* Visible lines */
};

/* List of variables */
struct variable_list {
struct probe_trace_point point; /* Actual probepoint */
struct strlist *vars; /* Available variables */
};

/* Command string to events */
extern int parse_perf_probe_command(const char *cmd,
struct perf_probe_event *pev);
Expand All @@ -115,6 +121,8 @@ extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
extern int del_perf_probe_events(struct strlist *dellist);
extern int show_perf_probe_events(void);
extern int show_line_range(struct line_range *lr);
extern int show_available_vars(struct perf_probe_event *pevs, int npevs,
int max_probe_points);


/* Maximum index number of event-name postfix */
Expand Down
Loading

0 comments on commit 862bcbf

Please sign in to comment.