Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312330
b: refs/heads/master
c: e84c282
h: refs/heads/master
v: v3
  • Loading branch information
Steven Rostedt authored and Namhyung Kim committed Jul 4, 2012
1 parent 6a848d0 commit 368ac93
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 151 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: 1dc12760854a670d0366dcfd8ad179e3574c1712
refs/heads/master: e84c282b40251f314c429f39b044785e323f2648
45 changes: 35 additions & 10 deletions trunk/tools/lib/traceevent/parse-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,18 +1710,43 @@ static int test_num(struct event_format *event,

static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record)
{
const char *val = record->data + arg->str.field->offset;
struct event_format *event;
struct pevent *pevent;
unsigned long long addr;
const char *val = NULL;
char hex[64];

/*
* We need to copy the data since we can't be sure the field
* is null terminated.
*/
if (*(val + arg->str.field->size - 1)) {
/* copy it */
memcpy(arg->str.buffer, val, arg->str.field->size);
/* the buffer is already NULL terminated */
val = arg->str.buffer;
/* If the field is not a string convert it */
if (arg->str.field->flags & FIELD_IS_STRING) {
val = record->data + arg->str.field->offset;

/*
* We need to copy the data since we can't be sure the field
* is null terminated.
*/
if (*(val + arg->str.field->size - 1)) {
/* copy it */
memcpy(arg->str.buffer, val, arg->str.field->size);
/* the buffer is already NULL terminated */
val = arg->str.buffer;
}

} else {
event = arg->str.field->event;
pevent = event->pevent;
addr = get_value(event, arg->str.field, record);

if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG))
/* convert to a kernel symbol */
val = pevent_find_function(pevent, addr);

if (val == NULL) {
/* just use the hex of the string name */
snprintf(hex, 64, "0x%llx", addr);
val = hex;
}
}

return val;
}

Expand Down
29 changes: 19 additions & 10 deletions trunk/tools/perf/util/parse-events-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ static struct test__event_st test__events[] = {
},
};

#define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))

static struct test__event_st test__events_pmu[] = {
[0] = {
.name = "cpu/config=10,config1,config2=3,period=1000/u",
Expand All @@ -645,6 +647,9 @@ static struct test__event_st test__events_pmu[] = {
},
};

#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
sizeof(struct test__event_st))

struct test__term {
const char *str;
__u32 type;
Expand Down Expand Up @@ -760,17 +765,21 @@ int parse_events__test(void)
{
int ret;

#define TEST_EVENTS(tests) \
do { \
ret = test_events(tests, ARRAY_SIZE(tests)); \
if (ret) \
return ret; \
} while (0)
do {
ret = test_events(test__events, TEST__EVENTS_CNT);
if (ret)
break;

if (test_pmu()) {
ret = test_events(test__events_pmu,
TEST__EVENTS_PMU_CNT);
if (ret)
break;
}

TEST_EVENTS(test__events);
ret = test_terms(test__terms, TEST__TERMS_CNT);

if (test_pmu())
TEST_EVENTS(test__events_pmu);
} while (0);

return test_terms(test__terms, ARRAY_SIZE(test__terms));
return ret;
}
174 changes: 57 additions & 117 deletions trunk/tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define MAX_NAME_LEN 100

struct event_symbol {
u8 type;
u64 config;
const char *symbol;
const char *alias;
};
Expand All @@ -28,86 +30,30 @@ extern int parse_events_debug;
#endif
int parse_events_parse(void *data, void *scanner);

static struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = {
[PERF_COUNT_HW_CPU_CYCLES] = {
.symbol = "cpu-cycles",
.alias = "cycles",
},
[PERF_COUNT_HW_INSTRUCTIONS] = {
.symbol = "instructions",
.alias = "",
},
[PERF_COUNT_HW_CACHE_REFERENCES] = {
.symbol = "cache-references",
.alias = "",
},
[PERF_COUNT_HW_CACHE_MISSES] = {
.symbol = "cache-misses",
.alias = "",
},
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = {
.symbol = "branch-instructions",
.alias = "branches",
},
[PERF_COUNT_HW_BRANCH_MISSES] = {
.symbol = "branch-misses",
.alias = "",
},
[PERF_COUNT_HW_BUS_CYCLES] = {
.symbol = "bus-cycles",
.alias = "",
},
[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = {
.symbol = "stalled-cycles-frontend",
.alias = "idle-cycles-frontend",
},
[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = {
.symbol = "stalled-cycles-backend",
.alias = "idle-cycles-backend",
},
[PERF_COUNT_HW_REF_CPU_CYCLES] = {
.symbol = "ref-cycles",
.alias = "",
},
};

static struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
[PERF_COUNT_SW_CPU_CLOCK] = {
.symbol = "cpu-clock",
.alias = "",
},
[PERF_COUNT_SW_TASK_CLOCK] = {
.symbol = "task-clock",
.alias = "",
},
[PERF_COUNT_SW_PAGE_FAULTS] = {
.symbol = "page-faults",
.alias = "faults",
},
[PERF_COUNT_SW_CONTEXT_SWITCHES] = {
.symbol = "context-switches",
.alias = "cs",
},
[PERF_COUNT_SW_CPU_MIGRATIONS] = {
.symbol = "cpu-migrations",
.alias = "migrations",
},
[PERF_COUNT_SW_PAGE_FAULTS_MIN] = {
.symbol = "minor-faults",
.alias = "",
},
[PERF_COUNT_SW_PAGE_FAULTS_MAJ] = {
.symbol = "major-faults",
.alias = "",
},
[PERF_COUNT_SW_ALIGNMENT_FAULTS] = {
.symbol = "alignment-faults",
.alias = "",
},
[PERF_COUNT_SW_EMULATION_FAULTS] = {
.symbol = "emulation-faults",
.alias = "",
},
#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x

static struct event_symbol event_symbols[] = {
{ CHW(CPU_CYCLES), "cpu-cycles", "cycles" },
{ CHW(STALLED_CYCLES_FRONTEND), "stalled-cycles-frontend", "idle-cycles-frontend" },
{ CHW(STALLED_CYCLES_BACKEND), "stalled-cycles-backend", "idle-cycles-backend" },
{ CHW(INSTRUCTIONS), "instructions", "" },
{ CHW(CACHE_REFERENCES), "cache-references", "" },
{ CHW(CACHE_MISSES), "cache-misses", "" },
{ CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" },
{ CHW(BRANCH_MISSES), "branch-misses", "" },
{ CHW(BUS_CYCLES), "bus-cycles", "" },
{ CHW(REF_CPU_CYCLES), "ref-cycles", "" },

{ CSW(CPU_CLOCK), "cpu-clock", "" },
{ CSW(TASK_CLOCK), "task-clock", "" },
{ CSW(PAGE_FAULTS), "page-faults", "faults" },
{ CSW(PAGE_FAULTS_MIN), "minor-faults", "" },
{ CSW(PAGE_FAULTS_MAJ), "major-faults", "" },
{ CSW(CONTEXT_SWITCHES), "context-switches", "cs" },
{ CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" },
{ CSW(ALIGNMENT_FAULTS), "alignment-faults", "" },
{ CSW(EMULATION_FAULTS), "emulation-faults", "" },
};

#define __PERF_EVENT_FIELD(config, name) \
Expand Down Expand Up @@ -878,13 +824,16 @@ int is_valid_tracepoint(const char *event_string)
return 0;
}

static void __print_events_type(u8 type, struct event_symbol *syms,
unsigned max)
void print_events_type(u8 type)
{
struct event_symbol *syms = event_symbols;
unsigned int i;
char name[64];
unsigned i;

for (i = 0; i < max ; i++, syms++) {
for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
if (type != syms->type)
continue;

if (strlen(syms->alias))
snprintf(name, sizeof(name), "%s OR %s",
syms->symbol, syms->alias);
Expand All @@ -896,14 +845,6 @@ static void __print_events_type(u8 type, struct event_symbol *syms,
}
}

void print_events_type(u8 type)
{
if (type == PERF_TYPE_SOFTWARE)
__print_events_type(type, event_symbols_sw, PERF_COUNT_SW_MAX);
else
__print_events_type(type, event_symbols_hw, PERF_COUNT_HW_MAX);
}

int print_hwcache_events(const char *event_glob)
{
unsigned int type, op, i, printed = 0;
Expand Down Expand Up @@ -931,13 +872,26 @@ int print_hwcache_events(const char *event_glob)
return printed;
}

static void print_symbol_events(const char *event_glob, unsigned type,
struct event_symbol *syms, unsigned max)
/*
* Print the help text for the event symbols:
*/
void print_events(const char *event_glob)
{
unsigned i, printed = 0;
unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
struct event_symbol *syms = event_symbols;
char name[MAX_NAME_LEN];

for (i = 0; i < max; i++, syms++) {
printf("\n");
printf("List of pre-defined events (to be used in -e):\n");

for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
type = syms->type;

if (type != prev_type && printed) {
printf("\n");
printed = 0;
ntypes_printed++;
}

if (event_glob != NULL &&
!(strglobmatch(syms->symbol, event_glob) ||
Expand All @@ -948,31 +902,17 @@ static void print_symbol_events(const char *event_glob, unsigned type,
snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
else
strncpy(name, syms->symbol, MAX_NAME_LEN);
printf(" %-50s [%s]\n", name,
event_type_descriptors[type]);

printf(" %-50s [%s]\n", name, event_type_descriptors[type]);

printed++;
prev_type = type;
++printed;
}

if (printed)
if (ntypes_printed) {
printed = 0;
printf("\n");
}

/*
* Print the help text for the event symbols:
*/
void print_events(const char *event_glob)
{

printf("\n");
printf("List of pre-defined events (to be used in -e):\n");

print_symbol_events(event_glob, PERF_TYPE_HARDWARE,
event_symbols_hw, PERF_COUNT_HW_MAX);

print_symbol_events(event_glob, PERF_TYPE_SOFTWARE,
event_symbols_sw, PERF_COUNT_SW_MAX);

}
print_hwcache_events(event_glob);

if (event_glob != NULL)
Expand Down
3 changes: 1 addition & 2 deletions trunk/tools/perf/util/parse-events.l
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int sym(yyscan_t scanner, int type, int config)
YYSTYPE *yylval = parse_events_get_lval(scanner);

yylval->num = (type << 16) + config;
return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW;
return PE_VALUE_SYM;
}

static int term(yyscan_t scanner, int type)
Expand Down Expand Up @@ -152,7 +152,6 @@ r{num_raw_hex} { return raw(yyscanner); }
, { return ','; }
: { return ':'; }
= { return '='; }
\n { }

<mem>{
{modifier_bp} { return str(yyscanner, PE_MODIFIER_BP); }
Expand Down
Loading

0 comments on commit 368ac93

Please sign in to comment.