Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169511
b: refs/heads/master
c: c171b55
h: refs/heads/master
i:
  169509: 4f785d6
  169507: 97a4c78
  169503: 6399427
v: v3
  • Loading branch information
Li Zefan authored and Ingo Molnar committed Oct 15, 2009
1 parent 95f0a91 commit f5839fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 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: 6fb2915df7f0747d9044da9dbff5b46dc2e20830
refs/heads/master: c171b552a7d316c7e1c3ad6f70a30178dd53e14c
15 changes: 14 additions & 1 deletion trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,11 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n

static void create_counter(int counter, int cpu, pid_t pid)
{
char *filter = filters[counter];
struct perf_event_attr *attr = attrs + counter;
struct perf_header_attr *h_attr;
int track = !counter; /* only the first counter needs these */
int ret;
struct {
u64 count;
u64 time_enabled;
Expand Down Expand Up @@ -479,7 +481,6 @@ static void create_counter(int counter, int cpu, pid_t pid)
multiplex_fd = fd[nr_cpu][counter];

if (multiplex && fd[nr_cpu][counter] != multiplex_fd) {
int ret;

ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
assert(ret != -1);
Expand All @@ -499,6 +500,16 @@ static void create_counter(int counter, int cpu, pid_t pid)
}
}

if (filter != NULL) {
ret = ioctl(fd[nr_cpu][counter],
PERF_EVENT_IOC_SET_FILTER, filter);
if (ret) {
error("failed to set filter with %d (%s)\n", errno,
strerror(errno));
exit(-1);
}
}

ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
}

Expand Down Expand Up @@ -676,6 +687,8 @@ static const struct option options[] = {
OPT_CALLBACK('e', "event", NULL, "event",
"event selector. use 'perf list' to list available events",
parse_events),
OPT_CALLBACK(0, "filter", NULL, "filter",
"event filter", parse_filter),
OPT_INTEGER('p', "pid", &target_pid,
"record events on existing pid"),
OPT_INTEGER('r', "realtime", &realtime_prio,
Expand Down
26 changes: 24 additions & 2 deletions trunk/tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include "cache.h"
#include "header.h"

int nr_counters;
int nr_counters;

struct perf_event_attr attrs[MAX_COUNTERS];
char *filters[MAX_COUNTERS];

struct event_symbol {
u8 type;
Expand Down Expand Up @@ -708,7 +709,6 @@ static void store_event_type(const char *orgname)
perf_header__push_event(id, orgname);
}


int parse_events(const struct option *opt __used, const char *str, int unset __used)
{
struct perf_event_attr attr;
Expand Down Expand Up @@ -745,6 +745,28 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u
return 0;
}

int parse_filter(const struct option *opt __used, const char *str,
int unset __used)
{
int i = nr_counters - 1;
int len = strlen(str);

if (i < 0 || attrs[i].type != PERF_TYPE_TRACEPOINT) {
fprintf(stderr,
"-F option should follow a -e tracepoint option\n");
return -1;
}

filters[i] = malloc(len + 1);
if (!filters[i]) {
fprintf(stderr, "not enough memory to hold filter string\n");
return -1;
}
strcpy(filters[i], str);

return 0;
}

static const char * const event_type_descriptors[] = {
"",
"Hardware event",
Expand Down
2 changes: 2 additions & 0 deletions trunk/tools/perf/util/parse-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
extern int nr_counters;

extern struct perf_event_attr attrs[MAX_COUNTERS];
extern char *filters[MAX_COUNTERS];

extern const char *event_name(int ctr);
extern const char *__event_name(int type, u64 config);

extern int parse_events(const struct option *opt, const char *str, int unset);
extern int parse_filter(const struct option *opt, const char *str, int unset);

#define EVENTS_HELP_MAX (128*1024)

Expand Down

0 comments on commit f5839fd

Please sign in to comment.