Skip to content

Commit ccd2674

Browse files
Ravi Bangoriaacmel
authored andcommitted
perf tool: Provide an option to print perf_event_open args and return value
Perf record with verbose=2 already prints this information along with whole lot of other traces which requires lot of scrolling. Introduce an option to print only perf_event_open() arguments and return value. Sample o/p: $ perf --debug perf-event-open=1 record -- ls > /dev/null ------------------------------------------------------------ perf_event_attr: size 112 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|PERIOD read_format ID disabled 1 inherit 1 exclude_kernel 1 mmap 1 comm 1 freq 1 enable_on_exec 1 task 1 precise_ip 3 sample_id_all 1 exclude_guest 1 mmap2 1 comm_exec 1 ksymbol 1 bpf_event 1 ------------------------------------------------------------ sys_perf_event_open: pid 4308 cpu 0 group_fd -1 flags 0x8 = 4 sys_perf_event_open: pid 4308 cpu 1 group_fd -1 flags 0x8 = 5 sys_perf_event_open: pid 4308 cpu 2 group_fd -1 flags 0x8 = 6 sys_perf_event_open: pid 4308 cpu 3 group_fd -1 flags 0x8 = 8 sys_perf_event_open: pid 4308 cpu 4 group_fd -1 flags 0x8 = 9 sys_perf_event_open: pid 4308 cpu 5 group_fd -1 flags 0x8 = 10 sys_perf_event_open: pid 4308 cpu 6 group_fd -1 flags 0x8 = 11 sys_perf_event_open: pid 4308 cpu 7 group_fd -1 flags 0x8 = 12 ------------------------------------------------------------ perf_event_attr: type 1 size 112 config 0x9 watermark 1 sample_id_all 1 bpf_event 1 { wakeup_events, wakeup_watermark } 1 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 sys_perf_event_open failed, error -13 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (9 samples) ] Committer notes: Just like the 'verbose' variable this new 'debug_peo_args' needs to be added to util/python.c, since we don't link the debug.o file in the python binding, which ended up making 'perf test python' fail with: # perf test -v python 18: 'import perf' in python : --- start --- test child forked, pid 19237 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: /tmp/build/perf/python/perf.so: undefined symbol: debug_peo_args test child finished with -1 ---- end ---- 'import perf' in python: FAILED! # After adding that new variable to util/python.c: # perf test -v python 18: 'import perf' in python : --- start --- test child forked, pid 22364 test child finished with 0 ---- end ---- 'import perf' in python: Ok # Signed-off-by: Ravi Bangoria <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7b018e2 commit ccd2674

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

tools/perf/Documentation/perf.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ OPTIONS
2424
data-convert - data convert command debug messages
2525
stderr - write debug output (option -v) to stderr
2626
in browser mode
27+
perf-event-open - Print perf_event_open() arguments and
28+
return value
2729

2830
--buildid-dir::
2931
Setup buildid cache directory. It has higher priority than

tools/perf/util/debug.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/ctype.h>
2525

2626
int verbose;
27+
int debug_peo_args;
2728
bool dump_trace = false, quiet = false;
2829
int debug_ordered_events;
2930
static int redirect_to_stderr;
@@ -180,6 +181,7 @@ static struct debug_variable {
180181
{ .name = "ordered-events", .ptr = &debug_ordered_events},
181182
{ .name = "stderr", .ptr = &redirect_to_stderr},
182183
{ .name = "data-convert", .ptr = &debug_data_convert },
184+
{ .name = "perf-event-open", .ptr = &debug_peo_args },
183185
{ .name = NULL, }
184186
};
185187

tools/perf/util/debug.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/compiler.h>
99

1010
extern int verbose;
11+
extern int debug_peo_args;
1112
extern bool quiet, dump_trace;
1213
extern int debug_ordered_events;
1314
extern int debug_data_convert;
@@ -30,6 +31,14 @@ extern int debug_data_convert;
3031
#define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)
3132
#define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)
3233

34+
/* Special macro to print perf_event_open arguments/return value. */
35+
#define pr_debug2_peo(fmt, ...) { \
36+
if (debug_peo_args) \
37+
pr_debugN(0, pr_fmt(fmt), ##__VA_ARGS__); \
38+
else \
39+
pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__); \
40+
}
41+
3342
#define pr_time_N(n, var, t, fmt, ...) \
3443
eprintf_time(n, var, t, fmt, ##__VA_ARGS__)
3544

tools/perf/util/evsel.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ static int __open_attr__fprintf(FILE *fp, const char *name, const char *val,
15241524

15251525
static void display_attr(struct perf_event_attr *attr)
15261526
{
1527-
if (verbose >= 2) {
1527+
if (verbose >= 2 || debug_peo_args) {
15281528
fprintf(stderr, "%.60s\n", graph_dotted_line);
15291529
fprintf(stderr, "perf_event_attr:\n");
15301530
perf_event_attr__fprintf(stderr, attr, __open_attr__fprintf, NULL);
@@ -1540,7 +1540,7 @@ static int perf_event_open(struct evsel *evsel,
15401540
int fd;
15411541

15421542
while (1) {
1543-
pr_debug2("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
1543+
pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
15441544
pid, cpu, group_fd, flags);
15451545

15461546
fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, flags);
@@ -1560,9 +1560,9 @@ static int perf_event_open(struct evsel *evsel,
15601560
break;
15611561
}
15621562

1563-
pr_debug2("\nsys_perf_event_open failed, error %d\n", -ENOTSUP);
1563+
pr_debug2_peo("\nsys_perf_event_open failed, error %d\n", -ENOTSUP);
15641564
evsel->core.attr.precise_ip--;
1565-
pr_debug2("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip);
1565+
pr_debug2_peo("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip);
15661566
display_attr(&evsel->core.attr);
15671567
}
15681568

@@ -1681,12 +1681,12 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
16811681
continue;
16821682
}
16831683

1684-
pr_debug2("\nsys_perf_event_open failed, error %d\n",
1684+
pr_debug2_peo("\nsys_perf_event_open failed, error %d\n",
16851685
err);
16861686
goto try_fallback;
16871687
}
16881688

1689-
pr_debug2(" = %d\n", fd);
1689+
pr_debug2_peo(" = %d\n", fd);
16901690

16911691
if (evsel->bpf_fd >= 0) {
16921692
int evt_fd = fd;
@@ -1754,58 +1754,58 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
17541754
*/
17551755
if (!perf_missing_features.aux_output && evsel->core.attr.aux_output) {
17561756
perf_missing_features.aux_output = true;
1757-
pr_debug2("Kernel has no attr.aux_output support, bailing out\n");
1757+
pr_debug2_peo("Kernel has no attr.aux_output support, bailing out\n");
17581758
goto out_close;
17591759
} else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) {
17601760
perf_missing_features.bpf = true;
1761-
pr_debug2("switching off bpf_event\n");
1761+
pr_debug2_peo("switching off bpf_event\n");
17621762
goto fallback_missing_features;
17631763
} else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) {
17641764
perf_missing_features.ksymbol = true;
1765-
pr_debug2("switching off ksymbol\n");
1765+
pr_debug2_peo("switching off ksymbol\n");
17661766
goto fallback_missing_features;
17671767
} else if (!perf_missing_features.write_backward && evsel->core.attr.write_backward) {
17681768
perf_missing_features.write_backward = true;
1769-
pr_debug2("switching off write_backward\n");
1769+
pr_debug2_peo("switching off write_backward\n");
17701770
goto out_close;
17711771
} else if (!perf_missing_features.clockid_wrong && evsel->core.attr.use_clockid) {
17721772
perf_missing_features.clockid_wrong = true;
1773-
pr_debug2("switching off clockid\n");
1773+
pr_debug2_peo("switching off clockid\n");
17741774
goto fallback_missing_features;
17751775
} else if (!perf_missing_features.clockid && evsel->core.attr.use_clockid) {
17761776
perf_missing_features.clockid = true;
1777-
pr_debug2("switching off use_clockid\n");
1777+
pr_debug2_peo("switching off use_clockid\n");
17781778
goto fallback_missing_features;
17791779
} else if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) {
17801780
perf_missing_features.cloexec = true;
1781-
pr_debug2("switching off cloexec flag\n");
1781+
pr_debug2_peo("switching off cloexec flag\n");
17821782
goto fallback_missing_features;
17831783
} else if (!perf_missing_features.mmap2 && evsel->core.attr.mmap2) {
17841784
perf_missing_features.mmap2 = true;
1785-
pr_debug2("switching off mmap2\n");
1785+
pr_debug2_peo("switching off mmap2\n");
17861786
goto fallback_missing_features;
17871787
} else if (!perf_missing_features.exclude_guest &&
17881788
(evsel->core.attr.exclude_guest || evsel->core.attr.exclude_host)) {
17891789
perf_missing_features.exclude_guest = true;
1790-
pr_debug2("switching off exclude_guest, exclude_host\n");
1790+
pr_debug2_peo("switching off exclude_guest, exclude_host\n");
17911791
goto fallback_missing_features;
17921792
} else if (!perf_missing_features.sample_id_all) {
17931793
perf_missing_features.sample_id_all = true;
1794-
pr_debug2("switching off sample_id_all\n");
1794+
pr_debug2_peo("switching off sample_id_all\n");
17951795
goto retry_sample_id;
17961796
} else if (!perf_missing_features.lbr_flags &&
17971797
(evsel->core.attr.branch_sample_type &
17981798
(PERF_SAMPLE_BRANCH_NO_CYCLES |
17991799
PERF_SAMPLE_BRANCH_NO_FLAGS))) {
18001800
perf_missing_features.lbr_flags = true;
1801-
pr_debug2("switching off branch sample type no (cycles/flags)\n");
1801+
pr_debug2_peo("switching off branch sample type no (cycles/flags)\n");
18021802
goto fallback_missing_features;
18031803
} else if (!perf_missing_features.group_read &&
18041804
evsel->core.attr.inherit &&
18051805
(evsel->core.attr.read_format & PERF_FORMAT_GROUP) &&
18061806
perf_evsel__is_group_leader(evsel)) {
18071807
perf_missing_features.group_read = true;
1808-
pr_debug2("switching off group read\n");
1808+
pr_debug2_peo("switching off group read\n");
18091809
goto fallback_missing_features;
18101810
}
18111811
out_close:

tools/perf/util/python.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct perf_env perf_env;
6565
* implementing 'verbose' and 'eprintf'.
6666
*/
6767
int verbose;
68+
int debug_peo_args;
6869

6970
int eprintf(int level, int var, const char *fmt, ...);
7071

0 commit comments

Comments
 (0)