diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-09-24 14:41:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-09-25 15:26:34 -0400 |
commit | ca1252779f48ece225c6003e01c675abb91cf1b4 (patch) | |
tree | bd7c98fec7da2fbab970ef5dff7c053a09e2810a | |
parent | 9620bc361ac6e292ad2d6997b2f59f41f4e17862 (diff) |
perf evsel: Introduce evsel_fprintf.h
We already had evsel_fprintf.c, add its counterpart, so that we can
reduce evsel.h a bit more.
We needed a new perf_event_attr_fprintf.c file so as to have a separate
object to link with the python binding in tools/perf/util/python-ext-sources
and not drag symbol_conf, etc into the python binding.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-06bdmt1062d9unzgqmxwlv88@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-evlist.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-sched.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 2 | ||||
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 153 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 51 | ||||
-rw-r--r-- | tools/perf/util/evsel_fprintf.c | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel_fprintf.h | 50 | ||||
-rw-r--r-- | tools/perf/util/header.c | 1 | ||||
-rw-r--r-- | tools/perf/util/perf_event_attr_fprintf.c | 148 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 |
12 files changed, 218 insertions, 193 deletions
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index 60509ce4dd28..440501994931 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "perf.h" | 10 | #include "perf.h" |
11 | #include "util/evlist.h" | 11 | #include "util/evlist.h" |
12 | #include "util/evsel.h" | 12 | #include "util/evsel.h" |
13 | #include "util/evsel_fprintf.h" | ||
13 | #include "util/parse-events.h" | 14 | #include "util/parse-events.h" |
14 | #include <subcmd/parse-options.h> | 15 | #include <subcmd/parse-options.h> |
15 | #include "util/session.h" | 16 | #include "util/session.h" |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index f9706306fea0..5cacc4f84c8d 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "util/cpumap.h" | 6 | #include "util/cpumap.h" |
7 | #include "util/evlist.h" | 7 | #include "util/evlist.h" |
8 | #include "util/evsel.h" | 8 | #include "util/evsel.h" |
9 | #include "util/evsel_fprintf.h" | ||
9 | #include "util/symbol.h" | 10 | #include "util/symbol.h" |
10 | #include "util/thread.h" | 11 | #include "util/thread.h" |
11 | #include "util/header.h" | 12 | #include "util/header.h" |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 0d43e2e5afff..286fc70d7402 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "util/trace-event.h" | 17 | #include "util/trace-event.h" |
18 | #include "util/evlist.h" | 18 | #include "util/evlist.h" |
19 | #include "util/evsel.h" | 19 | #include "util/evsel.h" |
20 | #include "util/evsel_fprintf.h" | ||
20 | #include "util/evswitch.h" | 21 | #include "util/evswitch.h" |
21 | #include "util/sort.h" | 22 | #include "util/sort.h" |
22 | #include "util/data.h" | 23 | #include "util/data.h" |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 318225c8d7a7..bb5130d02155 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #include "util/dso.h" | 28 | #include "util/dso.h" |
29 | #include "util/env.h" | 29 | #include "util/env.h" |
30 | #include "util/event.h" | 30 | #include "util/event.h" |
31 | #include "util/evsel.h" | ||
32 | #include "util/evsel_fprintf.h" | ||
31 | #include "util/synthetic-events.h" | 33 | #include "util/synthetic-events.h" |
32 | #include "util/evlist.h" | 34 | #include "util/evlist.h" |
33 | #include "util/evswitch.h" | 35 | #include "util/evswitch.h" |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 4d1894e38a81..8dcfca1a882f 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -11,6 +11,7 @@ perf-y += event.o | |||
11 | perf-y += evlist.o | 11 | perf-y += evlist.o |
12 | perf-y += evsel.o | 12 | perf-y += evsel.o |
13 | perf-y += evsel_fprintf.o | 13 | perf-y += evsel_fprintf.o |
14 | perf-y += perf_event_attr_fprintf.o | ||
14 | perf-y += evswitch.o | 15 | perf-y += evswitch.o |
15 | perf-y += find_bit.o | 16 | perf-y += find_bit.o |
16 | perf-y += get_current_dir_name.o | 17 | perf-y += get_current_dir_name.o |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9c284d2adcea..6323b0c60f6c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "counts.h" | 30 | #include "counts.h" |
31 | #include "event.h" | 31 | #include "event.h" |
32 | #include "evsel.h" | 32 | #include "evsel.h" |
33 | #include "util/evsel_fprintf.h" | ||
33 | #include "evlist.h" | 34 | #include "evlist.h" |
34 | #include <perf/cpumap.h> | 35 | #include <perf/cpumap.h> |
35 | #include "thread_map.h" | 36 | #include "thread_map.h" |
@@ -1443,152 +1444,6 @@ static int get_group_fd(struct evsel *evsel, int cpu, int thread) | |||
1443 | return fd; | 1444 | return fd; |
1444 | } | 1445 | } |
1445 | 1446 | ||
1446 | struct bit_names { | ||
1447 | int bit; | ||
1448 | const char *name; | ||
1449 | }; | ||
1450 | |||
1451 | static void __p_bits(char *buf, size_t size, u64 value, struct bit_names *bits) | ||
1452 | { | ||
1453 | bool first_bit = true; | ||
1454 | int i = 0; | ||
1455 | |||
1456 | do { | ||
1457 | if (value & bits[i].bit) { | ||
1458 | buf += scnprintf(buf, size, "%s%s", first_bit ? "" : "|", bits[i].name); | ||
1459 | first_bit = false; | ||
1460 | } | ||
1461 | } while (bits[++i].name != NULL); | ||
1462 | } | ||
1463 | |||
1464 | static void __p_sample_type(char *buf, size_t size, u64 value) | ||
1465 | { | ||
1466 | #define bit_name(n) { PERF_SAMPLE_##n, #n } | ||
1467 | struct bit_names bits[] = { | ||
1468 | bit_name(IP), bit_name(TID), bit_name(TIME), bit_name(ADDR), | ||
1469 | bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU), | ||
1470 | bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW), | ||
1471 | bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER), | ||
1472 | bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC), | ||
1473 | bit_name(WEIGHT), bit_name(PHYS_ADDR), | ||
1474 | { .name = NULL, } | ||
1475 | }; | ||
1476 | #undef bit_name | ||
1477 | __p_bits(buf, size, value, bits); | ||
1478 | } | ||
1479 | |||
1480 | static void __p_branch_sample_type(char *buf, size_t size, u64 value) | ||
1481 | { | ||
1482 | #define bit_name(n) { PERF_SAMPLE_BRANCH_##n, #n } | ||
1483 | struct bit_names bits[] = { | ||
1484 | bit_name(USER), bit_name(KERNEL), bit_name(HV), bit_name(ANY), | ||
1485 | bit_name(ANY_CALL), bit_name(ANY_RETURN), bit_name(IND_CALL), | ||
1486 | bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX), | ||
1487 | bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP), | ||
1488 | bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES), | ||
1489 | { .name = NULL, } | ||
1490 | }; | ||
1491 | #undef bit_name | ||
1492 | __p_bits(buf, size, value, bits); | ||
1493 | } | ||
1494 | |||
1495 | static void __p_read_format(char *buf, size_t size, u64 value) | ||
1496 | { | ||
1497 | #define bit_name(n) { PERF_FORMAT_##n, #n } | ||
1498 | struct bit_names bits[] = { | ||
1499 | bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING), | ||
1500 | bit_name(ID), bit_name(GROUP), | ||
1501 | { .name = NULL, } | ||
1502 | }; | ||
1503 | #undef bit_name | ||
1504 | __p_bits(buf, size, value, bits); | ||
1505 | } | ||
1506 | |||
1507 | #define BUF_SIZE 1024 | ||
1508 | |||
1509 | #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) | ||
1510 | #define p_unsigned(val) snprintf(buf, BUF_SIZE, "%"PRIu64, (uint64_t)(val)) | ||
1511 | #define p_signed(val) snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)(val)) | ||
1512 | #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) | ||
1513 | #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) | ||
1514 | #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) | ||
1515 | |||
1516 | #define PRINT_ATTRn(_n, _f, _p) \ | ||
1517 | do { \ | ||
1518 | if (attr->_f) { \ | ||
1519 | _p(attr->_f); \ | ||
1520 | ret += attr__fprintf(fp, _n, buf, priv);\ | ||
1521 | } \ | ||
1522 | } while (0) | ||
1523 | |||
1524 | #define PRINT_ATTRf(_f, _p) PRINT_ATTRn(#_f, _f, _p) | ||
1525 | |||
1526 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, | ||
1527 | attr__fprintf_f attr__fprintf, void *priv) | ||
1528 | { | ||
1529 | char buf[BUF_SIZE]; | ||
1530 | int ret = 0; | ||
1531 | |||
1532 | PRINT_ATTRf(type, p_unsigned); | ||
1533 | PRINT_ATTRf(size, p_unsigned); | ||
1534 | PRINT_ATTRf(config, p_hex); | ||
1535 | PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned); | ||
1536 | PRINT_ATTRf(sample_type, p_sample_type); | ||
1537 | PRINT_ATTRf(read_format, p_read_format); | ||
1538 | |||
1539 | PRINT_ATTRf(disabled, p_unsigned); | ||
1540 | PRINT_ATTRf(inherit, p_unsigned); | ||
1541 | PRINT_ATTRf(pinned, p_unsigned); | ||
1542 | PRINT_ATTRf(exclusive, p_unsigned); | ||
1543 | PRINT_ATTRf(exclude_user, p_unsigned); | ||
1544 | PRINT_ATTRf(exclude_kernel, p_unsigned); | ||
1545 | PRINT_ATTRf(exclude_hv, p_unsigned); | ||
1546 | PRINT_ATTRf(exclude_idle, p_unsigned); | ||
1547 | PRINT_ATTRf(mmap, p_unsigned); | ||
1548 | PRINT_ATTRf(comm, p_unsigned); | ||
1549 | PRINT_ATTRf(freq, p_unsigned); | ||
1550 | PRINT_ATTRf(inherit_stat, p_unsigned); | ||
1551 | PRINT_ATTRf(enable_on_exec, p_unsigned); | ||
1552 | PRINT_ATTRf(task, p_unsigned); | ||
1553 | PRINT_ATTRf(watermark, p_unsigned); | ||
1554 | PRINT_ATTRf(precise_ip, p_unsigned); | ||
1555 | PRINT_ATTRf(mmap_data, p_unsigned); | ||
1556 | PRINT_ATTRf(sample_id_all, p_unsigned); | ||
1557 | PRINT_ATTRf(exclude_host, p_unsigned); | ||
1558 | PRINT_ATTRf(exclude_guest, p_unsigned); | ||
1559 | PRINT_ATTRf(exclude_callchain_kernel, p_unsigned); | ||
1560 | PRINT_ATTRf(exclude_callchain_user, p_unsigned); | ||
1561 | PRINT_ATTRf(mmap2, p_unsigned); | ||
1562 | PRINT_ATTRf(comm_exec, p_unsigned); | ||
1563 | PRINT_ATTRf(use_clockid, p_unsigned); | ||
1564 | PRINT_ATTRf(context_switch, p_unsigned); | ||
1565 | PRINT_ATTRf(write_backward, p_unsigned); | ||
1566 | PRINT_ATTRf(namespaces, p_unsigned); | ||
1567 | PRINT_ATTRf(ksymbol, p_unsigned); | ||
1568 | PRINT_ATTRf(bpf_event, p_unsigned); | ||
1569 | PRINT_ATTRf(aux_output, p_unsigned); | ||
1570 | |||
1571 | PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned); | ||
1572 | PRINT_ATTRf(bp_type, p_unsigned); | ||
1573 | PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex); | ||
1574 | PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex); | ||
1575 | PRINT_ATTRf(branch_sample_type, p_branch_sample_type); | ||
1576 | PRINT_ATTRf(sample_regs_user, p_hex); | ||
1577 | PRINT_ATTRf(sample_stack_user, p_unsigned); | ||
1578 | PRINT_ATTRf(clockid, p_signed); | ||
1579 | PRINT_ATTRf(sample_regs_intr, p_hex); | ||
1580 | PRINT_ATTRf(aux_watermark, p_unsigned); | ||
1581 | PRINT_ATTRf(sample_max_stack, p_unsigned); | ||
1582 | |||
1583 | return ret; | ||
1584 | } | ||
1585 | |||
1586 | static int __open_attr__fprintf(FILE *fp, const char *name, const char *val, | ||
1587 | void *priv __maybe_unused) | ||
1588 | { | ||
1589 | return fprintf(fp, " %-32s %s\n", name, val); | ||
1590 | } | ||
1591 | |||
1592 | static void perf_evsel__remove_fd(struct evsel *pos, | 1447 | static void perf_evsel__remove_fd(struct evsel *pos, |
1593 | int nr_cpus, int nr_threads, | 1448 | int nr_cpus, int nr_threads, |
1594 | int thread_idx) | 1449 | int thread_idx) |
@@ -1659,6 +1514,12 @@ static bool ignore_missing_thread(struct evsel *evsel, | |||
1659 | return true; | 1514 | return true; |
1660 | } | 1515 | } |
1661 | 1516 | ||
1517 | static int __open_attr__fprintf(FILE *fp, const char *name, const char *val, | ||
1518 | void *priv __maybe_unused) | ||
1519 | { | ||
1520 | return fprintf(fp, " %-32s %s\n", name, val); | ||
1521 | } | ||
1522 | |||
1662 | static void display_attr(struct perf_event_attr *attr) | 1523 | static void display_attr(struct perf_event_attr *attr) |
1663 | { | 1524 | { |
1664 | if (verbose >= 2) { | 1525 | if (verbose >= 2) { |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 4a4c64833893..48183b5f5f83 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -4,7 +4,6 @@ | |||
4 | 4 | ||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <stdbool.h> | 6 | #include <stdbool.h> |
7 | #include <stdio.h> | ||
8 | #include <sys/types.h> | 7 | #include <sys/types.h> |
9 | #include <linux/perf_event.h> | 8 | #include <linux/perf_event.h> |
10 | #include <linux/types.h> | 9 | #include <linux/types.h> |
@@ -13,12 +12,6 @@ | |||
13 | #include "symbol_conf.h" | 12 | #include "symbol_conf.h" |
14 | #include <internal/cpumap.h> | 13 | #include <internal/cpumap.h> |
15 | 14 | ||
16 | struct addr_location; | ||
17 | struct evsel; | ||
18 | union perf_event; | ||
19 | |||
20 | struct cgroup; | ||
21 | |||
22 | /* | 15 | /* |
23 | * The 'struct perf_evsel_config_term' is used to pass event | 16 | * The 'struct perf_evsel_config_term' is used to pass event |
24 | * specific configuration data to perf_evsel__config routine. | 17 | * specific configuration data to perf_evsel__config routine. |
@@ -62,7 +55,11 @@ struct perf_evsel_config_term { | |||
62 | bool weak; | 55 | bool weak; |
63 | }; | 56 | }; |
64 | 57 | ||
58 | struct bpf_object; | ||
59 | struct cgroup; | ||
60 | struct perf_counts; | ||
65 | struct perf_stat_evsel; | 61 | struct perf_stat_evsel; |
62 | union perf_event; | ||
66 | 63 | ||
67 | typedef int (perf_evsel__sb_cb_t)(union perf_event *event, void *data); | 64 | typedef int (perf_evsel__sb_cb_t)(union perf_event *event, void *data); |
68 | 65 | ||
@@ -71,9 +68,6 @@ enum perf_tool_event { | |||
71 | PERF_TOOL_DURATION_TIME = 1, | 68 | PERF_TOOL_DURATION_TIME = 1, |
72 | }; | 69 | }; |
73 | 70 | ||
74 | struct bpf_object; | ||
75 | struct perf_counts; | ||
76 | |||
77 | /** struct evsel - event selector | 71 | /** struct evsel - event selector |
78 | * | 72 | * |
79 | * @evlist - evlist this evsel is in, if it is in one. | 73 | * @evlist - evlist this evsel is in, if it is in one. |
@@ -404,38 +398,6 @@ static inline bool perf_evsel__is_clock(struct evsel *evsel) | |||
404 | perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK); | 398 | perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK); |
405 | } | 399 | } |
406 | 400 | ||
407 | struct perf_attr_details { | ||
408 | bool freq; | ||
409 | bool verbose; | ||
410 | bool event_group; | ||
411 | bool force; | ||
412 | bool trace_fields; | ||
413 | }; | ||
414 | |||
415 | int perf_evsel__fprintf(struct evsel *evsel, | ||
416 | struct perf_attr_details *details, FILE *fp); | ||
417 | |||
418 | #define EVSEL__PRINT_IP (1<<0) | ||
419 | #define EVSEL__PRINT_SYM (1<<1) | ||
420 | #define EVSEL__PRINT_DSO (1<<2) | ||
421 | #define EVSEL__PRINT_SYMOFFSET (1<<3) | ||
422 | #define EVSEL__PRINT_ONELINE (1<<4) | ||
423 | #define EVSEL__PRINT_SRCLINE (1<<5) | ||
424 | #define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6) | ||
425 | #define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7) | ||
426 | #define EVSEL__PRINT_SKIP_IGNORED (1<<8) | ||
427 | |||
428 | struct callchain_cursor; | ||
429 | |||
430 | int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, | ||
431 | unsigned int print_opts, struct callchain_cursor *cursor, | ||
432 | struct strlist *bt_stop_list, FILE *fp); | ||
433 | |||
434 | int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, | ||
435 | int left_alignment, unsigned int print_opts, | ||
436 | struct callchain_cursor *cursor, | ||
437 | struct strlist *bt_stop_list, FILE *fp); | ||
438 | |||
439 | bool perf_evsel__fallback(struct evsel *evsel, int err, | 401 | bool perf_evsel__fallback(struct evsel *evsel, int err, |
440 | char *msg, size_t msgsize); | 402 | char *msg, size_t msgsize); |
441 | int perf_evsel__open_strerror(struct evsel *evsel, struct target *target, | 403 | int perf_evsel__open_strerror(struct evsel *evsel, struct target *target, |
@@ -468,11 +430,6 @@ static inline bool evsel__has_callchain(const struct evsel *evsel) | |||
468 | return (evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0; | 430 | return (evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0; |
469 | } | 431 | } |
470 | 432 | ||
471 | typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *); | ||
472 | |||
473 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, | ||
474 | attr__fprintf_f attr__fprintf, void *priv); | ||
475 | |||
476 | struct perf_env *perf_evsel__env(struct evsel *evsel); | 433 | struct perf_env *perf_evsel__env(struct evsel *evsel); |
477 | 434 | ||
478 | int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist); | 435 | int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist); |
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c index 756b1e852db7..028df7afb0dc 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <traceevent/event-parse.h> | 5 | #include <traceevent/event-parse.h> |
6 | #include "evsel.h" | 6 | #include "evsel.h" |
7 | #include "util/evsel_fprintf.h" | ||
7 | #include "util/event.h" | 8 | #include "util/event.h" |
8 | #include "callchain.h" | 9 | #include "callchain.h" |
9 | #include "map.h" | 10 | #include "map.h" |
diff --git a/tools/perf/util/evsel_fprintf.h b/tools/perf/util/evsel_fprintf.h new file mode 100644 index 000000000000..47e6c8456bb1 --- /dev/null +++ b/tools/perf/util/evsel_fprintf.h | |||
@@ -0,0 +1,50 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #ifndef __PERF_EVSEL_FPRINTF_H | ||
3 | #define __PERF_EVSEL_FPRINTF_H 1 | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdbool.h> | ||
7 | |||
8 | struct evsel; | ||
9 | |||
10 | struct perf_attr_details { | ||
11 | bool freq; | ||
12 | bool verbose; | ||
13 | bool event_group; | ||
14 | bool force; | ||
15 | bool trace_fields; | ||
16 | }; | ||
17 | |||
18 | int perf_evsel__fprintf(struct evsel *evsel, | ||
19 | struct perf_attr_details *details, FILE *fp); | ||
20 | |||
21 | #define EVSEL__PRINT_IP (1<<0) | ||
22 | #define EVSEL__PRINT_SYM (1<<1) | ||
23 | #define EVSEL__PRINT_DSO (1<<2) | ||
24 | #define EVSEL__PRINT_SYMOFFSET (1<<3) | ||
25 | #define EVSEL__PRINT_ONELINE (1<<4) | ||
26 | #define EVSEL__PRINT_SRCLINE (1<<5) | ||
27 | #define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6) | ||
28 | #define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7) | ||
29 | #define EVSEL__PRINT_SKIP_IGNORED (1<<8) | ||
30 | |||
31 | struct addr_location; | ||
32 | struct perf_event_attr; | ||
33 | struct perf_sample; | ||
34 | struct callchain_cursor; | ||
35 | struct strlist; | ||
36 | |||
37 | int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, | ||
38 | unsigned int print_opts, struct callchain_cursor *cursor, | ||
39 | struct strlist *bt_stop_list, FILE *fp); | ||
40 | |||
41 | int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, | ||
42 | int left_alignment, unsigned int print_opts, | ||
43 | struct callchain_cursor *cursor, | ||
44 | struct strlist *bt_stop_list, FILE *fp); | ||
45 | |||
46 | typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *); | ||
47 | |||
48 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, | ||
49 | attr__fprintf_f attr__fprintf, void *priv); | ||
50 | #endif // __PERF_EVSEL_H | ||
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 3b24b4974c5f..86d9396cb131 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "dso.h" | 25 | #include "dso.h" |
26 | #include "evlist.h" | 26 | #include "evlist.h" |
27 | #include "evsel.h" | 27 | #include "evsel.h" |
28 | #include "util/evsel_fprintf.h" | ||
28 | #include "header.h" | 29 | #include "header.h" |
29 | #include "memswap.h" | 30 | #include "memswap.h" |
30 | #include "trace-event.h" | 31 | #include "trace-event.h" |
diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c new file mode 100644 index 000000000000..d4ad3f04923a --- /dev/null +++ b/tools/perf/util/perf_event_attr_fprintf.c | |||
@@ -0,0 +1,148 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #include <inttypes.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdbool.h> | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/types.h> | ||
7 | #include <linux/perf_event.h> | ||
8 | #include "util/evsel_fprintf.h" | ||
9 | |||
10 | struct bit_names { | ||
11 | int bit; | ||
12 | const char *name; | ||
13 | }; | ||
14 | |||
15 | static void __p_bits(char *buf, size_t size, u64 value, struct bit_names *bits) | ||
16 | { | ||
17 | bool first_bit = true; | ||
18 | int i = 0; | ||
19 | |||
20 | do { | ||
21 | if (value & bits[i].bit) { | ||
22 | buf += scnprintf(buf, size, "%s%s", first_bit ? "" : "|", bits[i].name); | ||
23 | first_bit = false; | ||
24 | } | ||
25 | } while (bits[++i].name != NULL); | ||
26 | } | ||
27 | |||
28 | static void __p_sample_type(char *buf, size_t size, u64 value) | ||
29 | { | ||
30 | #define bit_name(n) { PERF_SAMPLE_##n, #n } | ||
31 | struct bit_names bits[] = { | ||
32 | bit_name(IP), bit_name(TID), bit_name(TIME), bit_name(ADDR), | ||
33 | bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU), | ||
34 | bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW), | ||
35 | bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER), | ||
36 | bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC), | ||
37 | bit_name(WEIGHT), bit_name(PHYS_ADDR), | ||
38 | { .name = NULL, } | ||
39 | }; | ||
40 | #undef bit_name | ||
41 | __p_bits(buf, size, value, bits); | ||
42 | } | ||
43 | |||
44 | static void __p_branch_sample_type(char *buf, size_t size, u64 value) | ||
45 | { | ||
46 | #define bit_name(n) { PERF_SAMPLE_BRANCH_##n, #n } | ||
47 | struct bit_names bits[] = { | ||
48 | bit_name(USER), bit_name(KERNEL), bit_name(HV), bit_name(ANY), | ||
49 | bit_name(ANY_CALL), bit_name(ANY_RETURN), bit_name(IND_CALL), | ||
50 | bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX), | ||
51 | bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP), | ||
52 | bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES), | ||
53 | { .name = NULL, } | ||
54 | }; | ||
55 | #undef bit_name | ||
56 | __p_bits(buf, size, value, bits); | ||
57 | } | ||
58 | |||
59 | static void __p_read_format(char *buf, size_t size, u64 value) | ||
60 | { | ||
61 | #define bit_name(n) { PERF_FORMAT_##n, #n } | ||
62 | struct bit_names bits[] = { | ||
63 | bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING), | ||
64 | bit_name(ID), bit_name(GROUP), | ||
65 | { .name = NULL, } | ||
66 | }; | ||
67 | #undef bit_name | ||
68 | __p_bits(buf, size, value, bits); | ||
69 | } | ||
70 | |||
71 | #define BUF_SIZE 1024 | ||
72 | |||
73 | #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) | ||
74 | #define p_unsigned(val) snprintf(buf, BUF_SIZE, "%"PRIu64, (uint64_t)(val)) | ||
75 | #define p_signed(val) snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)(val)) | ||
76 | #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) | ||
77 | #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) | ||
78 | #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) | ||
79 | |||
80 | #define PRINT_ATTRn(_n, _f, _p) \ | ||
81 | do { \ | ||
82 | if (attr->_f) { \ | ||
83 | _p(attr->_f); \ | ||
84 | ret += attr__fprintf(fp, _n, buf, priv);\ | ||
85 | } \ | ||
86 | } while (0) | ||
87 | |||
88 | #define PRINT_ATTRf(_f, _p) PRINT_ATTRn(#_f, _f, _p) | ||
89 | |||
90 | int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, | ||
91 | attr__fprintf_f attr__fprintf, void *priv) | ||
92 | { | ||
93 | char buf[BUF_SIZE]; | ||
94 | int ret = 0; | ||
95 | |||
96 | PRINT_ATTRf(type, p_unsigned); | ||
97 | PRINT_ATTRf(size, p_unsigned); | ||
98 | PRINT_ATTRf(config, p_hex); | ||
99 | PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned); | ||
100 | PRINT_ATTRf(sample_type, p_sample_type); | ||
101 | PRINT_ATTRf(read_format, p_read_format); | ||
102 | |||
103 | PRINT_ATTRf(disabled, p_unsigned); | ||
104 | PRINT_ATTRf(inherit, p_unsigned); | ||
105 | PRINT_ATTRf(pinned, p_unsigned); | ||
106 | PRINT_ATTRf(exclusive, p_unsigned); | ||
107 | PRINT_ATTRf(exclude_user, p_unsigned); | ||
108 | PRINT_ATTRf(exclude_kernel, p_unsigned); | ||
109 | PRINT_ATTRf(exclude_hv, p_unsigned); | ||
110 | PRINT_ATTRf(exclude_idle, p_unsigned); | ||
111 | PRINT_ATTRf(mmap, p_unsigned); | ||
112 | PRINT_ATTRf(comm, p_unsigned); | ||
113 | PRINT_ATTRf(freq, p_unsigned); | ||
114 | PRINT_ATTRf(inherit_stat, p_unsigned); | ||
115 | PRINT_ATTRf(enable_on_exec, p_unsigned); | ||
116 | PRINT_ATTRf(task, p_unsigned); | ||
117 | PRINT_ATTRf(watermark, p_unsigned); | ||
118 | PRINT_ATTRf(precise_ip, p_unsigned); | ||
119 | PRINT_ATTRf(mmap_data, p_unsigned); | ||
120 | PRINT_ATTRf(sample_id_all, p_unsigned); | ||
121 | PRINT_ATTRf(exclude_host, p_unsigned); | ||
122 | PRINT_ATTRf(exclude_guest, p_unsigned); | ||
123 | PRINT_ATTRf(exclude_callchain_kernel, p_unsigned); | ||
124 | PRINT_ATTRf(exclude_callchain_user, p_unsigned); | ||
125 | PRINT_ATTRf(mmap2, p_unsigned); | ||
126 | PRINT_ATTRf(comm_exec, p_unsigned); | ||
127 | PRINT_ATTRf(use_clockid, p_unsigned); | ||
128 | PRINT_ATTRf(context_switch, p_unsigned); | ||
129 | PRINT_ATTRf(write_backward, p_unsigned); | ||
130 | PRINT_ATTRf(namespaces, p_unsigned); | ||
131 | PRINT_ATTRf(ksymbol, p_unsigned); | ||
132 | PRINT_ATTRf(bpf_event, p_unsigned); | ||
133 | PRINT_ATTRf(aux_output, p_unsigned); | ||
134 | |||
135 | PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned); | ||
136 | PRINT_ATTRf(bp_type, p_unsigned); | ||
137 | PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex); | ||
138 | PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex); | ||
139 | PRINT_ATTRf(branch_sample_type, p_branch_sample_type); | ||
140 | PRINT_ATTRf(sample_regs_user, p_hex); | ||
141 | PRINT_ATTRf(sample_stack_user, p_unsigned); | ||
142 | PRINT_ATTRf(clockid, p_signed); | ||
143 | PRINT_ATTRf(sample_regs_intr, p_hex); | ||
144 | PRINT_ATTRf(aux_watermark, p_unsigned); | ||
145 | PRINT_ATTRf(sample_max_stack, p_unsigned); | ||
146 | |||
147 | return ret; | ||
148 | } | ||
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index c6dd478956f1..9af183860fbd 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -10,6 +10,7 @@ util/python.c | |||
10 | util/cap.c | 10 | util/cap.c |
11 | util/evlist.c | 11 | util/evlist.c |
12 | util/evsel.c | 12 | util/evsel.c |
13 | util/perf_event_attr_fprintf.c | ||
13 | util/cpumap.c | 14 | util/cpumap.c |
14 | util/memswap.c | 15 | util/memswap.c |
15 | util/mmap.c | 16 | util/mmap.c |