Skip to content

Commit e4cc9f4

Browse files
author
Ingo Molnar
committed
Merge branch 'perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 into perf/core
2 parents e9345aa + 668b878 commit e4cc9f4

10 files changed

Lines changed: 177 additions & 31 deletions

File tree

‎tools/perf/Documentation/perf-list.txt‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types
88
SYNOPSIS
99
--------
1010
[verse]
11-
'perf list'
11+
'perf list' [hw|sw|cache|tracepoint|event_glob]
1212

1313
DESCRIPTION
1414
-----------
@@ -63,7 +63,26 @@ details. Some of them are referenced in the SEE ALSO section below.
6363

6464
OPTIONS
6565
-------
66-
None
66+
67+
Without options all known events will be listed.
68+
69+
To limit the list use:
70+
71+
. 'hw' or 'hardware' to list hardware events such as cache-misses, etc.
72+
73+
. 'sw' or 'software' to list software events such as context switches, etc.
74+
75+
. 'cache' or 'hwcache' to list hardware cache events such as L1-dcache-loads, etc.
76+
77+
. 'tracepoint' to list all tracepoint events, alternatively use
78+
'subsys_glob:event_glob' to filter by tracepoint subsystems such as sched,
79+
block, etc.
80+
81+
. If none of the above is matched, it will apply the supplied glob to all
82+
events, printing the ones that match.
83+
84+
One or more types can be used at the same time, listing the events for the
85+
types specified.
6786

6887
SEE ALSO
6988
--------

‎tools/perf/builtin-list.c‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de>
77
* Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
8+
* Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
89
*/
910
#include "builtin.h"
1011

@@ -13,9 +14,47 @@
1314
#include "util/parse-events.h"
1415
#include "util/cache.h"
1516

16-
int cmd_list(int argc __used, const char **argv __used, const char *prefix __used)
17+
int cmd_list(int argc, const char **argv, const char *prefix __used)
1718
{
1819
setup_pager();
19-
print_events();
20+
21+
if (argc == 1)
22+
print_events(NULL);
23+
else {
24+
int i;
25+
26+
for (i = 1; i < argc; ++i) {
27+
if (i > 1)
28+
putchar('\n');
29+
if (strncmp(argv[i], "tracepoint", 10) == 0)
30+
print_tracepoint_events(NULL, NULL);
31+
else if (strcmp(argv[i], "hw") == 0 ||
32+
strcmp(argv[i], "hardware") == 0)
33+
print_events_type(PERF_TYPE_HARDWARE);
34+
else if (strcmp(argv[i], "sw") == 0 ||
35+
strcmp(argv[i], "software") == 0)
36+
print_events_type(PERF_TYPE_SOFTWARE);
37+
else if (strcmp(argv[i], "cache") == 0 ||
38+
strcmp(argv[i], "hwcache") == 0)
39+
print_hwcache_events(NULL);
40+
else {
41+
char *sep = strchr(argv[i], ':'), *s;
42+
int sep_idx;
43+
44+
if (sep == NULL) {
45+
print_events(argv[i]);
46+
continue;
47+
}
48+
sep_idx = sep - argv[i];
49+
s = strdup(argv[i]);
50+
if (s == NULL)
51+
return -1;
52+
53+
s[sep_idx] = '\0';
54+
print_tracepoint_events(s, s + sep_idx + 1);
55+
free(s);
56+
}
57+
}
58+
}
2059
return 0;
2160
}

‎tools/perf/builtin-record.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,6 @@ static int __cmd_record(int argc, const char **argv)
538538
if (have_tracepoints(&evsel_list->entries))
539539
perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
540540

541-
/*
542-
* perf_session__delete(session) will be called at atexit_header()
543-
*/
544-
atexit(atexit_header);
545-
546541
if (forks) {
547542
child_pid = fork();
548543
if (child_pid < 0) {
@@ -601,6 +596,11 @@ static int __cmd_record(int argc, const char **argv)
601596

602597
perf_session__set_sample_type(session, sample_type);
603598

599+
/*
600+
* perf_session__delete(session) will be called at atexit_header()
601+
*/
602+
atexit(atexit_header);
603+
604604
if (pipe_output) {
605605
err = perf_header__write_pipe(output);
606606
if (err < 0)

‎tools/perf/builtin-report.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ static int __cmd_report(void)
350350
perf_session__fprintf_dsos(session, stdout);
351351

352352
next = rb_first(&session->hists_tree);
353+
354+
if (next == NULL) {
355+
ui__warning("The %s file has no samples!\n", input_name);
356+
goto out_delete;
357+
}
358+
353359
while (next) {
354360
struct hists *hists;
355361

‎tools/perf/util/evsel.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void perf_evsel__delete(struct perf_evsel *evsel)
8686
{
8787
perf_evsel__exit(evsel);
8888
close_cgroup(evsel->cgrp);
89+
free(evsel->name);
8990
free(evsel);
9091
}
9192

‎tools/perf/util/evsel.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ struct perf_sample_id {
3737
struct perf_evsel *evsel;
3838
};
3939

40+
/** struct perf_evsel - event selector
41+
*
42+
* @name - Can be set to retain the original event name passed by the user,
43+
* so that when showing results in tools such as 'perf stat', we
44+
* show the name used, not some alias.
45+
*/
4046
struct perf_evsel {
4147
struct list_head node;
4248
struct perf_event_attr attr;
@@ -45,6 +51,7 @@ struct perf_evsel {
4551
struct xyarray *id;
4652
struct perf_counts *counts;
4753
int idx;
54+
char *name;
4855
void *priv;
4956
struct cgroup_sel *cgrp;
5057
};

‎tools/perf/util/hist.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
591591
{
592592
struct sort_entry *se;
593593
u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
594+
u64 nr_events;
594595
const char *sep = symbol_conf.field_sep;
595596
int ret;
596597

@@ -599,13 +600,15 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
599600

600601
if (pair_hists) {
601602
period = self->pair ? self->pair->period : 0;
603+
nr_events = self->pair ? self->pair->nr_events : 0;
602604
total = pair_hists->stats.total_period;
603605
period_sys = self->pair ? self->pair->period_sys : 0;
604606
period_us = self->pair ? self->pair->period_us : 0;
605607
period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
606608
period_guest_us = self->pair ? self->pair->period_guest_us : 0;
607609
} else {
608610
period = self->period;
611+
nr_events = self->nr_events;
609612
total = session_total;
610613
period_sys = self->period_sys;
611614
period_us = self->period_us;
@@ -646,9 +649,9 @@ int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
646649

647650
if (symbol_conf.show_nr_samples) {
648651
if (sep)
649-
ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
652+
ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
650653
else
651-
ret += snprintf(s + ret, size - ret, "%11" PRIu64, period);
654+
ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
652655
}
653656

654657
if (pair_hists) {

‎tools/perf/util/parse-events.c‎

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ const char *event_name(struct perf_evsel *evsel)
268268
u64 config = evsel->attr.config;
269269
int type = evsel->attr.type;
270270

271+
if (evsel->name)
272+
return evsel->name;
273+
271274
return __event_name(type, config);
272275
}
273276

@@ -782,8 +785,10 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
782785
struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
783786
struct perf_event_attr attr;
784787
enum event_result ret;
788+
const char *ostr;
785789

786790
for (;;) {
791+
ostr = str;
787792
memset(&attr, 0, sizeof(attr));
788793
ret = parse_event_symbols(opt, &str, &attr);
789794
if (ret == EVT_FAILED)
@@ -798,6 +803,11 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
798803
if (evsel == NULL)
799804
return -1;
800805
perf_evlist__add(evlist, evsel);
806+
807+
evsel->name = calloc(str - ostr + 1, 1);
808+
if (!evsel->name)
809+
return -1;
810+
strncpy(evsel->name, ostr, str - ostr);
801811
}
802812

803813
if (*str == 0)
@@ -848,7 +858,7 @@ static const char * const event_type_descriptors[] = {
848858
* Print the events from <debugfs_mount_point>/tracing/events
849859
*/
850860

851-
static void print_tracepoint_events(void)
861+
void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
852862
{
853863
DIR *sys_dir, *evt_dir;
854864
struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
@@ -863,6 +873,9 @@ static void print_tracepoint_events(void)
863873
return;
864874

865875
for_each_subsystem(sys_dir, sys_dirent, sys_next) {
876+
if (subsys_glob != NULL &&
877+
!strglobmatch(sys_dirent.d_name, subsys_glob))
878+
continue;
866879

867880
snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
868881
sys_dirent.d_name);
@@ -871,6 +884,10 @@ static void print_tracepoint_events(void)
871884
continue;
872885

873886
for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
887+
if (event_glob != NULL &&
888+
!strglobmatch(evt_dirent.d_name, event_glob))
889+
continue;
890+
874891
snprintf(evt_path, MAXPATHLEN, "%s:%s",
875892
sys_dirent.d_name, evt_dirent.d_name);
876893
printf(" %-42s [%s]\n", evt_path,
@@ -922,13 +939,61 @@ int is_valid_tracepoint(const char *event_string)
922939
return 0;
923940
}
924941

942+
void print_events_type(u8 type)
943+
{
944+
struct event_symbol *syms = event_symbols;
945+
unsigned int i;
946+
char name[64];
947+
948+
for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
949+
if (type != syms->type)
950+
continue;
951+
952+
if (strlen(syms->alias))
953+
snprintf(name, sizeof(name), "%s OR %s",
954+
syms->symbol, syms->alias);
955+
else
956+
snprintf(name, sizeof(name), "%s", syms->symbol);
957+
958+
printf(" %-42s [%s]\n", name,
959+
event_type_descriptors[type]);
960+
}
961+
}
962+
963+
int print_hwcache_events(const char *event_glob)
964+
{
965+
unsigned int type, op, i, printed = 0;
966+
967+
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
968+
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
969+
/* skip invalid cache type */
970+
if (!is_cache_op_valid(type, op))
971+
continue;
972+
973+
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
974+
char *name = event_cache_name(type, op, i);
975+
976+
if (event_glob != NULL &&
977+
!strglobmatch(name, event_glob))
978+
continue;
979+
980+
printf(" %-42s [%s]\n", name,
981+
event_type_descriptors[PERF_TYPE_HW_CACHE]);
982+
++printed;
983+
}
984+
}
985+
}
986+
987+
return printed;
988+
}
989+
925990
/*
926991
* Print the help text for the event symbols:
927992
*/
928-
void print_events(void)
993+
void print_events(const char *event_glob)
929994
{
930995
struct event_symbol *syms = event_symbols;
931-
unsigned int i, type, op, prev_type = -1;
996+
unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
932997
char name[40];
933998

934999
printf("\n");
@@ -937,8 +1002,16 @@ void print_events(void)
9371002
for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
9381003
type = syms->type;
9391004

940-
if (type != prev_type)
1005+
if (type != prev_type && printed) {
9411006
printf("\n");
1007+
printed = 0;
1008+
ntypes_printed++;
1009+
}
1010+
1011+
if (event_glob != NULL &&
1012+
!(strglobmatch(syms->symbol, event_glob) ||
1013+
(syms->alias && strglobmatch(syms->alias, event_glob))))
1014+
continue;
9421015

9431016
if (strlen(syms->alias))
9441017
sprintf(name, "%s OR %s", syms->symbol, syms->alias);
@@ -948,22 +1021,17 @@ void print_events(void)
9481021
event_type_descriptors[type]);
9491022

9501023
prev_type = type;
1024+
++printed;
9511025
}
9521026

953-
printf("\n");
954-
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
955-
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
956-
/* skip invalid cache type */
957-
if (!is_cache_op_valid(type, op))
958-
continue;
959-
960-
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
961-
printf(" %-42s [%s]\n",
962-
event_cache_name(type, op, i),
963-
event_type_descriptors[PERF_TYPE_HW_CACHE]);
964-
}
965-
}
1027+
if (ntypes_printed) {
1028+
printed = 0;
1029+
printf("\n");
9661030
}
1031+
print_hwcache_events(event_glob);
1032+
1033+
if (event_glob != NULL)
1034+
return;
9671035

9681036
printf("\n");
9691037
printf(" %-42s [%s]\n",
@@ -976,7 +1044,7 @@ void print_events(void)
9761044
event_type_descriptors[PERF_TYPE_BREAKPOINT]);
9771045
printf("\n");
9781046

979-
print_tracepoint_events();
1047+
print_tracepoint_events(NULL, NULL);
9801048

9811049
exit(129);
9821050
}

‎tools/perf/util/parse-events.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ extern int parse_filter(const struct option *opt, const char *str, int unset);
2828

2929
#define EVENTS_HELP_MAX (128*1024)
3030

31-
extern void print_events(void);
31+
void print_events(const char *event_glob);
32+
void print_events_type(u8 type);
33+
void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
34+
int print_hwcache_events(const char *event_glob);
3235
extern int is_valid_tracepoint(const char *event_string);
3336

3437
extern char debugfs_path[];

0 commit comments

Comments
 (0)