diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2018-01-07 11:03:52 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-01-08 10:39:50 -0500 |
| commit | 28a0b39877f5ed64ae9fadf95dddb90999309dee (patch) | |
| tree | f9429934af444c9defd54ee2b0545a1a8b39f484 /tools/perf | |
| parent | 972c14884728bf5f69ec69cfb1beeec1a9cd29ee (diff) | |
perf script: Add support to display sample misc field
Adding support to display sample misc field in form
of letter for each bit:
# perf script -F +misc ...
sched-messaging 1414 K 28690.636582: 4590 cycles ...
sched-messaging 1407 U 28690.636600: 325620 cycles ...
sched-messaging 1414 K 28690.636608: 19473 cycles ...
misc field __________/
The misc bits are assigned to following letters:
PERF_RECORD_MISC_KERNEL K
PERF_RECORD_MISC_USER U
PERF_RECORD_MISC_HYPERVISOR H
PERF_RECORD_MISC_GUEST_KERNEL G
PERF_RECORD_MISC_GUEST_USER g
PERF_RECORD_MISC_MMAP_DATA* M
PERF_RECORD_MISC_COMM_EXEC E
PERF_RECORD_MISC_SWITCH_OUT S
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180107160356.28203-9-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/Documentation/perf-script.txt | 20 | ||||
| -rw-r--r-- | tools/perf/builtin-script.c | 74 | ||||
| -rw-r--r-- | tools/perf/util/event.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 1 |
4 files changed, 84 insertions, 12 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index 7b622a812a72..93ae8d60e3d3 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt | |||
| @@ -117,7 +117,7 @@ OPTIONS | |||
| 117 | Comma separated list of fields to print. Options are: | 117 | Comma separated list of fields to print. Options are: |
| 118 | comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, | 118 | comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, |
| 119 | srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, | 119 | srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, |
| 120 | brstackoff, callindent, insn, insnlen, synth, phys_addr, metric. | 120 | brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc. |
| 121 | Field list can be prepended with the type, trace, sw or hw, | 121 | Field list can be prepended with the type, trace, sw or hw, |
| 122 | to indicate to which event type the field list applies. | 122 | to indicate to which event type the field list applies. |
| 123 | e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace | 123 | e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace |
| @@ -225,6 +225,24 @@ OPTIONS | |||
| 225 | that the metric computed is averaged over the whole sampling | 225 | that the metric computed is averaged over the whole sampling |
| 226 | period, not just for the sample point. | 226 | period, not just for the sample point. |
| 227 | 227 | ||
| 228 | For sample events it's possible to display misc field with -F +misc option, | ||
| 229 | following letters are displayed for each bit: | ||
| 230 | |||
| 231 | PERF_RECORD_MISC_KERNEL K | ||
| 232 | PERF_RECORD_MISC_USER U | ||
| 233 | PERF_RECORD_MISC_HYPERVISOR H | ||
| 234 | PERF_RECORD_MISC_GUEST_KERNEL G | ||
| 235 | PERF_RECORD_MISC_GUEST_USER g | ||
| 236 | PERF_RECORD_MISC_MMAP_DATA* M | ||
| 237 | PERF_RECORD_MISC_COMM_EXEC E | ||
| 238 | PERF_RECORD_MISC_SWITCH_OUT S | ||
| 239 | |||
| 240 | $ perf script -F +misc ... | ||
| 241 | sched-messaging 1414 K 28690.636582: 4590 cycles ... | ||
| 242 | sched-messaging 1407 U 28690.636600: 325620 cycles ... | ||
| 243 | sched-messaging 1414 K 28690.636608: 19473 cycles ... | ||
| 244 | misc field ___________/ | ||
| 245 | |||
| 228 | -k:: | 246 | -k:: |
| 229 | --vmlinux=<file>:: | 247 | --vmlinux=<file>:: |
| 230 | vmlinux pathname | 248 | vmlinux pathname |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 330dcd9b9b8f..bb603495cf4a 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
| @@ -93,6 +93,7 @@ enum perf_output_field { | |||
| 93 | PERF_OUTPUT_PHYS_ADDR = 1U << 26, | 93 | PERF_OUTPUT_PHYS_ADDR = 1U << 26, |
| 94 | PERF_OUTPUT_UREGS = 1U << 27, | 94 | PERF_OUTPUT_UREGS = 1U << 27, |
| 95 | PERF_OUTPUT_METRIC = 1U << 28, | 95 | PERF_OUTPUT_METRIC = 1U << 28, |
| 96 | PERF_OUTPUT_MISC = 1U << 29, | ||
| 96 | }; | 97 | }; |
| 97 | 98 | ||
| 98 | struct output_option { | 99 | struct output_option { |
| @@ -128,6 +129,7 @@ struct output_option { | |||
| 128 | {.str = "synth", .field = PERF_OUTPUT_SYNTH}, | 129 | {.str = "synth", .field = PERF_OUTPUT_SYNTH}, |
| 129 | {.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR}, | 130 | {.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR}, |
| 130 | {.str = "metric", .field = PERF_OUTPUT_METRIC}, | 131 | {.str = "metric", .field = PERF_OUTPUT_METRIC}, |
| 132 | {.str = "misc", .field = PERF_OUTPUT_MISC}, | ||
| 131 | }; | 133 | }; |
| 132 | 134 | ||
| 133 | enum { | 135 | enum { |
| @@ -594,7 +596,8 @@ static int perf_sample__fprintf_uregs(struct perf_sample *sample, | |||
| 594 | 596 | ||
| 595 | static int perf_sample__fprintf_start(struct perf_sample *sample, | 597 | static int perf_sample__fprintf_start(struct perf_sample *sample, |
| 596 | struct thread *thread, | 598 | struct thread *thread, |
| 597 | struct perf_evsel *evsel, FILE *fp) | 599 | struct perf_evsel *evsel, |
| 600 | u32 type, FILE *fp) | ||
| 598 | { | 601 | { |
| 599 | struct perf_event_attr *attr = &evsel->attr; | 602 | struct perf_event_attr *attr = &evsel->attr; |
| 600 | unsigned long secs; | 603 | unsigned long secs; |
| @@ -624,6 +627,47 @@ static int perf_sample__fprintf_start(struct perf_sample *sample, | |||
| 624 | printed += fprintf(fp, "[%03d] ", sample->cpu); | 627 | printed += fprintf(fp, "[%03d] ", sample->cpu); |
| 625 | } | 628 | } |
| 626 | 629 | ||
| 630 | if (PRINT_FIELD(MISC)) { | ||
| 631 | int ret = 0; | ||
| 632 | |||
| 633 | #define has(m) \ | ||
| 634 | (sample->misc & PERF_RECORD_MISC_##m) == PERF_RECORD_MISC_##m | ||
| 635 | |||
| 636 | if (has(KERNEL)) | ||
| 637 | ret += fprintf(fp, "K"); | ||
| 638 | if (has(USER)) | ||
| 639 | ret += fprintf(fp, "U"); | ||
| 640 | if (has(HYPERVISOR)) | ||
| 641 | ret += fprintf(fp, "H"); | ||
| 642 | if (has(GUEST_KERNEL)) | ||
| 643 | ret += fprintf(fp, "G"); | ||
| 644 | if (has(GUEST_USER)) | ||
| 645 | ret += fprintf(fp, "g"); | ||
| 646 | |||
| 647 | switch (type) { | ||
| 648 | case PERF_RECORD_MMAP: | ||
| 649 | case PERF_RECORD_MMAP2: | ||
| 650 | if (has(MMAP_DATA)) | ||
| 651 | ret += fprintf(fp, "M"); | ||
| 652 | break; | ||
| 653 | case PERF_RECORD_COMM: | ||
| 654 | if (has(COMM_EXEC)) | ||
| 655 | ret += fprintf(fp, "E"); | ||
| 656 | break; | ||
| 657 | case PERF_RECORD_SWITCH: | ||
| 658 | case PERF_RECORD_SWITCH_CPU_WIDE: | ||
| 659 | if (has(SWITCH_OUT)) | ||
| 660 | ret += fprintf(fp, "S"); | ||
| 661 | default: | ||
| 662 | break; | ||
| 663 | } | ||
| 664 | |||
| 665 | #undef has | ||
| 666 | |||
| 667 | ret += fprintf(fp, "%*s", 6 - ret, " "); | ||
| 668 | printed += ret; | ||
| 669 | } | ||
| 670 | |||
| 627 | if (PRINT_FIELD(TIME)) { | 671 | if (PRINT_FIELD(TIME)) { |
| 628 | nsecs = sample->time; | 672 | nsecs = sample->time; |
| 629 | secs = nsecs / NSEC_PER_SEC; | 673 | secs = nsecs / NSEC_PER_SEC; |
| @@ -1502,7 +1546,7 @@ static void script_print_metric(void *ctx, const char *color, | |||
| 1502 | if (!fmt) | 1546 | if (!fmt) |
| 1503 | return; | 1547 | return; |
| 1504 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, | 1548 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, |
| 1505 | mctx->fp); | 1549 | PERF_RECORD_SAMPLE, mctx->fp); |
| 1506 | fputs("\tmetric: ", mctx->fp); | 1550 | fputs("\tmetric: ", mctx->fp); |
| 1507 | if (color) | 1551 | if (color) |
| 1508 | color_fprintf(mctx->fp, color, fmt, val); | 1552 | color_fprintf(mctx->fp, color, fmt, val); |
| @@ -1516,7 +1560,7 @@ static void script_new_line(void *ctx) | |||
| 1516 | struct metric_ctx *mctx = ctx; | 1560 | struct metric_ctx *mctx = ctx; |
| 1517 | 1561 | ||
| 1518 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, | 1562 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, |
| 1519 | mctx->fp); | 1563 | PERF_RECORD_SAMPLE, mctx->fp); |
| 1520 | fputs("\tmetric: ", mctx->fp); | 1564 | fputs("\tmetric: ", mctx->fp); |
| 1521 | } | 1565 | } |
| 1522 | 1566 | ||
| @@ -1584,7 +1628,8 @@ static void process_event(struct perf_script *script, | |||
| 1584 | 1628 | ||
| 1585 | ++es->samples; | 1629 | ++es->samples; |
| 1586 | 1630 | ||
| 1587 | perf_sample__fprintf_start(sample, thread, evsel, fp); | 1631 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1632 | PERF_RECORD_SAMPLE, fp); | ||
| 1588 | 1633 | ||
| 1589 | if (PRINT_FIELD(PERIOD)) | 1634 | if (PRINT_FIELD(PERIOD)) |
| 1590 | fprintf(fp, "%10" PRIu64 " ", sample->period); | 1635 | fprintf(fp, "%10" PRIu64 " ", sample->period); |
| @@ -1833,7 +1878,8 @@ static int process_comm_event(struct perf_tool *tool, | |||
| 1833 | sample->tid = event->comm.tid; | 1878 | sample->tid = event->comm.tid; |
| 1834 | sample->pid = event->comm.pid; | 1879 | sample->pid = event->comm.pid; |
| 1835 | } | 1880 | } |
| 1836 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 1881 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1882 | PERF_RECORD_COMM, stdout); | ||
| 1837 | perf_event__fprintf(event, stdout); | 1883 | perf_event__fprintf(event, stdout); |
| 1838 | ret = 0; | 1884 | ret = 0; |
| 1839 | out: | 1885 | out: |
| @@ -1868,7 +1914,8 @@ static int process_namespaces_event(struct perf_tool *tool, | |||
| 1868 | sample->tid = event->namespaces.tid; | 1914 | sample->tid = event->namespaces.tid; |
| 1869 | sample->pid = event->namespaces.pid; | 1915 | sample->pid = event->namespaces.pid; |
| 1870 | } | 1916 | } |
| 1871 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 1917 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1918 | PERF_RECORD_NAMESPACES, stdout); | ||
| 1872 | perf_event__fprintf(event, stdout); | 1919 | perf_event__fprintf(event, stdout); |
| 1873 | ret = 0; | 1920 | ret = 0; |
| 1874 | out: | 1921 | out: |
| @@ -1901,7 +1948,8 @@ static int process_fork_event(struct perf_tool *tool, | |||
| 1901 | sample->tid = event->fork.tid; | 1948 | sample->tid = event->fork.tid; |
| 1902 | sample->pid = event->fork.pid; | 1949 | sample->pid = event->fork.pid; |
| 1903 | } | 1950 | } |
| 1904 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 1951 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1952 | PERF_RECORD_FORK, stdout); | ||
| 1905 | perf_event__fprintf(event, stdout); | 1953 | perf_event__fprintf(event, stdout); |
| 1906 | thread__put(thread); | 1954 | thread__put(thread); |
| 1907 | 1955 | ||
| @@ -1930,7 +1978,8 @@ static int process_exit_event(struct perf_tool *tool, | |||
| 1930 | sample->tid = event->fork.tid; | 1978 | sample->tid = event->fork.tid; |
| 1931 | sample->pid = event->fork.pid; | 1979 | sample->pid = event->fork.pid; |
| 1932 | } | 1980 | } |
| 1933 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 1981 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1982 | PERF_RECORD_EXIT, stdout); | ||
| 1934 | perf_event__fprintf(event, stdout); | 1983 | perf_event__fprintf(event, stdout); |
| 1935 | 1984 | ||
| 1936 | if (perf_event__process_exit(tool, event, sample, machine) < 0) | 1985 | if (perf_event__process_exit(tool, event, sample, machine) < 0) |
| @@ -1965,7 +2014,8 @@ static int process_mmap_event(struct perf_tool *tool, | |||
| 1965 | sample->tid = event->mmap.tid; | 2014 | sample->tid = event->mmap.tid; |
| 1966 | sample->pid = event->mmap.pid; | 2015 | sample->pid = event->mmap.pid; |
| 1967 | } | 2016 | } |
| 1968 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 2017 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2018 | PERF_RECORD_MMAP, stdout); | ||
| 1969 | perf_event__fprintf(event, stdout); | 2019 | perf_event__fprintf(event, stdout); |
| 1970 | thread__put(thread); | 2020 | thread__put(thread); |
| 1971 | return 0; | 2021 | return 0; |
| @@ -1996,7 +2046,8 @@ static int process_mmap2_event(struct perf_tool *tool, | |||
| 1996 | sample->tid = event->mmap2.tid; | 2046 | sample->tid = event->mmap2.tid; |
| 1997 | sample->pid = event->mmap2.pid; | 2047 | sample->pid = event->mmap2.pid; |
| 1998 | } | 2048 | } |
| 1999 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 2049 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2050 | PERF_RECORD_MMAP2, stdout); | ||
| 2000 | perf_event__fprintf(event, stdout); | 2051 | perf_event__fprintf(event, stdout); |
| 2001 | thread__put(thread); | 2052 | thread__put(thread); |
| 2002 | return 0; | 2053 | return 0; |
| @@ -2022,7 +2073,8 @@ static int process_switch_event(struct perf_tool *tool, | |||
| 2022 | return -1; | 2073 | return -1; |
| 2023 | } | 2074 | } |
| 2024 | 2075 | ||
| 2025 | perf_sample__fprintf_start(sample, thread, evsel, stdout); | 2076 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2077 | PERF_RECORD_SWITCH, stdout); | ||
| 2026 | perf_event__fprintf(event, stdout); | 2078 | perf_event__fprintf(event, stdout); |
| 2027 | thread__put(thread); | 2079 | thread__put(thread); |
| 2028 | return 0; | 2080 | return 0; |
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 1ae95efbfb95..e5fbd6dd1b01 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
| @@ -205,6 +205,7 @@ struct perf_sample { | |||
| 205 | u32 flags; | 205 | u32 flags; |
| 206 | u16 insn_len; | 206 | u16 insn_len; |
| 207 | u8 cpumode; | 207 | u8 cpumode; |
| 208 | u16 misc; | ||
| 208 | char insn[MAX_INSN]; | 209 | char insn[MAX_INSN]; |
| 209 | void *raw_data; | 210 | void *raw_data; |
| 210 | struct ip_callchain *callchain; | 211 | struct ip_callchain *callchain; |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index c435b2444153..d934f04e3110 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
| @@ -2042,6 +2042,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, | |||
| 2042 | data->stream_id = data->id = data->time = -1ULL; | 2042 | data->stream_id = data->id = data->time = -1ULL; |
| 2043 | data->period = evsel->attr.sample_period; | 2043 | data->period = evsel->attr.sample_period; |
| 2044 | data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 2044 | data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 2045 | data->misc = event->header.misc; | ||
| 2045 | data->id = -1ULL; | 2046 | data->id = -1ULL; |
| 2046 | data->data_src = PERF_MEM_DATA_SRC_NONE; | 2047 | data->data_src = PERF_MEM_DATA_SRC_NONE; |
| 2047 | 2048 | ||
