Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 177455
b: refs/heads/master
c: d761b08
h: refs/heads/master
i:
  177453: aab43ed
  177451: f8e6d64
  177447: a992fd8
  177439: 3449617
v: v3
  • Loading branch information
Masami Hiramatsu authored and Ingo Molnar committed Dec 15, 2009
1 parent 0b29118 commit bd47bc3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 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: af663d75a64d2cc3f18bdb8a29ff4650b9417c16
refs/heads/master: d761b08bff0a9b653f6bd248cea50322e7eccb14
6 changes: 5 additions & 1 deletion trunk/tools/perf/builtin-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static struct {
char *release;
bool need_dwarf;
bool list_events;
bool force_add;
int nr_probe;
struct probe_point probes[MAX_PROBES];
struct strlist *dellist;
Expand Down Expand Up @@ -192,6 +193,8 @@ static const struct option options[] = {
#endif
"\t\t\tkprobe-tracer argument format.)\n",
opt_add_probe_event),
OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events"
" with existing name"),
OPT_END()
};

Expand Down Expand Up @@ -294,7 +297,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
}

/* Settng up probe points */
add_trace_kprobe_events(session.probes, session.nr_probe);
add_trace_kprobe_events(session.probes, session.nr_probe,
session.force_add);
return 0;
}

24 changes: 21 additions & 3 deletions trunk/tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static void write_trace_kprobe_event(int fd, const char *buf)
}

static void get_new_event_name(char *buf, size_t len, const char *base,
struct strlist *namelist)
struct strlist *namelist, bool allow_suffix)
{
int i, ret;

Expand All @@ -493,6 +493,12 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
if (!strlist__has_entry(namelist, buf))
return;

if (!allow_suffix) {
pr_warning("Error: event \"%s\" already exists. "
"(Use -f to force duplicates.)\n", base);
die("Can't add new event.");
}

/* Try to add suffix */
for (i = 1; i < MAX_EVENT_INDEX; i++) {
ret = e_snprintf(buf, len, "%s_%d", base, i);
Expand All @@ -505,13 +511,15 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
die("Too many events are on the same function.");
}

void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
bool force_add)
{
int i, j, fd;
struct probe_point *pp;
char buf[MAX_CMDLEN];
char event[64];
struct strlist *namelist;
bool allow_suffix;

fd = open_kprobe_events(O_RDWR, O_APPEND);
/* Get current event names */
Expand All @@ -524,9 +532,12 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
if (!pp->group)
pp->group = strdup(PERFPROBE_GROUP);
DIE_IF(!pp->event || !pp->group);
/* If force_add is true, suffix search is allowed */
allow_suffix = force_add;
for (i = 0; i < pp->found; i++) {
/* Get an unused new event name */
get_new_event_name(event, 64, pp->event, namelist);
get_new_event_name(event, 64, pp->event, namelist,
allow_suffix);
snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
pp->retprobe ? 'r' : 'p',
pp->group, event,
Expand All @@ -538,6 +549,13 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
show_perf_probe_event(event, buf, pp);
/* Add added event name to namelist */
strlist__add(namelist, event);
/*
* Probes after the first probe which comes from same
* user input are always allowed to add suffix, because
* there might be several addresses corresponding to
* one code line.
*/
allow_suffix = true;
}
}
/* Show how to use the event. */
Expand Down
3 changes: 2 additions & 1 deletion trunk/tools/perf/util/probe-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
extern int synthesize_perf_probe_event(struct probe_point *pp);
extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
extern int synthesize_trace_kprobe_event(struct probe_point *pp);
extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes);
extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
bool force_add);
extern void del_trace_kprobe_events(struct strlist *dellist);
extern void show_perf_probe_events(void);

Expand Down

0 comments on commit bd47bc3

Please sign in to comment.