Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 2 | #include "builtin.h" |
| 3 | |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 4 | #include "util/cache.h" |
Arnaldo Carvalho de Melo | 0f31c01 | 2019-08-21 14:00:17 -0300 | [diff] [blame] | 5 | #include "util/counts.h" |
Andrea Gelmini | b7eead8 | 2010-08-05 15:51:38 +0200 | [diff] [blame] | 6 | #include "util/debug.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 7 | #include <subcmd/exec-cmd.h> |
Andrea Gelmini | b7eead8 | 2010-08-05 15:51:38 +0200 | [diff] [blame] | 8 | #include "util/header.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 9 | #include <subcmd/parse-options.h> |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 10 | #include "util/perf_regs.h" |
Andrea Gelmini | b7eead8 | 2010-08-05 15:51:38 +0200 | [diff] [blame] | 11 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 12 | #include "util/tool.h" |
Arnaldo Carvalho de Melo | 1101f69 | 2019-01-27 13:42:37 +0100 | [diff] [blame] | 13 | #include "util/map.h" |
Arnaldo Carvalho de Melo | 97b9d86 | 2019-08-22 17:10:08 -0300 | [diff] [blame^] | 14 | #include "util/srcline.h" |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 15 | #include "util/symbol.h" |
| 16 | #include "util/thread.h" |
Ingo Molnar | cf72344 | 2009-11-28 10:11:00 +0100 | [diff] [blame] | 17 | #include "util/trace-event.h" |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 18 | #include "util/evlist.h" |
| 19 | #include "util/evsel.h" |
Arnaldo Carvalho de Melo | d236044 | 2019-08-15 10:37:24 -0300 | [diff] [blame] | 20 | #include "util/evswitch.h" |
Feng Tang | 36385be | 2012-09-07 16:42:24 +0800 | [diff] [blame] | 21 | #include "util/sort.h" |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 22 | #include "util/data.h" |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 23 | #include "util/auxtrace.h" |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 24 | #include "util/cpumap.h" |
| 25 | #include "util/thread_map.h" |
| 26 | #include "util/stat.h" |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 27 | #include "util/color.h" |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 28 | #include "util/string2.h" |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 29 | #include "util/thread-stack.h" |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 30 | #include "util/time-utils.h" |
Jiri Olsa | 06c3f2a | 2017-12-06 18:45:35 +0100 | [diff] [blame] | 31 | #include "util/path.h" |
Arnaldo Carvalho de Melo | fea0139 | 2017-04-17 16:23:22 -0300 | [diff] [blame] | 32 | #include "print_binary.h" |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 33 | #include "archinsn.h" |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 34 | #include <linux/bitmap.h> |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 35 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 6125cc8 | 2016-04-14 18:15:18 -0300 | [diff] [blame] | 36 | #include <linux/stringify.h> |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 37 | #include <linux/time64.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 38 | #include <linux/zalloc.h> |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 39 | #include <sys/utsname.h> |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 40 | #include "asm/bug.h" |
Jiri Olsa | c19ac91 | 2016-02-24 09:46:54 +0100 | [diff] [blame] | 41 | #include "util/mem-events.h" |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 42 | #include "util/dump-insn.h" |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 43 | #include <dirent.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 44 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 45 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | 9607ad3 | 2017-04-19 15:49:18 -0300 | [diff] [blame] | 46 | #include <signal.h> |
Arnaldo Carvalho de Melo | 391e420 | 2017-04-19 18:51:14 -0300 | [diff] [blame] | 47 | #include <sys/param.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 48 | #include <sys/types.h> |
| 49 | #include <sys/stat.h> |
Arnaldo Carvalho de Melo | bafae98 | 2018-01-22 16:42:16 -0300 | [diff] [blame] | 50 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 51 | #include <unistd.h> |
Andi Kleen | b585ebd | 2018-09-20 11:05:36 -0700 | [diff] [blame] | 52 | #include <subcmd/pager.h> |
Jiri Olsa | 453fa03 | 2019-07-21 13:24:43 +0200 | [diff] [blame] | 53 | #include <perf/evlist.h> |
Arnaldo Carvalho de Melo | aeb00b1 | 2019-08-22 15:40:29 -0300 | [diff] [blame] | 54 | #include "util/record.h" |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 55 | |
Arnaldo Carvalho de Melo | 3052ba5 | 2019-06-25 17:27:31 -0300 | [diff] [blame] | 56 | #include <linux/ctype.h> |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 57 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 58 | static char const *script_name; |
| 59 | static char const *generate_script_lang; |
Andi Kleen | 90b10f4 | 2019-03-14 15:50:00 -0700 | [diff] [blame] | 60 | static bool reltime; |
| 61 | static u64 initial_time; |
Frederic Weisbecker | ffabd99 | 2010-05-27 16:27:47 +0200 | [diff] [blame] | 62 | static bool debug_mode; |
Frederic Weisbecker | e1889d7 | 2010-04-24 01:55:09 +0200 | [diff] [blame] | 63 | static u64 last_timestamp; |
Frederic Weisbecker | 6fcf7dd | 2010-05-27 15:46:25 +0200 | [diff] [blame] | 64 | static u64 nr_unordered; |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 65 | static bool no_callchain; |
Namhyung Kim | 47390ae | 2013-06-04 14:20:28 +0900 | [diff] [blame] | 66 | static bool latency_format; |
Robert Richter | 317df65 | 2011-11-25 15:05:25 +0100 | [diff] [blame] | 67 | static bool system_wide; |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 68 | static bool print_flags; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 69 | static const char *cpu_list; |
| 70 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
Jiri Olsa | 91a2c3d | 2016-01-05 22:09:07 +0100 | [diff] [blame] | 71 | static struct perf_stat_config stat_config; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 72 | static int max_blocks; |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 73 | static bool native_arch; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 74 | |
Adrian Hunter | 44cbe72 | 2015-09-25 16:15:50 +0300 | [diff] [blame] | 75 | unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; |
Adrian Hunter | 03cd1fe | 2015-09-25 16:15:49 +0300 | [diff] [blame] | 76 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 77 | enum perf_output_field { |
| 78 | PERF_OUTPUT_COMM = 1U << 0, |
| 79 | PERF_OUTPUT_TID = 1U << 1, |
| 80 | PERF_OUTPUT_PID = 1U << 2, |
| 81 | PERF_OUTPUT_TIME = 1U << 3, |
| 82 | PERF_OUTPUT_CPU = 1U << 4, |
| 83 | PERF_OUTPUT_EVNAME = 1U << 5, |
| 84 | PERF_OUTPUT_TRACE = 1U << 6, |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 85 | PERF_OUTPUT_IP = 1U << 7, |
| 86 | PERF_OUTPUT_SYM = 1U << 8, |
David Ahern | 610723f | 2011-05-27 14:28:44 -0600 | [diff] [blame] | 87 | PERF_OUTPUT_DSO = 1U << 9, |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 88 | PERF_OUTPUT_ADDR = 1U << 10, |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 89 | PERF_OUTPUT_SYMOFFSET = 1U << 11, |
Adrian Hunter | cc8fae1 | 2013-12-06 09:42:57 +0200 | [diff] [blame] | 90 | PERF_OUTPUT_SRCLINE = 1U << 12, |
Jiri Olsa | 535aeaae | 2014-08-25 16:45:42 +0200 | [diff] [blame] | 91 | PERF_OUTPUT_PERIOD = 1U << 13, |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 92 | PERF_OUTPUT_IREGS = 1U << 14, |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 93 | PERF_OUTPUT_BRSTACK = 1U << 15, |
| 94 | PERF_OUTPUT_BRSTACKSYM = 1U << 16, |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 95 | PERF_OUTPUT_DATA_SRC = 1U << 17, |
| 96 | PERF_OUTPUT_WEIGHT = 1U << 18, |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 97 | PERF_OUTPUT_BPF_OUTPUT = 1U << 19, |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 98 | PERF_OUTPUT_CALLINDENT = 1U << 20, |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 99 | PERF_OUTPUT_INSN = 1U << 21, |
| 100 | PERF_OUTPUT_INSNLEN = 1U << 22, |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 101 | PERF_OUTPUT_BRSTACKINSN = 1U << 23, |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 102 | PERF_OUTPUT_BRSTACKOFF = 1U << 24, |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 103 | PERF_OUTPUT_SYNTH = 1U << 25, |
Kan Liang | 49d58f0 | 2017-08-29 13:11:11 -0400 | [diff] [blame] | 104 | PERF_OUTPUT_PHYS_ADDR = 1U << 26, |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 105 | PERF_OUTPUT_UREGS = 1U << 27, |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 106 | PERF_OUTPUT_METRIC = 1U << 28, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 107 | PERF_OUTPUT_MISC = 1U << 29, |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 108 | PERF_OUTPUT_SRCCODE = 1U << 30, |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 109 | PERF_OUTPUT_IPC = 1U << 31, |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct output_option { |
| 113 | const char *str; |
| 114 | enum perf_output_field field; |
| 115 | } all_output_options[] = { |
| 116 | {.str = "comm", .field = PERF_OUTPUT_COMM}, |
| 117 | {.str = "tid", .field = PERF_OUTPUT_TID}, |
| 118 | {.str = "pid", .field = PERF_OUTPUT_PID}, |
| 119 | {.str = "time", .field = PERF_OUTPUT_TIME}, |
| 120 | {.str = "cpu", .field = PERF_OUTPUT_CPU}, |
| 121 | {.str = "event", .field = PERF_OUTPUT_EVNAME}, |
| 122 | {.str = "trace", .field = PERF_OUTPUT_TRACE}, |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 123 | {.str = "ip", .field = PERF_OUTPUT_IP}, |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 124 | {.str = "sym", .field = PERF_OUTPUT_SYM}, |
David Ahern | 610723f | 2011-05-27 14:28:44 -0600 | [diff] [blame] | 125 | {.str = "dso", .field = PERF_OUTPUT_DSO}, |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 126 | {.str = "addr", .field = PERF_OUTPUT_ADDR}, |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 127 | {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, |
Adrian Hunter | cc8fae1 | 2013-12-06 09:42:57 +0200 | [diff] [blame] | 128 | {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, |
Jiri Olsa | 535aeaae | 2014-08-25 16:45:42 +0200 | [diff] [blame] | 129 | {.str = "period", .field = PERF_OUTPUT_PERIOD}, |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 130 | {.str = "iregs", .field = PERF_OUTPUT_IREGS}, |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 131 | {.str = "uregs", .field = PERF_OUTPUT_UREGS}, |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 132 | {.str = "brstack", .field = PERF_OUTPUT_BRSTACK}, |
| 133 | {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM}, |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 134 | {.str = "data_src", .field = PERF_OUTPUT_DATA_SRC}, |
| 135 | {.str = "weight", .field = PERF_OUTPUT_WEIGHT}, |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 136 | {.str = "bpf-output", .field = PERF_OUTPUT_BPF_OUTPUT}, |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 137 | {.str = "callindent", .field = PERF_OUTPUT_CALLINDENT}, |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 138 | {.str = "insn", .field = PERF_OUTPUT_INSN}, |
| 139 | {.str = "insnlen", .field = PERF_OUTPUT_INSNLEN}, |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 140 | {.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN}, |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 141 | {.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF}, |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 142 | {.str = "synth", .field = PERF_OUTPUT_SYNTH}, |
Kan Liang | 49d58f0 | 2017-08-29 13:11:11 -0400 | [diff] [blame] | 143 | {.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR}, |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 144 | {.str = "metric", .field = PERF_OUTPUT_METRIC}, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 145 | {.str = "misc", .field = PERF_OUTPUT_MISC}, |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 146 | {.str = "srccode", .field = PERF_OUTPUT_SRCCODE}, |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 147 | {.str = "ipc", .field = PERF_OUTPUT_IPC}, |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 150 | enum { |
| 151 | OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX, |
| 152 | OUTPUT_TYPE_MAX |
| 153 | }; |
| 154 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 155 | /* default set to maintain compatibility with current format */ |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 156 | static struct { |
| 157 | bool user_set; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 158 | bool wildcard_set; |
David Ahern | a6ffaf9 | 2013-08-07 22:50:51 -0400 | [diff] [blame] | 159 | unsigned int print_ip_opts; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 160 | u64 fields; |
| 161 | u64 invalid_fields; |
Andi Kleen | 4b6ac81 | 2019-02-24 07:37:12 -0800 | [diff] [blame] | 162 | u64 user_set_fields; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 163 | } output[OUTPUT_TYPE_MAX] = { |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 164 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 165 | [PERF_TYPE_HARDWARE] = { |
| 166 | .user_set = false, |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 167 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 168 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 169 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 170 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 171 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 172 | PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 173 | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 174 | .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 175 | }, |
| 176 | |
| 177 | [PERF_TYPE_SOFTWARE] = { |
| 178 | .user_set = false, |
| 179 | |
| 180 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 181 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 182 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 183 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 184 | PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD | |
| 185 | PERF_OUTPUT_BPF_OUTPUT, |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 186 | |
| 187 | .invalid_fields = PERF_OUTPUT_TRACE, |
| 188 | }, |
| 189 | |
| 190 | [PERF_TYPE_TRACEPOINT] = { |
| 191 | .user_set = false, |
| 192 | |
| 193 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 194 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 195 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 196 | }, |
Arun Sharma | 0817a6a | 2011-04-14 10:38:18 -0700 | [diff] [blame] | 197 | |
Seeteena Thoufeek | fad76d4 | 2018-06-08 16:32:28 +0530 | [diff] [blame] | 198 | [PERF_TYPE_HW_CACHE] = { |
| 199 | .user_set = false, |
| 200 | |
| 201 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 202 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
| 203 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
| 204 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 205 | PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, |
| 206 | |
| 207 | .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, |
| 208 | }, |
| 209 | |
Arun Sharma | 0817a6a | 2011-04-14 10:38:18 -0700 | [diff] [blame] | 210 | [PERF_TYPE_RAW] = { |
| 211 | .user_set = false, |
| 212 | |
| 213 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 214 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 215 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 216 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 217 | PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD | |
| 218 | PERF_OUTPUT_ADDR | PERF_OUTPUT_DATA_SRC | |
| 219 | PERF_OUTPUT_WEIGHT | PERF_OUTPUT_PHYS_ADDR, |
Arun Sharma | 0817a6a | 2011-04-14 10:38:18 -0700 | [diff] [blame] | 220 | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 221 | .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, |
Arun Sharma | 0817a6a | 2011-04-14 10:38:18 -0700 | [diff] [blame] | 222 | }, |
Wang Nan | 27cfef0 | 2015-12-08 02:25:43 +0000 | [diff] [blame] | 223 | |
| 224 | [PERF_TYPE_BREAKPOINT] = { |
| 225 | .user_set = false, |
| 226 | |
| 227 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 228 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
| 229 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 230 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 231 | PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD, |
Wang Nan | 27cfef0 | 2015-12-08 02:25:43 +0000 | [diff] [blame] | 232 | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 233 | .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, |
Wang Nan | 27cfef0 | 2015-12-08 02:25:43 +0000 | [diff] [blame] | 234 | }, |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 235 | |
| 236 | [OUTPUT_TYPE_SYNTH] = { |
| 237 | .user_set = false, |
| 238 | |
| 239 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | |
| 240 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | |
| 241 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 242 | PERF_OUTPUT_SYM | PERF_OUTPUT_SYMOFFSET | |
| 243 | PERF_OUTPUT_DSO | PERF_OUTPUT_SYNTH, |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 244 | |
| 245 | .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT, |
| 246 | }, |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 247 | }; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 248 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 249 | struct evsel_script { |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 250 | char *filename; |
| 251 | FILE *fp; |
| 252 | u64 samples; |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 253 | /* For metric output */ |
| 254 | u64 val; |
| 255 | int gnum; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 256 | }; |
| 257 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 258 | static inline struct evsel_script *evsel_script(struct evsel *evsel) |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 259 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 260 | return (struct evsel_script *)evsel->priv; |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 263 | static struct evsel_script *perf_evsel_script__new(struct evsel *evsel, |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 264 | struct perf_data *data) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 265 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 266 | struct evsel_script *es = zalloc(sizeof(*es)); |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 267 | |
| 268 | if (es != NULL) { |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 269 | if (asprintf(&es->filename, "%s.%s.dump", data->file.path, perf_evsel__name(evsel)) < 0) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 270 | goto out_free; |
| 271 | es->fp = fopen(es->filename, "w"); |
| 272 | if (es->fp == NULL) |
| 273 | goto out_free_filename; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return es; |
| 277 | out_free_filename: |
| 278 | zfree(&es->filename); |
| 279 | out_free: |
| 280 | free(es); |
| 281 | return NULL; |
| 282 | } |
| 283 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 284 | static void perf_evsel_script__delete(struct evsel_script *es) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 285 | { |
| 286 | zfree(&es->filename); |
| 287 | fclose(es->fp); |
| 288 | es->fp = NULL; |
| 289 | free(es); |
| 290 | } |
| 291 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 292 | static int perf_evsel_script__fprintf(struct evsel_script *es, FILE *fp) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 293 | { |
| 294 | struct stat st; |
| 295 | |
| 296 | fstat(fileno(es->fp), &st); |
| 297 | return fprintf(fp, "[ perf script: Wrote %.3f MB %s (%" PRIu64 " samples) ]\n", |
| 298 | st.st_size / 1024.0 / 1024.0, es->filename, es->samples); |
| 299 | } |
| 300 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 301 | static inline int output_type(unsigned int type) |
| 302 | { |
| 303 | switch (type) { |
| 304 | case PERF_TYPE_SYNTH: |
| 305 | return OUTPUT_TYPE_SYNTH; |
| 306 | default: |
| 307 | return type; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | static inline unsigned int attr_type(unsigned int type) |
| 312 | { |
| 313 | switch (type) { |
| 314 | case OUTPUT_TYPE_SYNTH: |
| 315 | return PERF_TYPE_SYNTH; |
| 316 | default: |
| 317 | return type; |
| 318 | } |
| 319 | } |
| 320 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 321 | static bool output_set_by_user(void) |
| 322 | { |
| 323 | int j; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 324 | for (j = 0; j < OUTPUT_TYPE_MAX; ++j) { |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 325 | if (output[j].user_set) |
| 326 | return true; |
| 327 | } |
| 328 | return false; |
| 329 | } |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 330 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 331 | static const char *output_field2str(enum perf_output_field field) |
| 332 | { |
| 333 | int i, imax = ARRAY_SIZE(all_output_options); |
| 334 | const char *str = ""; |
| 335 | |
| 336 | for (i = 0; i < imax; ++i) { |
| 337 | if (all_output_options[i].field == field) { |
| 338 | str = all_output_options[i].str; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | return str; |
| 343 | } |
| 344 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 345 | #define PRINT_FIELD(x) (output[output_type(attr->type)].fields & PERF_OUTPUT_##x) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 346 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 347 | static int perf_evsel__do_check_stype(struct evsel *evsel, |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 348 | u64 sample_type, const char *sample_msg, |
| 349 | enum perf_output_field field, |
| 350 | bool allow_user_set) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 351 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 352 | struct perf_event_attr *attr = &evsel->core.attr; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 353 | int type = output_type(attr->type); |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 354 | const char *evname; |
| 355 | |
| 356 | if (attr->sample_type & sample_type) |
| 357 | return 0; |
| 358 | |
Andi Kleen | 4b6ac81 | 2019-02-24 07:37:12 -0800 | [diff] [blame] | 359 | if (output[type].user_set_fields & field) { |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 360 | if (allow_user_set) |
| 361 | return 0; |
Arnaldo Carvalho de Melo | 5bff01f | 2012-06-12 13:35:44 -0300 | [diff] [blame] | 362 | evname = perf_evsel__name(evsel); |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 363 | pr_err("Samples for '%s' event do not have %s attribute set. " |
| 364 | "Cannot print '%s' field.\n", |
| 365 | evname, sample_msg, output_field2str(field)); |
| 366 | return -1; |
| 367 | } |
| 368 | |
| 369 | /* user did not ask for it explicitly so remove from the default list */ |
| 370 | output[type].fields &= ~field; |
Arnaldo Carvalho de Melo | 5bff01f | 2012-06-12 13:35:44 -0300 | [diff] [blame] | 371 | evname = perf_evsel__name(evsel); |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 372 | pr_debug("Samples for '%s' event do not have %s attribute set. " |
| 373 | "Skipping '%s' field.\n", |
| 374 | evname, sample_msg, output_field2str(field)); |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 379 | static int perf_evsel__check_stype(struct evsel *evsel, |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 380 | u64 sample_type, const char *sample_msg, |
| 381 | enum perf_output_field field) |
| 382 | { |
| 383 | return perf_evsel__do_check_stype(evsel, sample_type, sample_msg, field, |
| 384 | false); |
| 385 | } |
| 386 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 387 | static int perf_evsel__check_attr(struct evsel *evsel, |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 388 | struct perf_session *session) |
| 389 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 390 | struct perf_event_attr *attr = &evsel->core.attr; |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 391 | bool allow_user_set; |
| 392 | |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 393 | if (perf_header__has_feat(&session->header, HEADER_STAT)) |
| 394 | return 0; |
| 395 | |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 396 | allow_user_set = perf_header__has_feat(&session->header, |
| 397 | HEADER_AUXTRACE); |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 398 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 399 | if (PRINT_FIELD(TRACE) && |
| 400 | !perf_session__has_traces(session, "record -R")) |
| 401 | return -EINVAL; |
| 402 | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 403 | if (PRINT_FIELD(IP)) { |
Arnaldo Carvalho de Melo | 5bff01f | 2012-06-12 13:35:44 -0300 | [diff] [blame] | 404 | if (perf_evsel__check_stype(evsel, PERF_SAMPLE_IP, "IP", |
| 405 | PERF_OUTPUT_IP)) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 406 | return -EINVAL; |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 407 | } |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 408 | |
| 409 | if (PRINT_FIELD(ADDR) && |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 410 | perf_evsel__do_check_stype(evsel, PERF_SAMPLE_ADDR, "ADDR", |
| 411 | PERF_OUTPUT_ADDR, allow_user_set)) |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 412 | return -EINVAL; |
| 413 | |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 414 | if (PRINT_FIELD(DATA_SRC) && |
| 415 | perf_evsel__check_stype(evsel, PERF_SAMPLE_DATA_SRC, "DATA_SRC", |
| 416 | PERF_OUTPUT_DATA_SRC)) |
| 417 | return -EINVAL; |
| 418 | |
| 419 | if (PRINT_FIELD(WEIGHT) && |
| 420 | perf_evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT, "WEIGHT", |
| 421 | PERF_OUTPUT_WEIGHT)) |
| 422 | return -EINVAL; |
| 423 | |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 424 | if (PRINT_FIELD(SYM) && |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 425 | !(evsel->core.attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) { |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 426 | pr_err("Display of symbols requested but neither sample IP nor " |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 427 | "sample address\navailable. Hence, no addresses to convert " |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 428 | "to symbols.\n"); |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 429 | return -EINVAL; |
| 430 | } |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 431 | if (PRINT_FIELD(SYMOFFSET) && !PRINT_FIELD(SYM)) { |
| 432 | pr_err("Display of offsets requested but symbol is not" |
| 433 | "selected.\n"); |
| 434 | return -EINVAL; |
| 435 | } |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 436 | if (PRINT_FIELD(DSO) && |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 437 | !(evsel->core.attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) { |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 438 | pr_err("Display of DSO requested but no address to convert.\n"); |
David Ahern | 610723f | 2011-05-27 14:28:44 -0600 | [diff] [blame] | 439 | return -EINVAL; |
| 440 | } |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 441 | if ((PRINT_FIELD(SRCLINE) || PRINT_FIELD(SRCCODE)) && !PRINT_FIELD(IP)) { |
Adrian Hunter | cc8fae1 | 2013-12-06 09:42:57 +0200 | [diff] [blame] | 442 | pr_err("Display of source line number requested but sample IP is not\n" |
| 443 | "selected. Hence, no address to lookup the source line number.\n"); |
| 444 | return -EINVAL; |
| 445 | } |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 446 | if (PRINT_FIELD(BRSTACKINSN) && |
| 447 | !(perf_evlist__combined_branch_type(session->evlist) & |
| 448 | PERF_SAMPLE_BRANCH_ANY)) { |
| 449 | pr_err("Display of branch stack assembler requested, but non all-branch filter set\n" |
| 450 | "Hint: run 'perf record -b ...'\n"); |
| 451 | return -EINVAL; |
| 452 | } |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 453 | if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) && |
Arnaldo Carvalho de Melo | 5bff01f | 2012-06-12 13:35:44 -0300 | [diff] [blame] | 454 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID", |
| 455 | PERF_OUTPUT_TID|PERF_OUTPUT_PID)) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 456 | return -EINVAL; |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 457 | |
| 458 | if (PRINT_FIELD(TIME) && |
Arnaldo Carvalho de Melo | 5bff01f | 2012-06-12 13:35:44 -0300 | [diff] [blame] | 459 | perf_evsel__check_stype(evsel, PERF_SAMPLE_TIME, "TIME", |
| 460 | PERF_OUTPUT_TIME)) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 461 | return -EINVAL; |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 462 | |
| 463 | if (PRINT_FIELD(CPU) && |
Adrian Hunter | 6d5cdd6 | 2015-04-24 22:29:44 +0300 | [diff] [blame] | 464 | perf_evsel__do_check_stype(evsel, PERF_SAMPLE_CPU, "CPU", |
| 465 | PERF_OUTPUT_CPU, allow_user_set)) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 466 | return -EINVAL; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 467 | |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 468 | if (PRINT_FIELD(IREGS) && |
| 469 | perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS", |
| 470 | PERF_OUTPUT_IREGS)) |
| 471 | return -EINVAL; |
| 472 | |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 473 | if (PRINT_FIELD(UREGS) && |
| 474 | perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_USER, "UREGS", |
| 475 | PERF_OUTPUT_UREGS)) |
| 476 | return -EINVAL; |
| 477 | |
Kan Liang | 49d58f0 | 2017-08-29 13:11:11 -0400 | [diff] [blame] | 478 | if (PRINT_FIELD(PHYS_ADDR) && |
| 479 | perf_evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", |
| 480 | PERF_OUTPUT_PHYS_ADDR)) |
| 481 | return -EINVAL; |
| 482 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 486 | static void set_print_ip_opts(struct perf_event_attr *attr) |
| 487 | { |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 488 | unsigned int type = output_type(attr->type); |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 489 | |
| 490 | output[type].print_ip_opts = 0; |
| 491 | if (PRINT_FIELD(IP)) |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 492 | output[type].print_ip_opts |= EVSEL__PRINT_IP; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 493 | |
| 494 | if (PRINT_FIELD(SYM)) |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 495 | output[type].print_ip_opts |= EVSEL__PRINT_SYM; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 496 | |
| 497 | if (PRINT_FIELD(DSO)) |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 498 | output[type].print_ip_opts |= EVSEL__PRINT_DSO; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 499 | |
| 500 | if (PRINT_FIELD(SYMOFFSET)) |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 501 | output[type].print_ip_opts |= EVSEL__PRINT_SYMOFFSET; |
Adrian Hunter | cc8fae1 | 2013-12-06 09:42:57 +0200 | [diff] [blame] | 502 | |
| 503 | if (PRINT_FIELD(SRCLINE)) |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 504 | output[type].print_ip_opts |= EVSEL__PRINT_SRCLINE; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 505 | } |
| 506 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 507 | /* |
| 508 | * verify all user requested events exist and the samples |
| 509 | * have the expected data |
| 510 | */ |
| 511 | static int perf_session__check_output_opt(struct perf_session *session) |
| 512 | { |
He Kuang | 40f20e5 | 2016-05-16 04:51:19 +0000 | [diff] [blame] | 513 | unsigned int j; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 514 | struct evsel *evsel; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 515 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 516 | for (j = 0; j < OUTPUT_TYPE_MAX; ++j) { |
| 517 | evsel = perf_session__find_first_evtype(session, attr_type(j)); |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 518 | |
| 519 | /* |
| 520 | * even if fields is set to 0 (ie., show nothing) event must |
| 521 | * exist if user explicitly includes it on the command line |
| 522 | */ |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 523 | if (!evsel && output[j].user_set && !output[j].wildcard_set && |
| 524 | j != OUTPUT_TYPE_SYNTH) { |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 525 | pr_err("%s events do not exist. " |
Adrian Hunter | 701516a | 2017-05-26 11:17:20 +0300 | [diff] [blame] | 526 | "Remove corresponding -F option to proceed.\n", |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 527 | event_type(j)); |
| 528 | return -1; |
| 529 | } |
| 530 | |
| 531 | if (evsel && output[j].fields && |
| 532 | perf_evsel__check_attr(evsel, session)) |
| 533 | return -1; |
David Ahern | a6ffaf9 | 2013-08-07 22:50:51 -0400 | [diff] [blame] | 534 | |
| 535 | if (evsel == NULL) |
| 536 | continue; |
| 537 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 538 | set_print_ip_opts(&evsel->core.attr); |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Adrian Hunter | 98526ee | 2014-07-31 09:00:59 +0300 | [diff] [blame] | 541 | if (!no_callchain) { |
| 542 | bool use_callchain = false; |
He Kuang | 71ac899 | 2016-08-04 11:25:43 +0000 | [diff] [blame] | 543 | bool not_pipe = false; |
Adrian Hunter | 98526ee | 2014-07-31 09:00:59 +0300 | [diff] [blame] | 544 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 545 | evlist__for_each_entry(session->evlist, evsel) { |
He Kuang | 71ac899 | 2016-08-04 11:25:43 +0000 | [diff] [blame] | 546 | not_pipe = true; |
Arnaldo Carvalho de Melo | 27de9b2 | 2018-05-28 16:00:29 -0300 | [diff] [blame] | 547 | if (evsel__has_callchain(evsel)) { |
Adrian Hunter | 98526ee | 2014-07-31 09:00:59 +0300 | [diff] [blame] | 548 | use_callchain = true; |
| 549 | break; |
| 550 | } |
| 551 | } |
He Kuang | 71ac899 | 2016-08-04 11:25:43 +0000 | [diff] [blame] | 552 | if (not_pipe && !use_callchain) |
Adrian Hunter | 98526ee | 2014-07-31 09:00:59 +0300 | [diff] [blame] | 553 | symbol_conf.use_callchain = false; |
| 554 | } |
| 555 | |
David Ahern | 80b8b49 | 2013-11-19 21:07:37 -0700 | [diff] [blame] | 556 | /* |
| 557 | * set default for tracepoints to print symbols only |
| 558 | * if callchains are present |
| 559 | */ |
| 560 | if (symbol_conf.use_callchain && |
| 561 | !output[PERF_TYPE_TRACEPOINT].user_set) { |
David Ahern | 80b8b49 | 2013-11-19 21:07:37 -0700 | [diff] [blame] | 562 | j = PERF_TYPE_TRACEPOINT; |
David Ahern | 80b8b49 | 2013-11-19 21:07:37 -0700 | [diff] [blame] | 563 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 564 | evlist__for_each_entry(session->evlist, evsel) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 565 | if (evsel->core.attr.type != j) |
He Kuang | 40f20e5 | 2016-05-16 04:51:19 +0000 | [diff] [blame] | 566 | continue; |
David Ahern | 80b8b49 | 2013-11-19 21:07:37 -0700 | [diff] [blame] | 567 | |
Arnaldo Carvalho de Melo | 27de9b2 | 2018-05-28 16:00:29 -0300 | [diff] [blame] | 568 | if (evsel__has_callchain(evsel)) { |
He Kuang | 40f20e5 | 2016-05-16 04:51:19 +0000 | [diff] [blame] | 569 | output[j].fields |= PERF_OUTPUT_IP; |
| 570 | output[j].fields |= PERF_OUTPUT_SYM; |
Sandipan Das | 7903a70 | 2018-05-17 12:03:26 +0530 | [diff] [blame] | 571 | output[j].fields |= PERF_OUTPUT_SYMOFFSET; |
He Kuang | 40f20e5 | 2016-05-16 04:51:19 +0000 | [diff] [blame] | 572 | output[j].fields |= PERF_OUTPUT_DSO; |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 573 | set_print_ip_opts(&evsel->core.attr); |
He Kuang | 40f20e5 | 2016-05-16 04:51:19 +0000 | [diff] [blame] | 574 | goto out; |
| 575 | } |
David Ahern | 80b8b49 | 2013-11-19 21:07:37 -0700 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | out: |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 580 | return 0; |
| 581 | } |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 582 | |
Milian Wolff | 9add8fe | 2018-11-07 23:34:37 +0100 | [diff] [blame] | 583 | static int perf_sample__fprintf_regs(struct regs_dump *regs, uint64_t mask, |
| 584 | FILE *fp |
| 585 | ) |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 586 | { |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 587 | unsigned i = 0, r; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 588 | int printed = 0; |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 589 | |
| 590 | if (!regs || !regs->regs) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 591 | return 0; |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 592 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 593 | printed += fprintf(fp, " ABI:%" PRIu64 " ", regs->abi); |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 594 | |
| 595 | for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { |
| 596 | u64 val = regs->regs[i++]; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 597 | printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val); |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 598 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 599 | |
Milian Wolff | b07d16f | 2018-11-07 10:37:05 +0100 | [diff] [blame] | 600 | fprintf(fp, "\n"); |
| 601 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 602 | return printed; |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Milian Wolff | 9add8fe | 2018-11-07 23:34:37 +0100 | [diff] [blame] | 605 | static int perf_sample__fprintf_iregs(struct perf_sample *sample, |
| 606 | struct perf_event_attr *attr, FILE *fp) |
| 607 | { |
| 608 | return perf_sample__fprintf_regs(&sample->intr_regs, |
| 609 | attr->sample_regs_intr, fp); |
| 610 | } |
| 611 | |
| 612 | static int perf_sample__fprintf_uregs(struct perf_sample *sample, |
| 613 | struct perf_event_attr *attr, FILE *fp) |
| 614 | { |
| 615 | return perf_sample__fprintf_regs(&sample->user_regs, |
| 616 | attr->sample_regs_user, fp); |
| 617 | } |
| 618 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 619 | static int perf_sample__fprintf_start(struct perf_sample *sample, |
| 620 | struct thread *thread, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 621 | struct evsel *evsel, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 622 | u32 type, FILE *fp) |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 623 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 624 | struct perf_event_attr *attr = &evsel->core.attr; |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 625 | unsigned long secs; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 626 | unsigned long long nsecs; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 627 | int printed = 0; |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 628 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 629 | if (PRINT_FIELD(COMM)) { |
| 630 | if (latency_format) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 631 | printed += fprintf(fp, "%8.8s ", thread__comm_str(thread)); |
Arnaldo Carvalho de Melo | b879833 | 2018-06-04 10:34:20 -0300 | [diff] [blame] | 632 | else if (PRINT_FIELD(IP) && evsel__has_callchain(evsel) && symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 633 | printed += fprintf(fp, "%s ", thread__comm_str(thread)); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 634 | else |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 635 | printed += fprintf(fp, "%16s ", thread__comm_str(thread)); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 636 | } |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 637 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 638 | if (PRINT_FIELD(PID) && PRINT_FIELD(TID)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 639 | printed += fprintf(fp, "%5d/%-5d ", sample->pid, sample->tid); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 640 | else if (PRINT_FIELD(PID)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 641 | printed += fprintf(fp, "%5d ", sample->pid); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 642 | else if (PRINT_FIELD(TID)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 643 | printed += fprintf(fp, "%5d ", sample->tid); |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 644 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 645 | if (PRINT_FIELD(CPU)) { |
| 646 | if (latency_format) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 647 | printed += fprintf(fp, "%3d ", sample->cpu); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 648 | else |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 649 | printed += fprintf(fp, "[%03d] ", sample->cpu); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 650 | } |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 651 | |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 652 | if (PRINT_FIELD(MISC)) { |
| 653 | int ret = 0; |
| 654 | |
| 655 | #define has(m) \ |
| 656 | (sample->misc & PERF_RECORD_MISC_##m) == PERF_RECORD_MISC_##m |
| 657 | |
| 658 | if (has(KERNEL)) |
| 659 | ret += fprintf(fp, "K"); |
| 660 | if (has(USER)) |
| 661 | ret += fprintf(fp, "U"); |
| 662 | if (has(HYPERVISOR)) |
| 663 | ret += fprintf(fp, "H"); |
| 664 | if (has(GUEST_KERNEL)) |
| 665 | ret += fprintf(fp, "G"); |
| 666 | if (has(GUEST_USER)) |
| 667 | ret += fprintf(fp, "g"); |
| 668 | |
| 669 | switch (type) { |
| 670 | case PERF_RECORD_MMAP: |
| 671 | case PERF_RECORD_MMAP2: |
| 672 | if (has(MMAP_DATA)) |
| 673 | ret += fprintf(fp, "M"); |
| 674 | break; |
| 675 | case PERF_RECORD_COMM: |
| 676 | if (has(COMM_EXEC)) |
| 677 | ret += fprintf(fp, "E"); |
| 678 | break; |
| 679 | case PERF_RECORD_SWITCH: |
| 680 | case PERF_RECORD_SWITCH_CPU_WIDE: |
Alexey Budankov | bf30cc1 | 2018-04-09 10:26:46 +0300 | [diff] [blame] | 681 | if (has(SWITCH_OUT)) { |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 682 | ret += fprintf(fp, "S"); |
Alexey Budankov | bf30cc1 | 2018-04-09 10:26:46 +0300 | [diff] [blame] | 683 | if (sample->misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT) |
| 684 | ret += fprintf(fp, "p"); |
| 685 | } |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 686 | default: |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | #undef has |
| 691 | |
| 692 | ret += fprintf(fp, "%*s", 6 - ret, " "); |
| 693 | printed += ret; |
| 694 | } |
| 695 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 696 | if (PRINT_FIELD(TIME)) { |
Andi Kleen | 90b10f4 | 2019-03-14 15:50:00 -0700 | [diff] [blame] | 697 | u64 t = sample->time; |
| 698 | if (reltime) { |
| 699 | if (!initial_time) |
| 700 | initial_time = sample->time; |
| 701 | t = sample->time - initial_time; |
| 702 | } |
| 703 | nsecs = t; |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 704 | secs = nsecs / NSEC_PER_SEC; |
| 705 | nsecs -= secs * NSEC_PER_SEC; |
Namhyung Kim | 99620a5 | 2016-10-24 11:02:45 +0900 | [diff] [blame] | 706 | |
Andi Kleen | 52bab88 | 2019-03-05 06:47:47 -0800 | [diff] [blame] | 707 | if (symbol_conf.nanosecs) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 708 | printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs); |
Namhyung Kim | 99620a5 | 2016-10-24 11:02:45 +0900 | [diff] [blame] | 709 | else { |
| 710 | char sample_time[32]; |
Andi Kleen | 90b10f4 | 2019-03-14 15:50:00 -0700 | [diff] [blame] | 711 | timestamp__scnprintf_usec(t, sample_time, sizeof(sample_time)); |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 712 | printed += fprintf(fp, "%12s: ", sample_time); |
Namhyung Kim | 99620a5 | 2016-10-24 11:02:45 +0900 | [diff] [blame] | 713 | } |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 714 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 715 | |
| 716 | return printed; |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 719 | static inline char |
| 720 | mispred_str(struct branch_entry *br) |
| 721 | { |
| 722 | if (!(br->flags.mispred || br->flags.predicted)) |
| 723 | return '-'; |
| 724 | |
| 725 | return br->flags.predicted ? 'P' : 'M'; |
| 726 | } |
| 727 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 728 | static int perf_sample__fprintf_brstack(struct perf_sample *sample, |
| 729 | struct thread *thread, |
| 730 | struct perf_event_attr *attr, FILE *fp) |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 731 | { |
| 732 | struct branch_stack *br = sample->branch_stack; |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 733 | struct addr_location alf, alt; |
| 734 | u64 i, from, to; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 735 | int printed = 0; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 736 | |
| 737 | if (!(br && br->nr)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 738 | return 0; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 739 | |
| 740 | for (i = 0; i < br->nr; i++) { |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 741 | from = br->entries[i].from; |
| 742 | to = br->entries[i].to; |
| 743 | |
| 744 | if (PRINT_FIELD(DSO)) { |
| 745 | memset(&alf, 0, sizeof(alf)); |
| 746 | memset(&alt, 0, sizeof(alt)); |
Adrian Hunter | 692d0e6 | 2018-11-06 23:07:12 +0200 | [diff] [blame] | 747 | thread__find_map_fb(thread, sample->cpumode, from, &alf); |
| 748 | thread__find_map_fb(thread, sample->cpumode, to, &alt); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 751 | printed += fprintf(fp, " 0x%"PRIx64, from); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 752 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 753 | printed += fprintf(fp, "("); |
| 754 | printed += map__fprintf_dsoname(alf.map, fp); |
| 755 | printed += fprintf(fp, ")"); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 758 | printed += fprintf(fp, "/0x%"PRIx64, to); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 759 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 760 | printed += fprintf(fp, "("); |
| 761 | printed += map__fprintf_dsoname(alt.map, fp); |
| 762 | printed += fprintf(fp, ")"); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 765 | printed += fprintf(fp, "/%c/%c/%c/%d ", |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 766 | mispred_str( br->entries + i), |
| 767 | br->entries[i].flags.in_tx? 'X' : '-', |
| 768 | br->entries[i].flags.abort? 'A' : '-', |
| 769 | br->entries[i].flags.cycles); |
| 770 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 771 | |
| 772 | return printed; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 773 | } |
| 774 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 775 | static int perf_sample__fprintf_brstacksym(struct perf_sample *sample, |
| 776 | struct thread *thread, |
| 777 | struct perf_event_attr *attr, FILE *fp) |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 778 | { |
| 779 | struct branch_stack *br = sample->branch_stack; |
| 780 | struct addr_location alf, alt; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 781 | u64 i, from, to; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 782 | int printed = 0; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 783 | |
| 784 | if (!(br && br->nr)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 785 | return 0; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 786 | |
| 787 | for (i = 0; i < br->nr; i++) { |
| 788 | |
| 789 | memset(&alf, 0, sizeof(alf)); |
| 790 | memset(&alt, 0, sizeof(alt)); |
| 791 | from = br->entries[i].from; |
| 792 | to = br->entries[i].to; |
| 793 | |
Adrian Hunter | 692d0e6 | 2018-11-06 23:07:12 +0200 | [diff] [blame] | 794 | thread__find_symbol_fb(thread, sample->cpumode, from, &alf); |
| 795 | thread__find_symbol_fb(thread, sample->cpumode, to, &alt); |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 796 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 797 | printed += symbol__fprintf_symname_offs(alf.sym, &alf, fp); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 798 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 799 | printed += fprintf(fp, "("); |
| 800 | printed += map__fprintf_dsoname(alf.map, fp); |
| 801 | printed += fprintf(fp, ")"); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 802 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 803 | printed += fprintf(fp, "%c", '/'); |
| 804 | printed += symbol__fprintf_symname_offs(alt.sym, &alt, fp); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 805 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 806 | printed += fprintf(fp, "("); |
| 807 | printed += map__fprintf_dsoname(alt.map, fp); |
| 808 | printed += fprintf(fp, ")"); |
Mark Santaniello | 55b9b50 | 2017-06-19 09:38:24 -0700 | [diff] [blame] | 809 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 810 | printed += fprintf(fp, "/%c/%c/%c/%d ", |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 811 | mispred_str( br->entries + i), |
| 812 | br->entries[i].flags.in_tx? 'X' : '-', |
| 813 | br->entries[i].flags.abort? 'A' : '-', |
| 814 | br->entries[i].flags.cycles); |
| 815 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 816 | |
| 817 | return printed; |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 818 | } |
| 819 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 820 | static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, |
| 821 | struct thread *thread, |
| 822 | struct perf_event_attr *attr, FILE *fp) |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 823 | { |
| 824 | struct branch_stack *br = sample->branch_stack; |
| 825 | struct addr_location alf, alt; |
| 826 | u64 i, from, to; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 827 | int printed = 0; |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 828 | |
| 829 | if (!(br && br->nr)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 830 | return 0; |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 831 | |
| 832 | for (i = 0; i < br->nr; i++) { |
| 833 | |
| 834 | memset(&alf, 0, sizeof(alf)); |
| 835 | memset(&alt, 0, sizeof(alt)); |
| 836 | from = br->entries[i].from; |
| 837 | to = br->entries[i].to; |
| 838 | |
Adrian Hunter | 692d0e6 | 2018-11-06 23:07:12 +0200 | [diff] [blame] | 839 | if (thread__find_map_fb(thread, sample->cpumode, from, &alf) && |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 840 | !alf.map->dso->adjust_symbols) |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 841 | from = map__map_ip(alf.map, from); |
| 842 | |
Adrian Hunter | 692d0e6 | 2018-11-06 23:07:12 +0200 | [diff] [blame] | 843 | if (thread__find_map_fb(thread, sample->cpumode, to, &alt) && |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 844 | !alt.map->dso->adjust_symbols) |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 845 | to = map__map_ip(alt.map, to); |
| 846 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 847 | printed += fprintf(fp, " 0x%"PRIx64, from); |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 848 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 849 | printed += fprintf(fp, "("); |
| 850 | printed += map__fprintf_dsoname(alf.map, fp); |
| 851 | printed += fprintf(fp, ")"); |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 852 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 853 | printed += fprintf(fp, "/0x%"PRIx64, to); |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 854 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 855 | printed += fprintf(fp, "("); |
| 856 | printed += map__fprintf_dsoname(alt.map, fp); |
| 857 | printed += fprintf(fp, ")"); |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 858 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 859 | printed += fprintf(fp, "/%c/%c/%c/%d ", |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 860 | mispred_str(br->entries + i), |
| 861 | br->entries[i].flags.in_tx ? 'X' : '-', |
| 862 | br->entries[i].flags.abort ? 'A' : '-', |
| 863 | br->entries[i].flags.cycles); |
| 864 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 865 | |
| 866 | return printed; |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 867 | } |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 868 | #define MAXBB 16384UL |
| 869 | |
| 870 | static int grab_bb(u8 *buffer, u64 start, u64 end, |
| 871 | struct machine *machine, struct thread *thread, |
| 872 | bool *is64bit, u8 *cpumode, bool last) |
| 873 | { |
| 874 | long offset, len; |
| 875 | struct addr_location al; |
| 876 | bool kernel; |
| 877 | |
| 878 | if (!start || !end) |
| 879 | return 0; |
| 880 | |
| 881 | kernel = machine__kernel_ip(machine, start); |
| 882 | if (kernel) |
| 883 | *cpumode = PERF_RECORD_MISC_KERNEL; |
| 884 | else |
| 885 | *cpumode = PERF_RECORD_MISC_USER; |
| 886 | |
| 887 | /* |
| 888 | * Block overlaps between kernel and user. |
| 889 | * This can happen due to ring filtering |
| 890 | * On Intel CPUs the entry into the kernel is filtered, |
| 891 | * but the exit is not. Let the caller patch it up. |
| 892 | */ |
| 893 | if (kernel != machine__kernel_ip(machine, end)) { |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 894 | pr_debug("\tblock %" PRIx64 "-%" PRIx64 " transfers between kernel and user\n", start, end); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 895 | return -ENXIO; |
| 896 | } |
| 897 | |
| 898 | memset(&al, 0, sizeof(al)); |
| 899 | if (end - start > MAXBB - MAXINSN) { |
| 900 | if (last) |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 901 | pr_debug("\tbrstack does not reach to final jump (%" PRIx64 "-%" PRIx64 ")\n", start, end); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 902 | else |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 903 | pr_debug("\tblock %" PRIx64 "-%" PRIx64 " (%" PRIu64 ") too long to dump\n", start, end, end - start); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 907 | if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) { |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 908 | pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 909 | return 0; |
| 910 | } |
| 911 | if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) { |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 912 | pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | /* Load maps to ensure dso->is_64_bit has been updated */ |
| 917 | map__load(al.map); |
| 918 | |
| 919 | offset = al.map->map_ip(al.map, start); |
| 920 | len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer, |
| 921 | end - start + MAXINSN); |
| 922 | |
| 923 | *is64bit = al.map->dso->is_64_bit; |
| 924 | if (len <= 0) |
Arnaldo Carvalho de Melo | 5ce2c5b | 2017-10-26 09:55:22 -0300 | [diff] [blame] | 925 | pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n", |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 926 | start, end); |
| 927 | return len; |
| 928 | } |
| 929 | |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 930 | static int print_srccode(struct thread *thread, u8 cpumode, uint64_t addr) |
| 931 | { |
| 932 | struct addr_location al; |
| 933 | int ret = 0; |
| 934 | |
| 935 | memset(&al, 0, sizeof(al)); |
| 936 | thread__find_map(thread, cpumode, addr, &al); |
| 937 | if (!al.map) |
| 938 | return 0; |
| 939 | ret = map__fprintf_srccode(al.map, al.addr, stdout, |
| 940 | &thread->srccode_state); |
| 941 | if (ret) |
| 942 | ret += printf("\n"); |
| 943 | return ret; |
| 944 | } |
| 945 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 946 | static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en, |
| 947 | struct perf_insn *x, u8 *inbuf, int len, |
Andi Kleen | fe57120 | 2018-09-24 10:07:32 -0700 | [diff] [blame] | 948 | int insn, FILE *fp, int *total_cycles) |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 949 | { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 950 | int printed = fprintf(fp, "\t%016" PRIx64 "\t%-30s\t#%s%s%s%s", ip, |
| 951 | dump_insn(x, ip, inbuf, len, NULL), |
| 952 | en->flags.predicted ? " PRED" : "", |
| 953 | en->flags.mispred ? " MISPRED" : "", |
| 954 | en->flags.in_tx ? " INTX" : "", |
| 955 | en->flags.abort ? " ABORT" : ""); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 956 | if (en->flags.cycles) { |
Andi Kleen | fe57120 | 2018-09-24 10:07:32 -0700 | [diff] [blame] | 957 | *total_cycles += en->flags.cycles; |
| 958 | printed += fprintf(fp, " %d cycles [%d]", en->flags.cycles, *total_cycles); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 959 | if (insn) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 960 | printed += fprintf(fp, " %.2f IPC", (float)insn / en->flags.cycles); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 961 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 962 | return printed + fprintf(fp, "\n"); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 965 | static int ip__fprintf_sym(uint64_t addr, struct thread *thread, |
| 966 | u8 cpumode, int cpu, struct symbol **lastsym, |
| 967 | struct perf_event_attr *attr, FILE *fp) |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 968 | { |
| 969 | struct addr_location al; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 970 | int off, printed = 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 971 | |
| 972 | memset(&al, 0, sizeof(al)); |
| 973 | |
Arnaldo Carvalho de Melo | 404eb5a | 2018-04-26 09:34:37 -0300 | [diff] [blame] | 974 | thread__find_map(thread, cpumode, addr, &al); |
| 975 | |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 976 | if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 977 | return 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 978 | |
| 979 | al.cpu = cpu; |
| 980 | al.sym = NULL; |
| 981 | if (al.map) |
| 982 | al.sym = map__find_symbol(al.map, al.addr); |
| 983 | |
| 984 | if (!al.sym) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 985 | return 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 986 | |
| 987 | if (al.addr < al.sym->end) |
| 988 | off = al.addr - al.sym->start; |
| 989 | else |
| 990 | off = al.addr - al.map->start - al.sym->start; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 991 | printed += fprintf(fp, "\t%s", al.sym->name); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 992 | if (off) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 993 | printed += fprintf(fp, "%+d", off); |
| 994 | printed += fprintf(fp, ":"); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 995 | if (PRINT_FIELD(SRCLINE)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 996 | printed += map__fprintf_srcline(al.map, al.addr, "\t", fp); |
| 997 | printed += fprintf(fp, "\n"); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 998 | *lastsym = al.sym; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 999 | |
| 1000 | return printed; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1003 | static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample, |
| 1004 | struct thread *thread, |
| 1005 | struct perf_event_attr *attr, |
| 1006 | struct machine *machine, FILE *fp) |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1007 | { |
| 1008 | struct branch_stack *br = sample->branch_stack; |
| 1009 | u64 start, end; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1010 | int i, insn, len, nr, ilen, printed = 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1011 | struct perf_insn x; |
| 1012 | u8 buffer[MAXBB]; |
| 1013 | unsigned off; |
| 1014 | struct symbol *lastsym = NULL; |
Andi Kleen | fe57120 | 2018-09-24 10:07:32 -0700 | [diff] [blame] | 1015 | int total_cycles = 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1016 | |
| 1017 | if (!(br && br->nr)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1018 | return 0; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1019 | nr = br->nr; |
| 1020 | if (max_blocks && nr > max_blocks + 1) |
| 1021 | nr = max_blocks + 1; |
| 1022 | |
| 1023 | x.thread = thread; |
| 1024 | x.cpu = sample->cpu; |
| 1025 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1026 | printed += fprintf(fp, "%c", '\n'); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1027 | |
| 1028 | /* Handle first from jump, of which we don't know the entry. */ |
| 1029 | len = grab_bb(buffer, br->entries[nr-1].from, |
| 1030 | br->entries[nr-1].from, |
| 1031 | machine, thread, &x.is64bit, &x.cpumode, false); |
| 1032 | if (len > 0) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1033 | printed += ip__fprintf_sym(br->entries[nr - 1].from, thread, |
| 1034 | x.cpumode, x.cpu, &lastsym, attr, fp); |
| 1035 | printed += ip__fprintf_jump(br->entries[nr - 1].from, &br->entries[nr - 1], |
Andi Kleen | fe57120 | 2018-09-24 10:07:32 -0700 | [diff] [blame] | 1036 | &x, buffer, len, 0, fp, &total_cycles); |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1037 | if (PRINT_FIELD(SRCCODE)) |
| 1038 | printed += print_srccode(thread, x.cpumode, br->entries[nr - 1].from); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /* Print all blocks */ |
| 1042 | for (i = nr - 2; i >= 0; i--) { |
| 1043 | if (br->entries[i].from || br->entries[i].to) |
| 1044 | pr_debug("%d: %" PRIx64 "-%" PRIx64 "\n", i, |
| 1045 | br->entries[i].from, |
| 1046 | br->entries[i].to); |
| 1047 | start = br->entries[i + 1].to; |
| 1048 | end = br->entries[i].from; |
| 1049 | |
| 1050 | len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false); |
| 1051 | /* Patch up missing kernel transfers due to ring filters */ |
| 1052 | if (len == -ENXIO && i > 0) { |
| 1053 | end = br->entries[--i].from; |
| 1054 | pr_debug("\tpatching up to %" PRIx64 "-%" PRIx64 "\n", start, end); |
| 1055 | len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, false); |
| 1056 | } |
| 1057 | if (len <= 0) |
| 1058 | continue; |
| 1059 | |
| 1060 | insn = 0; |
| 1061 | for (off = 0;; off += ilen) { |
| 1062 | uint64_t ip = start + off; |
| 1063 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1064 | printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1065 | if (ip == end) { |
Andi Kleen | dde4e73 | 2019-07-11 11:19:21 -0700 | [diff] [blame] | 1066 | printed += ip__fprintf_jump(ip, &br->entries[i], &x, buffer + off, len - off, ++insn, fp, |
Andi Kleen | fe57120 | 2018-09-24 10:07:32 -0700 | [diff] [blame] | 1067 | &total_cycles); |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1068 | if (PRINT_FIELD(SRCCODE)) |
| 1069 | printed += print_srccode(thread, x.cpumode, ip); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1070 | break; |
| 1071 | } else { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1072 | printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip, |
| 1073 | dump_insn(&x, ip, buffer + off, len - off, &ilen)); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1074 | if (ilen == 0) |
| 1075 | break; |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1076 | if (PRINT_FIELD(SRCCODE)) |
| 1077 | print_srccode(thread, x.cpumode, ip); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1078 | insn++; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | /* |
| 1084 | * Hit the branch? In this case we are already done, and the target |
| 1085 | * has not been executed yet. |
| 1086 | */ |
| 1087 | if (br->entries[0].from == sample->ip) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1088 | goto out; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1089 | if (br->entries[0].flags.abort) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1090 | goto out; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1091 | |
| 1092 | /* |
| 1093 | * Print final block upto sample |
Andi Kleen | 61f6115 | 2018-11-19 21:06:17 -0800 | [diff] [blame] | 1094 | * |
| 1095 | * Due to pipeline delays the LBRs might be missing a branch |
| 1096 | * or two, which can result in very large or negative blocks |
| 1097 | * between final branch and sample. When this happens just |
| 1098 | * continue walking after the last TO until we hit a branch. |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1099 | */ |
| 1100 | start = br->entries[0].to; |
| 1101 | end = sample->ip; |
Andi Kleen | 61f6115 | 2018-11-19 21:06:17 -0800 | [diff] [blame] | 1102 | if (end < start) { |
| 1103 | /* Missing jump. Scan 128 bytes for the next branch */ |
| 1104 | end = start + 128; |
| 1105 | } |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1106 | len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true); |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1107 | printed += ip__fprintf_sym(start, thread, x.cpumode, x.cpu, &lastsym, attr, fp); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1108 | if (len <= 0) { |
| 1109 | /* Print at least last IP if basic block did not work */ |
| 1110 | len = grab_bb(buffer, sample->ip, sample->ip, |
| 1111 | machine, thread, &x.is64bit, &x.cpumode, false); |
| 1112 | if (len <= 0) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1113 | goto out; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1114 | printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", sample->ip, |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1115 | dump_insn(&x, sample->ip, buffer, len, NULL)); |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1116 | if (PRINT_FIELD(SRCCODE)) |
| 1117 | print_srccode(thread, x.cpumode, sample->ip); |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1118 | goto out; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1119 | } |
| 1120 | for (off = 0; off <= end - start; off += ilen) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1121 | printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off, |
| 1122 | dump_insn(&x, start + off, buffer + off, len - off, &ilen)); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1123 | if (ilen == 0) |
| 1124 | break; |
Andi Kleen | 61f6115 | 2018-11-19 21:06:17 -0800 | [diff] [blame] | 1125 | if (arch_is_branch(buffer + off, len - off, x.is64bit) && start + off != sample->ip) { |
| 1126 | /* |
| 1127 | * Hit a missing branch. Just stop. |
| 1128 | */ |
| 1129 | printed += fprintf(fp, "\t... not reaching sample ...\n"); |
| 1130 | break; |
| 1131 | } |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1132 | if (PRINT_FIELD(SRCCODE)) |
| 1133 | print_srccode(thread, x.cpumode, start + off); |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1134 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1135 | out: |
| 1136 | return printed; |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1137 | } |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 1138 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1139 | static int perf_sample__fprintf_addr(struct perf_sample *sample, |
| 1140 | struct thread *thread, |
| 1141 | struct perf_event_attr *attr, FILE *fp) |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1142 | { |
| 1143 | struct addr_location al; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1144 | int printed = fprintf(fp, "%16" PRIx64, sample->addr); |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1145 | |
| 1146 | if (!sample_addr_correlates_sym(attr)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1147 | goto out; |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1148 | |
Arnaldo Carvalho de Melo | c2740a8 | 2016-03-22 18:44:46 -0300 | [diff] [blame] | 1149 | thread__resolve(thread, &al, sample); |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1150 | |
| 1151 | if (PRINT_FIELD(SYM)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1152 | printed += fprintf(fp, " "); |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 1153 | if (PRINT_FIELD(SYMOFFSET)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1154 | printed += symbol__fprintf_symname_offs(al.sym, &al, fp); |
Akihiro Nagai | a978f2a | 2012-01-30 13:43:15 +0900 | [diff] [blame] | 1155 | else |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1156 | printed += symbol__fprintf_symname(al.sym, fp); |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | if (PRINT_FIELD(DSO)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1160 | printed += fprintf(fp, " ("); |
| 1161 | printed += map__fprintf_dsoname(al.map, fp); |
| 1162 | printed += fprintf(fp, ")"); |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1163 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1164 | out: |
| 1165 | return printed; |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1166 | } |
| 1167 | |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1168 | static const char *resolve_branch_sym(struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1169 | struct evsel *evsel, |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1170 | struct thread *thread, |
| 1171 | struct addr_location *al, |
| 1172 | u64 *ip) |
| 1173 | { |
| 1174 | struct addr_location addr_al; |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1175 | struct perf_event_attr *attr = &evsel->core.attr; |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1176 | const char *name = NULL; |
| 1177 | |
| 1178 | if (sample->flags & (PERF_IP_FLAG_CALL | PERF_IP_FLAG_TRACE_BEGIN)) { |
| 1179 | if (sample_addr_correlates_sym(attr)) { |
| 1180 | thread__resolve(thread, &addr_al, sample); |
| 1181 | if (addr_al.sym) |
| 1182 | name = addr_al.sym->name; |
| 1183 | else |
| 1184 | *ip = sample->addr; |
| 1185 | } else { |
| 1186 | *ip = sample->addr; |
| 1187 | } |
| 1188 | } else if (sample->flags & (PERF_IP_FLAG_RETURN | PERF_IP_FLAG_TRACE_END)) { |
| 1189 | if (al->sym) |
| 1190 | name = al->sym->name; |
| 1191 | else |
| 1192 | *ip = sample->ip; |
| 1193 | } |
| 1194 | return name; |
| 1195 | } |
| 1196 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1197 | static int perf_sample__fprintf_callindent(struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1198 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1199 | struct thread *thread, |
| 1200 | struct addr_location *al, FILE *fp) |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1201 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1202 | struct perf_event_attr *attr = &evsel->core.attr; |
Adrian Hunter | 256d92b | 2018-12-21 14:06:19 +0200 | [diff] [blame] | 1203 | size_t depth = thread_stack__depth(thread, sample->cpu); |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1204 | const char *name = NULL; |
| 1205 | static int spacing; |
| 1206 | int len = 0; |
Andi Kleen | a78cdee | 2018-09-18 05:32:10 -0700 | [diff] [blame] | 1207 | int dlen = 0; |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1208 | u64 ip = 0; |
| 1209 | |
| 1210 | /* |
| 1211 | * The 'return' has already been popped off the stack so the depth has |
| 1212 | * to be adjusted to match the 'call'. |
| 1213 | */ |
| 1214 | if (thread->ts && sample->flags & PERF_IP_FLAG_RETURN) |
| 1215 | depth += 1; |
| 1216 | |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1217 | name = resolve_branch_sym(sample, evsel, thread, al, &ip); |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1218 | |
Andi Kleen | a78cdee | 2018-09-18 05:32:10 -0700 | [diff] [blame] | 1219 | if (PRINT_FIELD(DSO) && !(PRINT_FIELD(IP) || PRINT_FIELD(ADDR))) { |
| 1220 | dlen += fprintf(fp, "("); |
| 1221 | dlen += map__fprintf_dsoname(al->map, fp); |
| 1222 | dlen += fprintf(fp, ")\t"); |
| 1223 | } |
| 1224 | |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1225 | if (name) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1226 | len = fprintf(fp, "%*s%s", (int)depth * 4, "", name); |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1227 | else if (ip) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1228 | len = fprintf(fp, "%*s%16" PRIx64, (int)depth * 4, "", ip); |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1229 | |
| 1230 | if (len < 0) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1231 | return len; |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1232 | |
| 1233 | /* |
| 1234 | * Try to keep the output length from changing frequently so that the |
| 1235 | * output lines up more nicely. |
| 1236 | */ |
| 1237 | if (len > spacing || (len && len < spacing - 52)) |
| 1238 | spacing = round_up(len + 4, 32); |
| 1239 | |
| 1240 | if (len < spacing) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1241 | len += fprintf(fp, "%*s", spacing - len, ""); |
| 1242 | |
Andi Kleen | a78cdee | 2018-09-18 05:32:10 -0700 | [diff] [blame] | 1243 | return len + dlen; |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1244 | } |
| 1245 | |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 1246 | __weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, |
| 1247 | struct thread *thread __maybe_unused, |
| 1248 | struct machine *machine __maybe_unused) |
| 1249 | { |
| 1250 | } |
| 1251 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1252 | static int perf_sample__fprintf_insn(struct perf_sample *sample, |
| 1253 | struct perf_event_attr *attr, |
| 1254 | struct thread *thread, |
| 1255 | struct machine *machine, FILE *fp) |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1256 | { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1257 | int printed = 0; |
| 1258 | |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 1259 | if (sample->insn_len == 0 && native_arch) |
| 1260 | arch_fetch_insn(sample, thread, machine); |
| 1261 | |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1262 | if (PRINT_FIELD(INSNLEN)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1263 | printed += fprintf(fp, " ilen: %d", sample->insn_len); |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 1264 | if (PRINT_FIELD(INSN) && sample->insn_len) { |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1265 | int i; |
| 1266 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1267 | printed += fprintf(fp, " insn:"); |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1268 | for (i = 0; i < sample->insn_len; i++) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1269 | printed += fprintf(fp, " %02x", (unsigned char)sample->insn[i]); |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1270 | } |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1271 | if (PRINT_FIELD(BRSTACKINSN)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1272 | printed += perf_sample__fprintf_brstackinsn(sample, thread, attr, machine, fp); |
| 1273 | |
| 1274 | return printed; |
Andi Kleen | 224e2c9 | 2016-10-07 16:42:27 +0300 | [diff] [blame] | 1275 | } |
| 1276 | |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 1277 | static int perf_sample__fprintf_ipc(struct perf_sample *sample, |
| 1278 | struct perf_event_attr *attr, FILE *fp) |
| 1279 | { |
| 1280 | unsigned int ipc; |
| 1281 | |
| 1282 | if (!PRINT_FIELD(IPC) || !sample->cyc_cnt || !sample->insn_cnt) |
| 1283 | return 0; |
| 1284 | |
| 1285 | ipc = (sample->insn_cnt * 100) / sample->cyc_cnt; |
| 1286 | |
| 1287 | return fprintf(fp, " \t IPC: %u.%02u (%" PRIu64 "/%" PRIu64 ") ", |
| 1288 | ipc / 100, ipc % 100, sample->insn_cnt, sample->cyc_cnt); |
| 1289 | } |
| 1290 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1291 | static int perf_sample__fprintf_bts(struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1292 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1293 | struct thread *thread, |
| 1294 | struct addr_location *al, |
| 1295 | struct machine *machine, FILE *fp) |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1296 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1297 | struct perf_event_attr *attr = &evsel->core.attr; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 1298 | unsigned int type = output_type(attr->type); |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1299 | bool print_srcline_last = false; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1300 | int printed = 0; |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1301 | |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1302 | if (PRINT_FIELD(CALLINDENT)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1303 | printed += perf_sample__fprintf_callindent(sample, evsel, thread, al, fp); |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 1304 | |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1305 | /* print branch_from information */ |
| 1306 | if (PRINT_FIELD(IP)) { |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 1307 | unsigned int print_opts = output[type].print_ip_opts; |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1308 | struct callchain_cursor *cursor = NULL; |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1309 | |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1310 | if (symbol_conf.use_callchain && sample->callchain && |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1311 | thread__resolve_callchain(al->thread, &callchain_cursor, evsel, |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1312 | sample, NULL, NULL, scripting_max_stack) == 0) |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1313 | cursor = &callchain_cursor; |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1314 | |
| 1315 | if (cursor == NULL) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1316 | printed += fprintf(fp, " "); |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 1317 | if (print_opts & EVSEL__PRINT_SRCLINE) { |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1318 | print_srcline_last = true; |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 1319 | print_opts &= ~EVSEL__PRINT_SRCLINE; |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1320 | } |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1321 | } else |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1322 | printed += fprintf(fp, "\n"); |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1323 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1324 | printed += sample__fprintf_sym(sample, al, 0, print_opts, cursor, fp); |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1325 | } |
| 1326 | |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1327 | /* print branch_to information */ |
Adrian Hunter | 243be3d | 2013-10-18 15:29:14 +0300 | [diff] [blame] | 1328 | if (PRINT_FIELD(ADDR) || |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1329 | ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) && |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 1330 | !output[type].user_set)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1331 | printed += fprintf(fp, " => "); |
| 1332 | printed += perf_sample__fprintf_addr(sample, thread, attr, fp); |
Adrian Hunter | 578bea4 | 2014-07-22 16:17:16 +0300 | [diff] [blame] | 1333 | } |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1334 | |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 1335 | printed += perf_sample__fprintf_ipc(sample, attr, fp); |
| 1336 | |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1337 | if (print_srcline_last) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1338 | printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp); |
Adrian Hunter | 8066be5f | 2014-07-22 16:17:15 +0300 | [diff] [blame] | 1339 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1340 | printed += perf_sample__fprintf_insn(sample, attr, thread, machine, fp); |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1341 | printed += fprintf(fp, "\n"); |
| 1342 | if (PRINT_FIELD(SRCCODE)) { |
| 1343 | int ret = map__fprintf_srccode(al->map, al->addr, stdout, |
| 1344 | &thread->srccode_state); |
| 1345 | if (ret) { |
| 1346 | printed += ret; |
| 1347 | printed += printf("\n"); |
| 1348 | } |
| 1349 | } |
| 1350 | return printed; |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1351 | } |
| 1352 | |
Adrian Hunter | 055cd33 | 2016-06-23 16:40:56 +0300 | [diff] [blame] | 1353 | static struct { |
| 1354 | u32 flags; |
| 1355 | const char *name; |
| 1356 | } sample_flags[] = { |
| 1357 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL, "call"}, |
| 1358 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN, "return"}, |
| 1359 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CONDITIONAL, "jcc"}, |
| 1360 | {PERF_IP_FLAG_BRANCH, "jmp"}, |
| 1361 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT, "int"}, |
| 1362 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT, "iret"}, |
| 1363 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET, "syscall"}, |
| 1364 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET, "sysret"}, |
| 1365 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_ASYNC, "async"}, |
| 1366 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | PERF_IP_FLAG_INTERRUPT, "hw int"}, |
| 1367 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT, "tx abrt"}, |
| 1368 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_BEGIN, "tr strt"}, |
| 1369 | {PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TRACE_END, "tr end"}, |
| 1370 | {0, NULL} |
| 1371 | }; |
| 1372 | |
Adrian Hunter | 62cb1b8 | 2018-09-20 16:00:43 +0300 | [diff] [blame] | 1373 | static const char *sample_flags_to_name(u32 flags) |
| 1374 | { |
| 1375 | int i; |
| 1376 | |
| 1377 | for (i = 0; sample_flags[i].name ; i++) { |
| 1378 | if (sample_flags[i].flags == flags) |
| 1379 | return sample_flags[i].name; |
| 1380 | } |
| 1381 | |
| 1382 | return NULL; |
| 1383 | } |
| 1384 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1385 | static int perf_sample__fprintf_flags(u32 flags, FILE *fp) |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1386 | { |
| 1387 | const char *chars = PERF_IP_FLAG_CHARS; |
| 1388 | const int n = strlen(PERF_IP_FLAG_CHARS); |
Adrian Hunter | 055cd33 | 2016-06-23 16:40:56 +0300 | [diff] [blame] | 1389 | bool in_tx = flags & PERF_IP_FLAG_IN_TX; |
| 1390 | const char *name = NULL; |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1391 | char str[33]; |
| 1392 | int i, pos = 0; |
| 1393 | |
Adrian Hunter | 62cb1b8 | 2018-09-20 16:00:43 +0300 | [diff] [blame] | 1394 | name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX); |
| 1395 | if (name) |
| 1396 | return fprintf(fp, " %-15s%4s ", name, in_tx ? "(x)" : ""); |
| 1397 | |
| 1398 | if (flags & PERF_IP_FLAG_TRACE_BEGIN) { |
| 1399 | name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN)); |
| 1400 | if (name) |
| 1401 | return fprintf(fp, " tr strt %-7s%4s ", name, in_tx ? "(x)" : ""); |
| 1402 | } |
| 1403 | |
| 1404 | if (flags & PERF_IP_FLAG_TRACE_END) { |
| 1405 | name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END)); |
| 1406 | if (name) |
| 1407 | return fprintf(fp, " tr end %-7s%4s ", name, in_tx ? "(x)" : ""); |
Adrian Hunter | 055cd33 | 2016-06-23 16:40:56 +0300 | [diff] [blame] | 1408 | } |
| 1409 | |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1410 | for (i = 0; i < n; i++, flags >>= 1) { |
| 1411 | if (flags & 1) |
| 1412 | str[pos++] = chars[i]; |
| 1413 | } |
| 1414 | for (; i < 32; i++, flags >>= 1) { |
| 1415 | if (flags & 1) |
| 1416 | str[pos++] = '?'; |
| 1417 | } |
| 1418 | str[pos] = 0; |
Adrian Hunter | 055cd33 | 2016-06-23 16:40:56 +0300 | [diff] [blame] | 1419 | |
Adrian Hunter | 62cb1b8 | 2018-09-20 16:00:43 +0300 | [diff] [blame] | 1420 | return fprintf(fp, " %-19s ", str); |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1421 | } |
| 1422 | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1423 | struct printer_data { |
| 1424 | int line_no; |
| 1425 | bool hit_nul; |
| 1426 | bool is_printable; |
| 1427 | }; |
| 1428 | |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1429 | static int sample__fprintf_bpf_output(enum binary_printer_ops op, |
| 1430 | unsigned int val, |
| 1431 | void *extra, FILE *fp) |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1432 | { |
| 1433 | unsigned char ch = (unsigned char)val; |
| 1434 | struct printer_data *printer_data = extra; |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1435 | int printed = 0; |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1436 | |
| 1437 | switch (op) { |
| 1438 | case BINARY_PRINT_DATA_BEGIN: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1439 | printed += fprintf(fp, "\n"); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | case BINARY_PRINT_LINE_BEGIN: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1442 | printed += fprintf(fp, "%17s", !printer_data->line_no ? "BPF output:" : |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1443 | " "); |
| 1444 | break; |
| 1445 | case BINARY_PRINT_ADDR: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1446 | printed += fprintf(fp, " %04x:", val); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | case BINARY_PRINT_NUM_DATA: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1449 | printed += fprintf(fp, " %02x", val); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1450 | break; |
| 1451 | case BINARY_PRINT_NUM_PAD: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1452 | printed += fprintf(fp, " "); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1453 | break; |
| 1454 | case BINARY_PRINT_SEP: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1455 | printed += fprintf(fp, " "); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1456 | break; |
| 1457 | case BINARY_PRINT_CHAR_DATA: |
| 1458 | if (printer_data->hit_nul && ch) |
| 1459 | printer_data->is_printable = false; |
| 1460 | |
| 1461 | if (!isprint(ch)) { |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1462 | printed += fprintf(fp, "%c", '.'); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1463 | |
| 1464 | if (!printer_data->is_printable) |
| 1465 | break; |
| 1466 | |
| 1467 | if (ch == '\0') |
| 1468 | printer_data->hit_nul = true; |
| 1469 | else |
| 1470 | printer_data->is_printable = false; |
| 1471 | } else { |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1472 | printed += fprintf(fp, "%c", ch); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1473 | } |
| 1474 | break; |
| 1475 | case BINARY_PRINT_CHAR_PAD: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1476 | printed += fprintf(fp, " "); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1477 | break; |
| 1478 | case BINARY_PRINT_LINE_END: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1479 | printed += fprintf(fp, "\n"); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1480 | printer_data->line_no++; |
| 1481 | break; |
| 1482 | case BINARY_PRINT_DATA_END: |
| 1483 | default: |
| 1484 | break; |
| 1485 | } |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 1486 | |
| 1487 | return printed; |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1490 | static int perf_sample__fprintf_bpf_output(struct perf_sample *sample, FILE *fp) |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1491 | { |
| 1492 | unsigned int nr_bytes = sample->raw_size; |
| 1493 | struct printer_data printer_data = {0, false, true}; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1494 | int printed = binary__fprintf(sample->raw_data, nr_bytes, 8, |
| 1495 | sample__fprintf_bpf_output, &printer_data, fp); |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1496 | |
| 1497 | if (printer_data.is_printable && printer_data.hit_nul) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1498 | printed += fprintf(fp, "%17s \"%s\"\n", "BPF string:", (char *)(sample->raw_data)); |
| 1499 | |
| 1500 | return printed; |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1503 | static int perf_sample__fprintf_spacing(int len, int spacing, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1504 | { |
| 1505 | if (len > 0 && len < spacing) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1506 | return fprintf(fp, "%*s", spacing - len, ""); |
| 1507 | |
| 1508 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1509 | } |
| 1510 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1511 | static int perf_sample__fprintf_pt_spacing(int len, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1512 | { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1513 | return perf_sample__fprintf_spacing(len, 34, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1514 | } |
| 1515 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1516 | static int perf_sample__fprintf_synth_ptwrite(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1517 | { |
| 1518 | struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample); |
| 1519 | int len; |
| 1520 | |
| 1521 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1522 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1523 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1524 | len = fprintf(fp, " IP: %u payload: %#" PRIx64 " ", |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1525 | data->ip, le64_to_cpu(data->payload)); |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1526 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1527 | } |
| 1528 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1529 | static int perf_sample__fprintf_synth_mwait(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1530 | { |
| 1531 | struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample); |
| 1532 | int len; |
| 1533 | |
| 1534 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1535 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1536 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1537 | len = fprintf(fp, " hints: %#x extensions: %#x ", |
| 1538 | data->hints, data->extensions); |
| 1539 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1540 | } |
| 1541 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1542 | static int perf_sample__fprintf_synth_pwre(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1543 | { |
| 1544 | struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample); |
| 1545 | int len; |
| 1546 | |
| 1547 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1548 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1549 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1550 | len = fprintf(fp, " hw: %u cstate: %u sub-cstate: %u ", |
| 1551 | data->hw, data->cstate, data->subcstate); |
| 1552 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1553 | } |
| 1554 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1555 | static int perf_sample__fprintf_synth_exstop(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1556 | { |
| 1557 | struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample); |
| 1558 | int len; |
| 1559 | |
| 1560 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1561 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1562 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1563 | len = fprintf(fp, " IP: %u ", data->ip); |
| 1564 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1565 | } |
| 1566 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1567 | static int perf_sample__fprintf_synth_pwrx(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1568 | { |
| 1569 | struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample); |
| 1570 | int len; |
| 1571 | |
| 1572 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1573 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1574 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1575 | len = fprintf(fp, " deepest cstate: %u last cstate: %u wake reason: %#x ", |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1576 | data->deepest_cstate, data->last_cstate, |
| 1577 | data->wake_reason); |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1578 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1579 | } |
| 1580 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1581 | static int perf_sample__fprintf_synth_cbr(struct perf_sample *sample, FILE *fp) |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1582 | { |
| 1583 | struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample); |
| 1584 | unsigned int percent, freq; |
| 1585 | int len; |
| 1586 | |
| 1587 | if (perf_sample__bad_synth_size(sample, *data)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1588 | return 0; |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1589 | |
| 1590 | freq = (le32_to_cpu(data->freq) + 500) / 1000; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1591 | len = fprintf(fp, " cbr: %2u freq: %4u MHz ", data->cbr, freq); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1592 | if (data->max_nonturbo) { |
| 1593 | percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10; |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1594 | len += fprintf(fp, "(%3u%%) ", percent); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1595 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1596 | return len + perf_sample__fprintf_pt_spacing(len, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1597 | } |
| 1598 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1599 | static int perf_sample__fprintf_synth(struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1600 | struct evsel *evsel, FILE *fp) |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 1601 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1602 | switch (evsel->core.attr.config) { |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1603 | case PERF_SYNTH_INTEL_PTWRITE: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1604 | return perf_sample__fprintf_synth_ptwrite(sample, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1605 | case PERF_SYNTH_INTEL_MWAIT: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1606 | return perf_sample__fprintf_synth_mwait(sample, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1607 | case PERF_SYNTH_INTEL_PWRE: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1608 | return perf_sample__fprintf_synth_pwre(sample, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1609 | case PERF_SYNTH_INTEL_EXSTOP: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1610 | return perf_sample__fprintf_synth_exstop(sample, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1611 | case PERF_SYNTH_INTEL_PWRX: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1612 | return perf_sample__fprintf_synth_pwrx(sample, fp); |
Adrian Hunter | 65c5e18 | 2017-06-30 11:36:42 +0300 | [diff] [blame] | 1613 | case PERF_SYNTH_INTEL_CBR: |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1614 | return perf_sample__fprintf_synth_cbr(sample, fp); |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 1615 | default: |
| 1616 | break; |
| 1617 | } |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1618 | |
| 1619 | return 0; |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 1620 | } |
| 1621 | |
Jiri Olsa | 809e942 | 2015-11-26 18:55:21 +0100 | [diff] [blame] | 1622 | struct perf_script { |
| 1623 | struct perf_tool tool; |
| 1624 | struct perf_session *session; |
| 1625 | bool show_task_events; |
| 1626 | bool show_mmap_events; |
| 1627 | bool show_switch_events; |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 1628 | bool show_namespace_events; |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 1629 | bool show_lost_events; |
Jiri Olsa | 3233b37 | 2018-02-06 19:17:59 +0100 | [diff] [blame] | 1630 | bool show_round_events; |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 1631 | bool show_bpf_events; |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 1632 | bool allocated; |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 1633 | bool per_event_dump; |
Arnaldo Carvalho de Melo | f90a241 | 2019-08-14 16:20:13 -0300 | [diff] [blame] | 1634 | struct evswitch evswitch; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 1635 | struct perf_cpu_map *cpus; |
Jiri Olsa | 9749b90 | 2019-07-21 13:23:50 +0200 | [diff] [blame] | 1636 | struct perf_thread_map *threads; |
Jiri Olsa | 9cdbc40 | 2016-01-07 10:14:05 +0100 | [diff] [blame] | 1637 | int name_width; |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 1638 | const char *time_str; |
Jin Yao | cc2ef58 | 2018-01-10 23:00:33 +0800 | [diff] [blame] | 1639 | struct perf_time_interval *ptime_range; |
| 1640 | int range_size; |
Jin Yao | 2ab046c | 2017-12-08 21:13:46 +0800 | [diff] [blame] | 1641 | int range_num; |
Jiri Olsa | 809e942 | 2015-11-26 18:55:21 +0100 | [diff] [blame] | 1642 | }; |
| 1643 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1644 | static int perf_evlist__max_name_len(struct evlist *evlist) |
Jiri Olsa | 9cdbc40 | 2016-01-07 10:14:05 +0100 | [diff] [blame] | 1645 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1646 | struct evsel *evsel; |
Jiri Olsa | 9cdbc40 | 2016-01-07 10:14:05 +0100 | [diff] [blame] | 1647 | int max = 0; |
| 1648 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1649 | evlist__for_each_entry(evlist, evsel) { |
Jiri Olsa | 9cdbc40 | 2016-01-07 10:14:05 +0100 | [diff] [blame] | 1650 | int len = strlen(perf_evsel__name(evsel)); |
| 1651 | |
| 1652 | max = MAX(len, max); |
| 1653 | } |
| 1654 | |
| 1655 | return max; |
| 1656 | } |
| 1657 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1658 | static int data_src__fprintf(u64 data_src, FILE *fp) |
Jiri Olsa | c19ac91 | 2016-02-24 09:46:54 +0100 | [diff] [blame] | 1659 | { |
| 1660 | struct mem_info mi = { .data_src.val = data_src }; |
| 1661 | char decode[100]; |
| 1662 | char out[100]; |
| 1663 | static int maxlen; |
| 1664 | int len; |
| 1665 | |
| 1666 | perf_script__meminfo_scnprintf(decode, 100, &mi); |
| 1667 | |
| 1668 | len = scnprintf(out, 100, "%16" PRIx64 " %s", data_src, decode); |
| 1669 | if (maxlen < len) |
| 1670 | maxlen = len; |
| 1671 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1672 | return fprintf(fp, "%-*s", maxlen, out); |
Jiri Olsa | c19ac91 | 2016-02-24 09:46:54 +0100 | [diff] [blame] | 1673 | } |
| 1674 | |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1675 | struct metric_ctx { |
| 1676 | struct perf_sample *sample; |
| 1677 | struct thread *thread; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1678 | struct evsel *evsel; |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1679 | FILE *fp; |
| 1680 | }; |
| 1681 | |
Jiri Olsa | 6ca9a08 | 2018-08-30 08:32:28 +0200 | [diff] [blame] | 1682 | static void script_print_metric(struct perf_stat_config *config __maybe_unused, |
| 1683 | void *ctx, const char *color, |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1684 | const char *fmt, |
| 1685 | const char *unit, double val) |
| 1686 | { |
| 1687 | struct metric_ctx *mctx = ctx; |
| 1688 | |
| 1689 | if (!fmt) |
| 1690 | return; |
| 1691 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 1692 | PERF_RECORD_SAMPLE, mctx->fp); |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1693 | fputs("\tmetric: ", mctx->fp); |
| 1694 | if (color) |
| 1695 | color_fprintf(mctx->fp, color, fmt, val); |
| 1696 | else |
| 1697 | printf(fmt, val); |
| 1698 | fprintf(mctx->fp, " %s\n", unit); |
| 1699 | } |
| 1700 | |
Jiri Olsa | 6ca9a08 | 2018-08-30 08:32:28 +0200 | [diff] [blame] | 1701 | static void script_new_line(struct perf_stat_config *config __maybe_unused, |
| 1702 | void *ctx) |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1703 | { |
| 1704 | struct metric_ctx *mctx = ctx; |
| 1705 | |
| 1706 | perf_sample__fprintf_start(mctx->sample, mctx->thread, mctx->evsel, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 1707 | PERF_RECORD_SAMPLE, mctx->fp); |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1708 | fputs("\tmetric: ", mctx->fp); |
| 1709 | } |
| 1710 | |
| 1711 | static void perf_sample__fprint_metric(struct perf_script *script, |
| 1712 | struct thread *thread, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1713 | struct evsel *evsel, |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1714 | struct perf_sample *sample, |
| 1715 | FILE *fp) |
| 1716 | { |
| 1717 | struct perf_stat_output_ctx ctx = { |
| 1718 | .print_metric = script_print_metric, |
| 1719 | .new_line = script_new_line, |
| 1720 | .ctx = &(struct metric_ctx) { |
| 1721 | .sample = sample, |
| 1722 | .thread = thread, |
| 1723 | .evsel = evsel, |
| 1724 | .fp = fp, |
| 1725 | }, |
| 1726 | .force_header = false, |
| 1727 | }; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1728 | struct evsel *ev2; |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1729 | u64 val; |
| 1730 | |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1731 | if (!evsel->stats) |
| 1732 | perf_evlist__alloc_stats(script->session->evlist, false); |
| 1733 | if (evsel_script(evsel->leader)->gnum++ == 0) |
| 1734 | perf_stat__reset_shadow_stats(); |
| 1735 | val = sample->period * evsel->scale; |
| 1736 | perf_stat__update_shadow_stats(evsel, |
| 1737 | val, |
Jin Yao | 1fcd039 | 2017-12-05 22:03:04 +0800 | [diff] [blame] | 1738 | sample->cpu, |
| 1739 | &rt_stat); |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1740 | evsel_script(evsel)->val = val; |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 1741 | if (evsel_script(evsel->leader)->gnum == evsel->leader->core.nr_members) { |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1742 | for_each_group_member (ev2, evsel->leader) { |
Jiri Olsa | 6ca9a08 | 2018-08-30 08:32:28 +0200 | [diff] [blame] | 1743 | perf_stat__print_shadow_stats(&stat_config, ev2, |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1744 | evsel_script(ev2)->val, |
| 1745 | sample->cpu, |
| 1746 | &ctx, |
Jin Yao | e0128b3 | 2017-12-05 22:03:05 +0800 | [diff] [blame] | 1747 | NULL, |
| 1748 | &rt_stat); |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1749 | } |
| 1750 | evsel_script(evsel->leader)->gnum = 0; |
| 1751 | } |
| 1752 | } |
| 1753 | |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1754 | static bool show_event(struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1755 | struct evsel *evsel, |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1756 | struct thread *thread, |
| 1757 | struct addr_location *al) |
| 1758 | { |
Adrian Hunter | 256d92b | 2018-12-21 14:06:19 +0200 | [diff] [blame] | 1759 | int depth = thread_stack__depth(thread, sample->cpu); |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1760 | |
| 1761 | if (!symbol_conf.graph_function) |
| 1762 | return true; |
| 1763 | |
| 1764 | if (thread->filter) { |
| 1765 | if (depth <= thread->filter_entry_depth) { |
| 1766 | thread->filter = false; |
| 1767 | return false; |
| 1768 | } |
| 1769 | return true; |
| 1770 | } else { |
| 1771 | const char *s = symbol_conf.graph_function; |
| 1772 | u64 ip; |
| 1773 | const char *name = resolve_branch_sym(sample, evsel, thread, al, |
| 1774 | &ip); |
| 1775 | unsigned nlen; |
| 1776 | |
| 1777 | if (!name) |
| 1778 | return false; |
| 1779 | nlen = strlen(name); |
| 1780 | while (*s) { |
| 1781 | unsigned len = strcspn(s, ","); |
| 1782 | if (nlen == len && !strncmp(name, s, len)) { |
| 1783 | thread->filter = true; |
| 1784 | thread->filter_entry_depth = depth; |
| 1785 | return true; |
| 1786 | } |
| 1787 | s += len; |
| 1788 | if (*s == ',') |
| 1789 | s++; |
| 1790 | } |
| 1791 | return false; |
| 1792 | } |
| 1793 | } |
| 1794 | |
Arnaldo Carvalho de Melo | a3dff30 | 2016-03-23 11:55:24 -0300 | [diff] [blame] | 1795 | static void process_event(struct perf_script *script, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1796 | struct perf_sample *sample, struct evsel *evsel, |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 1797 | struct addr_location *al, |
| 1798 | struct machine *machine) |
David Ahern | be6d842 | 2011-03-09 22:23:23 -0700 | [diff] [blame] | 1799 | { |
Arnaldo Carvalho de Melo | f9d5d54 | 2015-04-01 13:29:25 -0300 | [diff] [blame] | 1800 | struct thread *thread = al->thread; |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1801 | struct perf_event_attr *attr = &evsel->core.attr; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 1802 | unsigned int type = output_type(attr->type); |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1803 | struct evsel_script *es = evsel->priv; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 1804 | FILE *fp = es->fp; |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 1805 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 1806 | if (output[type].fields == 0) |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 1807 | return; |
| 1808 | |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 1809 | if (!show_event(sample, evsel, thread, al)) |
| 1810 | return; |
| 1811 | |
Arnaldo Carvalho de Melo | 8829e56 | 2019-08-15 11:00:11 -0300 | [diff] [blame] | 1812 | if (evswitch__discard(&script->evswitch, evsel)) |
| 1813 | return; |
Arnaldo Carvalho de Melo | f90a241 | 2019-08-14 16:20:13 -0300 | [diff] [blame] | 1814 | |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 1815 | ++es->samples; |
| 1816 | |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 1817 | perf_sample__fprintf_start(sample, thread, evsel, |
| 1818 | PERF_RECORD_SAMPLE, fp); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 1819 | |
Jiri Olsa | 535aeaae | 2014-08-25 16:45:42 +0200 | [diff] [blame] | 1820 | if (PRINT_FIELD(PERIOD)) |
Arnaldo Carvalho de Melo | 69c7125 | 2017-10-26 09:51:13 -0300 | [diff] [blame] | 1821 | fprintf(fp, "%10" PRIu64 " ", sample->period); |
Jiri Olsa | 535aeaae | 2014-08-25 16:45:42 +0200 | [diff] [blame] | 1822 | |
Namhyung Kim | e944d3d | 2013-11-18 14:34:52 +0900 | [diff] [blame] | 1823 | if (PRINT_FIELD(EVNAME)) { |
| 1824 | const char *evname = perf_evsel__name(evsel); |
Jiri Olsa | 9cdbc40 | 2016-01-07 10:14:05 +0100 | [diff] [blame] | 1825 | |
| 1826 | if (!script->name_width) |
| 1827 | script->name_width = perf_evlist__max_name_len(script->session->evlist); |
| 1828 | |
Arnaldo Carvalho de Melo | 69c7125 | 2017-10-26 09:51:13 -0300 | [diff] [blame] | 1829 | fprintf(fp, "%*s: ", script->name_width, evname ?: "[unknown]"); |
Namhyung Kim | e944d3d | 2013-11-18 14:34:52 +0900 | [diff] [blame] | 1830 | } |
| 1831 | |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1832 | if (print_flags) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1833 | perf_sample__fprintf_flags(sample->flags, fp); |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 1834 | |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1835 | if (is_bts_event(attr)) { |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1836 | perf_sample__fprintf_bts(sample, evsel, thread, al, machine, fp); |
Akihiro Nagai | 9558259 | 2012-01-30 13:43:09 +0900 | [diff] [blame] | 1837 | return; |
| 1838 | } |
| 1839 | |
Andi Kleen | 9616716 | 2019-01-17 11:48:34 -0800 | [diff] [blame] | 1840 | if (PRINT_FIELD(TRACE) && sample->raw_data) { |
Arnaldo Carvalho de Melo | 894f3f1 | 2017-10-26 10:26:52 -0300 | [diff] [blame] | 1841 | event_format__fprintf(evsel->tp_format, sample->cpu, |
| 1842 | sample->raw_data, sample->raw_size, fp); |
| 1843 | } |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 1844 | |
| 1845 | if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1846 | perf_sample__fprintf_synth(sample, evsel, fp); |
Adrian Hunter | 47e7808 | 2017-05-26 11:17:22 +0300 | [diff] [blame] | 1847 | |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1848 | if (PRINT_FIELD(ADDR)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1849 | perf_sample__fprintf_addr(sample, thread, attr, fp); |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1850 | |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 1851 | if (PRINT_FIELD(DATA_SRC)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1852 | data_src__fprintf(sample->data_src, fp); |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 1853 | |
| 1854 | if (PRINT_FIELD(WEIGHT)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1855 | fprintf(fp, "%16" PRIu64, sample->weight); |
Jiri Olsa | 94ddddf | 2016-02-15 09:34:51 +0100 | [diff] [blame] | 1856 | |
David Ahern | 787bef1 | 2011-05-27 14:28:43 -0600 | [diff] [blame] | 1857 | if (PRINT_FIELD(IP)) { |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1858 | struct callchain_cursor *cursor = NULL; |
David Ahern | a6ffaf9 | 2013-08-07 22:50:51 -0400 | [diff] [blame] | 1859 | |
Arnaldo Carvalho de Melo | 9223152 | 2016-04-18 11:31:46 -0300 | [diff] [blame] | 1860 | if (symbol_conf.use_callchain && sample->callchain && |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1861 | thread__resolve_callchain(al->thread, &callchain_cursor, evsel, |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1862 | sample, NULL, NULL, scripting_max_stack) == 0) |
Chris Phlipot | e557b67 | 2016-04-19 19:32:11 -0700 | [diff] [blame] | 1863 | cursor = &callchain_cursor; |
Arnaldo Carvalho de Melo | 6f73673 | 2016-04-14 17:45:51 -0300 | [diff] [blame] | 1864 | |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1865 | fputc(cursor ? '\n' : ' ', fp); |
| 1866 | sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, fp); |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 1869 | if (PRINT_FIELD(IREGS)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1870 | perf_sample__fprintf_iregs(sample, attr, fp); |
Stephane Eranian | fc36f94 | 2015-08-31 18:41:10 +0200 | [diff] [blame] | 1871 | |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 1872 | if (PRINT_FIELD(UREGS)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1873 | perf_sample__fprintf_uregs(sample, attr, fp); |
Andi Kleen | b1491ac | 2017-09-05 11:40:57 -0700 | [diff] [blame] | 1874 | |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 1875 | if (PRINT_FIELD(BRSTACK)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1876 | perf_sample__fprintf_brstack(sample, thread, attr, fp); |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 1877 | else if (PRINT_FIELD(BRSTACKSYM)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1878 | perf_sample__fprintf_brstacksym(sample, thread, attr, fp); |
Mark Santaniello | 106dacd | 2017-06-19 09:38:25 -0700 | [diff] [blame] | 1879 | else if (PRINT_FIELD(BRSTACKOFF)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1880 | perf_sample__fprintf_brstackoff(sample, thread, attr, fp); |
Stephane Eranian | dc323ce | 2015-08-31 18:41:13 +0200 | [diff] [blame] | 1881 | |
Wang Nan | 30372f0 | 2016-02-24 11:20:45 +0000 | [diff] [blame] | 1882 | if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) |
Arnaldo Carvalho de Melo | a1a5870 | 2017-10-17 10:54:24 -0300 | [diff] [blame] | 1883 | perf_sample__fprintf_bpf_output(sample, fp); |
| 1884 | perf_sample__fprintf_insn(sample, attr, thread, machine, fp); |
Kan Liang | 49d58f0 | 2017-08-29 13:11:11 -0400 | [diff] [blame] | 1885 | |
| 1886 | if (PRINT_FIELD(PHYS_ADDR)) |
Arnaldo Carvalho de Melo | 69c7125 | 2017-10-26 09:51:13 -0300 | [diff] [blame] | 1887 | fprintf(fp, "%16" PRIx64, sample->phys_addr); |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 1888 | |
| 1889 | perf_sample__fprintf_ipc(sample, attr, fp); |
| 1890 | |
Arnaldo Carvalho de Melo | 69c7125 | 2017-10-26 09:51:13 -0300 | [diff] [blame] | 1891 | fprintf(fp, "\n"); |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1892 | |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 1893 | if (PRINT_FIELD(SRCCODE)) { |
| 1894 | if (map__fprintf_srccode(al->map, al->addr, stdout, |
| 1895 | &thread->srccode_state)) |
| 1896 | printf("\n"); |
| 1897 | } |
| 1898 | |
Andi Kleen | 4bd1bef | 2017-11-17 13:43:00 -0800 | [diff] [blame] | 1899 | if (PRINT_FIELD(METRIC)) |
| 1900 | perf_sample__fprint_metric(script, thread, evsel, sample, fp); |
Milian Wolff | 7ee4067 | 2018-10-21 21:14:24 +0200 | [diff] [blame] | 1901 | |
| 1902 | if (verbose) |
| 1903 | fflush(fp); |
David Ahern | be6d842 | 2011-03-09 22:23:23 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 1906 | static struct scripting_ops *scripting_ops; |
| 1907 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1908 | static void __process_stat(struct evsel *counter, u64 tstamp) |
Jiri Olsa | 36e33c5 | 2016-01-06 11:49:56 +0100 | [diff] [blame] | 1909 | { |
Jiri Olsa | a2f354e | 2019-08-22 13:11:41 +0200 | [diff] [blame] | 1910 | int nthreads = perf_thread_map__nr(counter->core.threads); |
Jiri Olsa | 36e33c5 | 2016-01-06 11:49:56 +0100 | [diff] [blame] | 1911 | int ncpus = perf_evsel__nr_cpus(counter); |
| 1912 | int cpu, thread; |
| 1913 | static int header_printed; |
| 1914 | |
| 1915 | if (counter->system_wide) |
| 1916 | nthreads = 1; |
| 1917 | |
| 1918 | if (!header_printed) { |
| 1919 | printf("%3s %8s %15s %15s %15s %15s %s\n", |
| 1920 | "CPU", "THREAD", "VAL", "ENA", "RUN", "TIME", "EVENT"); |
| 1921 | header_printed = 1; |
| 1922 | } |
| 1923 | |
| 1924 | for (thread = 0; thread < nthreads; thread++) { |
| 1925 | for (cpu = 0; cpu < ncpus; cpu++) { |
| 1926 | struct perf_counts_values *counts; |
| 1927 | |
| 1928 | counts = perf_counts(counter->counts, cpu, thread); |
| 1929 | |
| 1930 | printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", |
Jiri Olsa | d400bd3 | 2019-07-21 13:24:37 +0200 | [diff] [blame] | 1931 | counter->core.cpus->map[cpu], |
Jiri Olsa | a2f354e | 2019-08-22 13:11:41 +0200 | [diff] [blame] | 1932 | perf_thread_map__pid(counter->core.threads, thread), |
Jiri Olsa | 36e33c5 | 2016-01-06 11:49:56 +0100 | [diff] [blame] | 1933 | counts->val, |
| 1934 | counts->ena, |
| 1935 | counts->run, |
| 1936 | tstamp, |
| 1937 | perf_evsel__name(counter)); |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1942 | static void process_stat(struct evsel *counter, u64 tstamp) |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 1943 | { |
| 1944 | if (scripting_ops && scripting_ops->process_stat) |
| 1945 | scripting_ops->process_stat(&stat_config, counter, tstamp); |
Jiri Olsa | 36e33c5 | 2016-01-06 11:49:56 +0100 | [diff] [blame] | 1946 | else |
| 1947 | __process_stat(counter, tstamp); |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | static void process_stat_interval(u64 tstamp) |
| 1951 | { |
| 1952 | if (scripting_ops && scripting_ops->process_stat_interval) |
| 1953 | scripting_ops->process_stat_interval(tstamp); |
| 1954 | } |
| 1955 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 1956 | static void setup_scripting(void) |
| 1957 | { |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 1958 | setup_perl_scripting(); |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 1959 | setup_python_scripting(); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 1960 | } |
| 1961 | |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 1962 | static int flush_scripting(void) |
| 1963 | { |
Jiri Olsa | 2aaecfc | 2015-11-26 14:55:23 +0100 | [diff] [blame] | 1964 | return scripting_ops ? scripting_ops->flush_script() : 0; |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 1965 | } |
| 1966 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 1967 | static int cleanup_scripting(void) |
| 1968 | { |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 1969 | pr_debug("\nperf script stopped\n"); |
Tom Zanussi | 3824a4e | 2010-05-09 23:46:57 -0500 | [diff] [blame] | 1970 | |
Jiri Olsa | 2aaecfc | 2015-11-26 14:55:23 +0100 | [diff] [blame] | 1971 | return scripting_ops ? scripting_ops->stop_script() : 0; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 1972 | } |
| 1973 | |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 1974 | static bool filter_cpu(struct perf_sample *sample) |
| 1975 | { |
| 1976 | if (cpu_list) |
| 1977 | return !test_bit(sample->cpu, cpu_bitmap); |
| 1978 | return false; |
| 1979 | } |
| 1980 | |
Jiri Olsa | 809e942 | 2015-11-26 18:55:21 +0100 | [diff] [blame] | 1981 | static int process_sample_event(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 1982 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1983 | struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1984 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1985 | struct machine *machine) |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 1986 | { |
Jiri Olsa | 809e942 | 2015-11-26 18:55:21 +0100 | [diff] [blame] | 1987 | struct perf_script *scr = container_of(tool, struct perf_script, tool); |
David Ahern | e7984b7 | 2011-11-21 10:02:52 -0700 | [diff] [blame] | 1988 | struct addr_location al; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 1989 | |
Jin Yao | 2ab046c | 2017-12-08 21:13:46 +0800 | [diff] [blame] | 1990 | if (perf_time__ranges_skip_sample(scr->ptime_range, scr->range_num, |
| 1991 | sample->time)) { |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 1992 | return 0; |
Jin Yao | 2ab046c | 2017-12-08 21:13:46 +0800 | [diff] [blame] | 1993 | } |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 1994 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 1995 | if (debug_mode) { |
| 1996 | if (sample->time < last_timestamp) { |
| 1997 | pr_err("Samples misordered, previous: %" PRIu64 |
| 1998 | " this: %" PRIu64 "\n", last_timestamp, |
| 1999 | sample->time); |
| 2000 | nr_unordered++; |
Frederic Weisbecker | e1889d7 | 2010-04-24 01:55:09 +0200 | [diff] [blame] | 2001 | } |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 2002 | last_timestamp = sample->time; |
| 2003 | return 0; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 2004 | } |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2005 | |
Arnaldo Carvalho de Melo | bb3eb56 | 2016-03-22 18:39:09 -0300 | [diff] [blame] | 2006 | if (machine__resolve(machine, &al, sample) < 0) { |
David Ahern | e7984b7 | 2011-11-21 10:02:52 -0700 | [diff] [blame] | 2007 | pr_err("problem processing %d event, skipping it.\n", |
| 2008 | event->header.type); |
| 2009 | return -1; |
| 2010 | } |
| 2011 | |
| 2012 | if (al.filtered) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2013 | goto out_put; |
David Ahern | e7984b7 | 2011-11-21 10:02:52 -0700 | [diff] [blame] | 2014 | |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2015 | if (filter_cpu(sample)) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2016 | goto out_put; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2017 | |
Jiri Olsa | 2aaecfc | 2015-11-26 14:55:23 +0100 | [diff] [blame] | 2018 | if (scripting_ops) |
| 2019 | scripting_ops->process_event(event, sample, evsel, &al); |
| 2020 | else |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 2021 | process_event(scr, sample, evsel, &al, machine); |
Jiri Olsa | 2aaecfc | 2015-11-26 14:55:23 +0100 | [diff] [blame] | 2022 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2023 | out_put: |
| 2024 | addr_location__put(&al); |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 2025 | return 0; |
| 2026 | } |
| 2027 | |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2028 | static int process_attr(struct perf_tool *tool, union perf_event *event, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2029 | struct evlist **pevlist) |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2030 | { |
| 2031 | struct perf_script *scr = container_of(tool, struct perf_script, tool); |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2032 | struct evlist *evlist; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2033 | struct evsel *evsel, *pos; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2034 | int err; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2035 | static struct evsel_script *es; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2036 | |
| 2037 | err = perf_event__process_attr(tool, event, pevlist); |
| 2038 | if (err) |
| 2039 | return err; |
| 2040 | |
| 2041 | evlist = *pevlist; |
| 2042 | evsel = perf_evlist__last(*pevlist); |
| 2043 | |
Ravi Bangoria | a3af66f | 2018-06-25 18:12:19 +0530 | [diff] [blame] | 2044 | if (!evsel->priv) { |
| 2045 | if (scr->per_event_dump) { |
| 2046 | evsel->priv = perf_evsel_script__new(evsel, |
| 2047 | scr->session->data); |
| 2048 | } else { |
| 2049 | es = zalloc(sizeof(*es)); |
| 2050 | if (!es) |
| 2051 | return -ENOMEM; |
| 2052 | es->fp = stdout; |
| 2053 | evsel->priv = es; |
| 2054 | } |
| 2055 | } |
| 2056 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2057 | if (evsel->core.attr.type >= PERF_TYPE_MAX && |
| 2058 | evsel->core.attr.type != PERF_TYPE_SYNTH) |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2059 | return 0; |
| 2060 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2061 | evlist__for_each_entry(evlist, pos) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2062 | if (pos->core.attr.type == evsel->core.attr.type && pos != evsel) |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2063 | return 0; |
| 2064 | } |
| 2065 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2066 | set_print_ip_opts(&evsel->core.attr); |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2067 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2068 | if (evsel->core.attr.sample_type) |
Jiri Olsa | d2b5a31 | 2015-10-16 12:41:25 +0200 | [diff] [blame] | 2069 | err = perf_evsel__check_attr(evsel, scr->session); |
| 2070 | |
| 2071 | return err; |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2074 | static int process_comm_event(struct perf_tool *tool, |
| 2075 | union perf_event *event, |
| 2076 | struct perf_sample *sample, |
| 2077 | struct machine *machine) |
| 2078 | { |
| 2079 | struct thread *thread; |
| 2080 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2081 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2082 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2083 | int ret = -1; |
| 2084 | |
| 2085 | thread = machine__findnew_thread(machine, event->comm.pid, event->comm.tid); |
| 2086 | if (thread == NULL) { |
| 2087 | pr_debug("problem processing COMM event, skipping it.\n"); |
| 2088 | return -1; |
| 2089 | } |
| 2090 | |
| 2091 | if (perf_event__process_comm(tool, event, sample, machine) < 0) |
| 2092 | goto out; |
| 2093 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2094 | if (!evsel->core.attr.sample_id_all) { |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2095 | sample->cpu = 0; |
| 2096 | sample->time = 0; |
| 2097 | sample->tid = event->comm.tid; |
| 2098 | sample->pid = event->comm.pid; |
| 2099 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2100 | if (!filter_cpu(sample)) { |
| 2101 | perf_sample__fprintf_start(sample, thread, evsel, |
Jiri Olsa | 28a0b39 | 2018-01-07 17:03:52 +0100 | [diff] [blame] | 2102 | PERF_RECORD_COMM, stdout); |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2103 | perf_event__fprintf(event, stdout); |
| 2104 | } |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2105 | ret = 0; |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2106 | out: |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2107 | thread__put(thread); |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2108 | return ret; |
| 2109 | } |
| 2110 | |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 2111 | static int process_namespaces_event(struct perf_tool *tool, |
| 2112 | union perf_event *event, |
| 2113 | struct perf_sample *sample, |
| 2114 | struct machine *machine) |
| 2115 | { |
| 2116 | struct thread *thread; |
| 2117 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2118 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2119 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 2120 | int ret = -1; |
| 2121 | |
| 2122 | thread = machine__findnew_thread(machine, event->namespaces.pid, |
| 2123 | event->namespaces.tid); |
| 2124 | if (thread == NULL) { |
| 2125 | pr_debug("problem processing NAMESPACES event, skipping it.\n"); |
| 2126 | return -1; |
| 2127 | } |
| 2128 | |
| 2129 | if (perf_event__process_namespaces(tool, event, sample, machine) < 0) |
| 2130 | goto out; |
| 2131 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2132 | if (!evsel->core.attr.sample_id_all) { |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 2133 | sample->cpu = 0; |
| 2134 | sample->time = 0; |
| 2135 | sample->tid = event->namespaces.tid; |
| 2136 | sample->pid = event->namespaces.pid; |
| 2137 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2138 | if (!filter_cpu(sample)) { |
| 2139 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2140 | PERF_RECORD_NAMESPACES, stdout); |
| 2141 | perf_event__fprintf(event, stdout); |
| 2142 | } |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 2143 | ret = 0; |
| 2144 | out: |
| 2145 | thread__put(thread); |
| 2146 | return ret; |
| 2147 | } |
| 2148 | |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2149 | static int process_fork_event(struct perf_tool *tool, |
| 2150 | union perf_event *event, |
| 2151 | struct perf_sample *sample, |
| 2152 | struct machine *machine) |
| 2153 | { |
| 2154 | struct thread *thread; |
| 2155 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2156 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2157 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2158 | |
| 2159 | if (perf_event__process_fork(tool, event, sample, machine) < 0) |
| 2160 | return -1; |
| 2161 | |
| 2162 | thread = machine__findnew_thread(machine, event->fork.pid, event->fork.tid); |
| 2163 | if (thread == NULL) { |
| 2164 | pr_debug("problem processing FORK event, skipping it.\n"); |
| 2165 | return -1; |
| 2166 | } |
| 2167 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2168 | if (!evsel->core.attr.sample_id_all) { |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2169 | sample->cpu = 0; |
| 2170 | sample->time = event->fork.time; |
| 2171 | sample->tid = event->fork.tid; |
| 2172 | sample->pid = event->fork.pid; |
| 2173 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2174 | if (!filter_cpu(sample)) { |
| 2175 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2176 | PERF_RECORD_FORK, stdout); |
| 2177 | perf_event__fprintf(event, stdout); |
| 2178 | } |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2179 | thread__put(thread); |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2180 | |
| 2181 | return 0; |
| 2182 | } |
| 2183 | static int process_exit_event(struct perf_tool *tool, |
| 2184 | union perf_event *event, |
| 2185 | struct perf_sample *sample, |
| 2186 | struct machine *machine) |
| 2187 | { |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2188 | int err = 0; |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2189 | struct thread *thread; |
| 2190 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2191 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2192 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2193 | |
| 2194 | thread = machine__findnew_thread(machine, event->fork.pid, event->fork.tid); |
| 2195 | if (thread == NULL) { |
| 2196 | pr_debug("problem processing EXIT event, skipping it.\n"); |
| 2197 | return -1; |
| 2198 | } |
| 2199 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2200 | if (!evsel->core.attr.sample_id_all) { |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2201 | sample->cpu = 0; |
| 2202 | sample->time = 0; |
Adrian Hunter | 53ff6bc | 2015-08-18 12:07:05 +0300 | [diff] [blame] | 2203 | sample->tid = event->fork.tid; |
| 2204 | sample->pid = event->fork.pid; |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2205 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2206 | if (!filter_cpu(sample)) { |
| 2207 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2208 | PERF_RECORD_EXIT, stdout); |
| 2209 | perf_event__fprintf(event, stdout); |
| 2210 | } |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2211 | |
| 2212 | if (perf_event__process_exit(tool, event, sample, machine) < 0) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2213 | err = -1; |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2214 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2215 | thread__put(thread); |
| 2216 | return err; |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2217 | } |
| 2218 | |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2219 | static int process_mmap_event(struct perf_tool *tool, |
| 2220 | union perf_event *event, |
| 2221 | struct perf_sample *sample, |
| 2222 | struct machine *machine) |
| 2223 | { |
| 2224 | struct thread *thread; |
| 2225 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2226 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2227 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2228 | |
| 2229 | if (perf_event__process_mmap(tool, event, sample, machine) < 0) |
| 2230 | return -1; |
| 2231 | |
| 2232 | thread = machine__findnew_thread(machine, event->mmap.pid, event->mmap.tid); |
| 2233 | if (thread == NULL) { |
| 2234 | pr_debug("problem processing MMAP event, skipping it.\n"); |
| 2235 | return -1; |
| 2236 | } |
| 2237 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2238 | if (!evsel->core.attr.sample_id_all) { |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2239 | sample->cpu = 0; |
| 2240 | sample->time = 0; |
| 2241 | sample->tid = event->mmap.tid; |
| 2242 | sample->pid = event->mmap.pid; |
| 2243 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2244 | if (!filter_cpu(sample)) { |
| 2245 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2246 | PERF_RECORD_MMAP, stdout); |
| 2247 | perf_event__fprintf(event, stdout); |
| 2248 | } |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2249 | thread__put(thread); |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | static int process_mmap2_event(struct perf_tool *tool, |
| 2254 | union perf_event *event, |
| 2255 | struct perf_sample *sample, |
| 2256 | struct machine *machine) |
| 2257 | { |
| 2258 | struct thread *thread; |
| 2259 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2260 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2261 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2262 | |
| 2263 | if (perf_event__process_mmap2(tool, event, sample, machine) < 0) |
| 2264 | return -1; |
| 2265 | |
| 2266 | thread = machine__findnew_thread(machine, event->mmap2.pid, event->mmap2.tid); |
| 2267 | if (thread == NULL) { |
| 2268 | pr_debug("problem processing MMAP2 event, skipping it.\n"); |
| 2269 | return -1; |
| 2270 | } |
| 2271 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2272 | if (!evsel->core.attr.sample_id_all) { |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2273 | sample->cpu = 0; |
| 2274 | sample->time = 0; |
| 2275 | sample->tid = event->mmap2.tid; |
| 2276 | sample->pid = event->mmap2.pid; |
| 2277 | } |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2278 | if (!filter_cpu(sample)) { |
| 2279 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2280 | PERF_RECORD_MMAP2, stdout); |
| 2281 | perf_event__fprintf(event, stdout); |
| 2282 | } |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2283 | thread__put(thread); |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2284 | return 0; |
| 2285 | } |
| 2286 | |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 2287 | static int process_switch_event(struct perf_tool *tool, |
| 2288 | union perf_event *event, |
| 2289 | struct perf_sample *sample, |
| 2290 | struct machine *machine) |
| 2291 | { |
| 2292 | struct thread *thread; |
| 2293 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2294 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2295 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 2296 | |
| 2297 | if (perf_event__process_switch(tool, event, sample, machine) < 0) |
| 2298 | return -1; |
| 2299 | |
Adrian Hunter | 5bf83c2 | 2019-07-10 11:58:06 +0300 | [diff] [blame] | 2300 | if (scripting_ops && scripting_ops->process_switch) |
| 2301 | scripting_ops->process_switch(event, sample, machine); |
| 2302 | |
| 2303 | if (!script->show_switch_events) |
| 2304 | return 0; |
| 2305 | |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 2306 | thread = machine__findnew_thread(machine, sample->pid, |
| 2307 | sample->tid); |
| 2308 | if (thread == NULL) { |
| 2309 | pr_debug("problem processing SWITCH event, skipping it.\n"); |
| 2310 | return -1; |
| 2311 | } |
| 2312 | |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2313 | if (!filter_cpu(sample)) { |
| 2314 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2315 | PERF_RECORD_SWITCH, stdout); |
| 2316 | perf_event__fprintf(event, stdout); |
| 2317 | } |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 2318 | thread__put(thread); |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 2322 | static int |
| 2323 | process_lost_event(struct perf_tool *tool, |
| 2324 | union perf_event *event, |
| 2325 | struct perf_sample *sample, |
| 2326 | struct machine *machine) |
| 2327 | { |
| 2328 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2329 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2330 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 2331 | struct thread *thread; |
| 2332 | |
| 2333 | thread = machine__findnew_thread(machine, sample->pid, |
| 2334 | sample->tid); |
| 2335 | if (thread == NULL) |
| 2336 | return -1; |
| 2337 | |
Andi Kleen | e87e548 | 2019-03-11 07:44:52 -0700 | [diff] [blame] | 2338 | if (!filter_cpu(sample)) { |
| 2339 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2340 | PERF_RECORD_LOST, stdout); |
| 2341 | perf_event__fprintf(event, stdout); |
| 2342 | } |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 2343 | thread__put(thread); |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
Jiri Olsa | 3233b37 | 2018-02-06 19:17:59 +0100 | [diff] [blame] | 2347 | static int |
| 2348 | process_finished_round_event(struct perf_tool *tool __maybe_unused, |
| 2349 | union perf_event *event, |
| 2350 | struct ordered_events *oe __maybe_unused) |
| 2351 | |
| 2352 | { |
| 2353 | perf_event__fprintf(event, stdout); |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 2357 | static int |
| 2358 | process_bpf_events(struct perf_tool *tool __maybe_unused, |
| 2359 | union perf_event *event, |
| 2360 | struct perf_sample *sample, |
| 2361 | struct machine *machine) |
| 2362 | { |
| 2363 | struct thread *thread; |
| 2364 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 2365 | struct perf_session *session = script->session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2366 | struct evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 2367 | |
| 2368 | if (machine__process_ksymbol(machine, event, sample) < 0) |
| 2369 | return -1; |
| 2370 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2371 | if (!evsel->core.attr.sample_id_all) { |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 2372 | perf_event__fprintf(event, stdout); |
| 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | thread = machine__findnew_thread(machine, sample->pid, sample->tid); |
| 2377 | if (thread == NULL) { |
| 2378 | pr_debug("problem processing MMAP event, skipping it.\n"); |
| 2379 | return -1; |
| 2380 | } |
| 2381 | |
| 2382 | if (!filter_cpu(sample)) { |
| 2383 | perf_sample__fprintf_start(sample, thread, evsel, |
| 2384 | event->header.type, stdout); |
| 2385 | perf_event__fprintf(event, stdout); |
| 2386 | } |
| 2387 | |
| 2388 | thread__put(thread); |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2392 | static void sig_handler(int sig __maybe_unused) |
Tom Zanussi | c239da3 | 2010-04-01 23:59:18 -0500 | [diff] [blame] | 2393 | { |
| 2394 | session_done = 1; |
| 2395 | } |
| 2396 | |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2397 | static void perf_script__fclose_per_event_dump(struct perf_script *script) |
| 2398 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2399 | struct evlist *evlist = script->session->evlist; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2400 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2401 | |
| 2402 | evlist__for_each_entry(evlist, evsel) { |
| 2403 | if (!evsel->priv) |
| 2404 | break; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2405 | perf_evsel_script__delete(evsel->priv); |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2406 | evsel->priv = NULL; |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | static int perf_script__fopen_per_event_dump(struct perf_script *script) |
| 2411 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2412 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2413 | |
| 2414 | evlist__for_each_entry(script->session->evlist, evsel) { |
Arnaldo Carvalho de Melo | fa48c89 | 2017-11-09 16:04:26 -0300 | [diff] [blame] | 2415 | /* |
| 2416 | * Already setup? I.e. we may be called twice in cases like |
| 2417 | * Intel PT, one for the intel_pt// and dummy events, then |
| 2418 | * for the evsels syntheized from the auxtrace info. |
| 2419 | * |
| 2420 | * Ses perf_script__process_auxtrace_info. |
| 2421 | */ |
| 2422 | if (evsel->priv != NULL) |
| 2423 | continue; |
| 2424 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2425 | evsel->priv = perf_evsel_script__new(evsel, script->session->data); |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2426 | if (evsel->priv == NULL) |
| 2427 | goto out_err_fclose; |
| 2428 | } |
| 2429 | |
| 2430 | return 0; |
| 2431 | |
| 2432 | out_err_fclose: |
| 2433 | perf_script__fclose_per_event_dump(script); |
| 2434 | return -1; |
| 2435 | } |
| 2436 | |
| 2437 | static int perf_script__setup_per_event_dump(struct perf_script *script) |
| 2438 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2439 | struct evsel *evsel; |
| 2440 | static struct evsel_script es_stdout; |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2441 | |
| 2442 | if (script->per_event_dump) |
| 2443 | return perf_script__fopen_per_event_dump(script); |
| 2444 | |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2445 | es_stdout.fp = stdout; |
| 2446 | |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2447 | evlist__for_each_entry(script->session->evlist, evsel) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2448 | evsel->priv = &es_stdout; |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2449 | |
| 2450 | return 0; |
| 2451 | } |
| 2452 | |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2453 | static void perf_script__exit_per_event_dump_stats(struct perf_script *script) |
| 2454 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2455 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2456 | |
| 2457 | evlist__for_each_entry(script->session->evlist, evsel) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2458 | struct evsel_script *es = evsel->priv; |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2459 | |
| 2460 | perf_evsel_script__fprintf(es, stdout); |
| 2461 | perf_evsel_script__delete(es); |
| 2462 | evsel->priv = NULL; |
| 2463 | } |
| 2464 | } |
| 2465 | |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 2466 | static int __cmd_script(struct perf_script *script) |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 2467 | { |
Frederic Weisbecker | 6fcf7dd | 2010-05-27 15:46:25 +0200 | [diff] [blame] | 2468 | int ret; |
| 2469 | |
Tom Zanussi | c239da3 | 2010-04-01 23:59:18 -0500 | [diff] [blame] | 2470 | signal(SIGINT, sig_handler); |
| 2471 | |
Tony Jones | 8bf8c6d | 2019-01-20 11:14:14 -0800 | [diff] [blame] | 2472 | perf_stat__init_shadow_stats(); |
| 2473 | |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2474 | /* override event processing functions */ |
| 2475 | if (script->show_task_events) { |
| 2476 | script->tool.comm = process_comm_event; |
| 2477 | script->tool.fork = process_fork_event; |
| 2478 | script->tool.exit = process_exit_event; |
| 2479 | } |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 2480 | if (script->show_mmap_events) { |
| 2481 | script->tool.mmap = process_mmap_event; |
| 2482 | script->tool.mmap2 = process_mmap2_event; |
| 2483 | } |
Adrian Hunter | 5bf83c2 | 2019-07-10 11:58:06 +0300 | [diff] [blame] | 2484 | if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 2485 | script->tool.context_switch = process_switch_event; |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 2486 | if (script->show_namespace_events) |
| 2487 | script->tool.namespaces = process_namespaces_event; |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 2488 | if (script->show_lost_events) |
| 2489 | script->tool.lost = process_lost_event; |
Jiri Olsa | 3233b37 | 2018-02-06 19:17:59 +0100 | [diff] [blame] | 2490 | if (script->show_round_events) { |
| 2491 | script->tool.ordered_events = false; |
| 2492 | script->tool.finished_round = process_finished_round_event; |
| 2493 | } |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 2494 | if (script->show_bpf_events) { |
| 2495 | script->tool.ksymbol = process_bpf_events; |
| 2496 | script->tool.bpf_event = process_bpf_events; |
| 2497 | } |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 2498 | |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2499 | if (perf_script__setup_per_event_dump(script)) { |
| 2500 | pr_err("Couldn't create the per event dump files\n"); |
| 2501 | return -1; |
| 2502 | } |
| 2503 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 2504 | ret = perf_session__process_events(script->session); |
Frederic Weisbecker | 6fcf7dd | 2010-05-27 15:46:25 +0200 | [diff] [blame] | 2505 | |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2506 | if (script->per_event_dump) |
Arnaldo Carvalho de Melo | 642ee1c | 2017-10-30 13:11:15 -0300 | [diff] [blame] | 2507 | perf_script__exit_per_event_dump_stats(script); |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 2508 | |
Arnaldo Carvalho de Melo | 6d8afb5 | 2011-01-04 16:27:30 -0200 | [diff] [blame] | 2509 | if (debug_mode) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 2510 | pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); |
Frederic Weisbecker | 6fcf7dd | 2010-05-27 15:46:25 +0200 | [diff] [blame] | 2511 | |
| 2512 | return ret; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 2513 | } |
| 2514 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2515 | struct script_spec { |
| 2516 | struct list_head node; |
| 2517 | struct scripting_ops *ops; |
| 2518 | char spec[0]; |
| 2519 | }; |
| 2520 | |
Arnaldo Carvalho de Melo | eccdfe2 | 2011-01-04 16:32:52 -0200 | [diff] [blame] | 2521 | static LIST_HEAD(script_specs); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2522 | |
| 2523 | static struct script_spec *script_spec__new(const char *spec, |
| 2524 | struct scripting_ops *ops) |
| 2525 | { |
| 2526 | struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1); |
| 2527 | |
| 2528 | if (s != NULL) { |
| 2529 | strcpy(s->spec, spec); |
| 2530 | s->ops = ops; |
| 2531 | } |
| 2532 | |
| 2533 | return s; |
| 2534 | } |
| 2535 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2536 | static void script_spec__add(struct script_spec *s) |
| 2537 | { |
| 2538 | list_add_tail(&s->node, &script_specs); |
| 2539 | } |
| 2540 | |
| 2541 | static struct script_spec *script_spec__find(const char *spec) |
| 2542 | { |
| 2543 | struct script_spec *s; |
| 2544 | |
| 2545 | list_for_each_entry(s, &script_specs, node) |
| 2546 | if (strcasecmp(s->spec, spec) == 0) |
| 2547 | return s; |
| 2548 | return NULL; |
| 2549 | } |
| 2550 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2551 | int script_spec_register(const char *spec, struct scripting_ops *ops) |
| 2552 | { |
| 2553 | struct script_spec *s; |
| 2554 | |
| 2555 | s = script_spec__find(spec); |
| 2556 | if (s) |
| 2557 | return -1; |
| 2558 | |
Taeung Song | 8560bae | 2016-02-26 00:13:10 +0900 | [diff] [blame] | 2559 | s = script_spec__new(spec, ops); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2560 | if (!s) |
| 2561 | return -1; |
Taeung Song | 8560bae | 2016-02-26 00:13:10 +0900 | [diff] [blame] | 2562 | else |
| 2563 | script_spec__add(s); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2564 | |
| 2565 | return 0; |
| 2566 | } |
| 2567 | |
| 2568 | static struct scripting_ops *script_spec__lookup(const char *spec) |
| 2569 | { |
| 2570 | struct script_spec *s = script_spec__find(spec); |
| 2571 | if (!s) |
| 2572 | return NULL; |
| 2573 | |
| 2574 | return s->ops; |
| 2575 | } |
| 2576 | |
| 2577 | static void list_available_languages(void) |
| 2578 | { |
| 2579 | struct script_spec *s; |
| 2580 | |
| 2581 | fprintf(stderr, "\n"); |
| 2582 | fprintf(stderr, "Scripting language extensions (used in " |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 2583 | "perf script -s [spec:]script.[spec]):\n\n"); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2584 | |
| 2585 | list_for_each_entry(s, &script_specs, node) |
| 2586 | fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); |
| 2587 | |
| 2588 | fprintf(stderr, "\n"); |
| 2589 | } |
| 2590 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2591 | static int parse_scriptname(const struct option *opt __maybe_unused, |
| 2592 | const char *str, int unset __maybe_unused) |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2593 | { |
| 2594 | char spec[PATH_MAX]; |
| 2595 | const char *script, *ext; |
| 2596 | int len; |
| 2597 | |
Tom Zanussi | f526d68 | 2010-01-27 02:27:52 -0600 | [diff] [blame] | 2598 | if (strcmp(str, "lang") == 0) { |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2599 | list_available_languages(); |
Tom Zanussi | f526d68 | 2010-01-27 02:27:52 -0600 | [diff] [blame] | 2600 | exit(0); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | script = strchr(str, ':'); |
| 2604 | if (script) { |
| 2605 | len = script - str; |
| 2606 | if (len >= PATH_MAX) { |
| 2607 | fprintf(stderr, "invalid language specifier"); |
| 2608 | return -1; |
| 2609 | } |
| 2610 | strncpy(spec, str, len); |
| 2611 | spec[len] = '\0'; |
| 2612 | scripting_ops = script_spec__lookup(spec); |
| 2613 | if (!scripting_ops) { |
| 2614 | fprintf(stderr, "invalid language specifier"); |
| 2615 | return -1; |
| 2616 | } |
| 2617 | script++; |
| 2618 | } else { |
| 2619 | script = str; |
Ben Hutchings | d1e95bb | 2010-10-10 16:11:02 +0100 | [diff] [blame] | 2620 | ext = strrchr(script, '.'); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 2621 | if (!ext) { |
| 2622 | fprintf(stderr, "invalid script extension"); |
| 2623 | return -1; |
| 2624 | } |
| 2625 | scripting_ops = script_spec__lookup(++ext); |
| 2626 | if (!scripting_ops) { |
| 2627 | fprintf(stderr, "invalid script extension"); |
| 2628 | return -1; |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | script_name = strdup(script); |
| 2633 | |
| 2634 | return 0; |
| 2635 | } |
| 2636 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2637 | static int parse_output_fields(const struct option *opt __maybe_unused, |
| 2638 | const char *arg, int unset __maybe_unused) |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2639 | { |
Arnaldo Carvalho de Melo | 49346e8 | 2017-04-05 11:43:41 -0300 | [diff] [blame] | 2640 | char *tok, *strtok_saveptr = NULL; |
Sasha Levin | 50ca19a | 2012-12-20 14:11:19 -0500 | [diff] [blame] | 2641 | int i, imax = ARRAY_SIZE(all_output_options); |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2642 | int j; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2643 | int rc = 0; |
| 2644 | char *str = strdup(arg); |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 2645 | int type = -1; |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2646 | enum { DEFAULT, SET, ADD, REMOVE } change = DEFAULT; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2647 | |
| 2648 | if (!str) |
| 2649 | return -ENOMEM; |
| 2650 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2651 | /* first word can state for which event type the user is specifying |
| 2652 | * the fields. If no type exists, the specified fields apply to all |
| 2653 | * event types found in the file minus the invalid fields for a type. |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 2654 | */ |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2655 | tok = strchr(str, ':'); |
| 2656 | if (tok) { |
| 2657 | *tok = '\0'; |
| 2658 | tok++; |
| 2659 | if (!strcmp(str, "hw")) |
| 2660 | type = PERF_TYPE_HARDWARE; |
| 2661 | else if (!strcmp(str, "sw")) |
| 2662 | type = PERF_TYPE_SOFTWARE; |
| 2663 | else if (!strcmp(str, "trace")) |
| 2664 | type = PERF_TYPE_TRACEPOINT; |
Arun Sharma | 0817a6a | 2011-04-14 10:38:18 -0700 | [diff] [blame] | 2665 | else if (!strcmp(str, "raw")) |
| 2666 | type = PERF_TYPE_RAW; |
Wang Nan | 27cfef0 | 2015-12-08 02:25:43 +0000 | [diff] [blame] | 2667 | else if (!strcmp(str, "break")) |
| 2668 | type = PERF_TYPE_BREAKPOINT; |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 2669 | else if (!strcmp(str, "synth")) |
| 2670 | type = OUTPUT_TYPE_SYNTH; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2671 | else { |
| 2672 | fprintf(stderr, "Invalid event type in field string.\n"); |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 2673 | rc = -EINVAL; |
| 2674 | goto out; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | if (output[type].user_set) |
| 2678 | pr_warning("Overriding previous field request for %s events.\n", |
| 2679 | event_type(type)); |
| 2680 | |
Jiri Olsa | 6ef362f | 2019-02-20 13:27:57 +0100 | [diff] [blame] | 2681 | /* Don't override defaults for +- */ |
| 2682 | if (strchr(tok, '+') || strchr(tok, '-')) |
| 2683 | goto parse; |
| 2684 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2685 | output[type].fields = 0; |
| 2686 | output[type].user_set = true; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 2687 | output[type].wildcard_set = false; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2688 | |
| 2689 | } else { |
| 2690 | tok = str; |
| 2691 | if (strlen(str) == 0) { |
| 2692 | fprintf(stderr, |
| 2693 | "Cannot set fields to 'none' for all event types.\n"); |
| 2694 | rc = -EINVAL; |
| 2695 | goto out; |
| 2696 | } |
| 2697 | |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2698 | /* Don't override defaults for +- */ |
| 2699 | if (strchr(str, '+') || strchr(str, '-')) |
| 2700 | goto parse; |
| 2701 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2702 | if (output_set_by_user()) |
| 2703 | pr_warning("Overriding previous field request for all events.\n"); |
| 2704 | |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 2705 | for (j = 0; j < OUTPUT_TYPE_MAX; ++j) { |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2706 | output[j].fields = 0; |
| 2707 | output[j].user_set = true; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 2708 | output[j].wildcard_set = true; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2709 | } |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2712 | parse: |
Arnaldo Carvalho de Melo | 49346e8 | 2017-04-05 11:43:41 -0300 | [diff] [blame] | 2713 | for (tok = strtok_r(tok, ",", &strtok_saveptr); tok; tok = strtok_r(NULL, ",", &strtok_saveptr)) { |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2714 | if (*tok == '+') { |
| 2715 | if (change == SET) |
| 2716 | goto out_badmix; |
| 2717 | change = ADD; |
| 2718 | tok++; |
| 2719 | } else if (*tok == '-') { |
| 2720 | if (change == SET) |
| 2721 | goto out_badmix; |
| 2722 | change = REMOVE; |
| 2723 | tok++; |
| 2724 | } else { |
| 2725 | if (change != SET && change != DEFAULT) |
| 2726 | goto out_badmix; |
| 2727 | change = SET; |
| 2728 | } |
| 2729 | |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2730 | for (i = 0; i < imax; ++i) { |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2731 | if (strcmp(tok, all_output_options[i].str) == 0) |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2732 | break; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2733 | } |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 2734 | if (i == imax && strcmp(tok, "flags") == 0) { |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2735 | print_flags = change == REMOVE ? false : true; |
Adrian Hunter | 400ea6d | 2015-04-09 18:54:05 +0300 | [diff] [blame] | 2736 | continue; |
| 2737 | } |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2738 | if (i == imax) { |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2739 | fprintf(stderr, "Invalid field requested.\n"); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2740 | rc = -EINVAL; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2741 | goto out; |
| 2742 | } |
| 2743 | |
| 2744 | if (type == -1) { |
| 2745 | /* add user option to all events types for |
| 2746 | * which it is valid |
| 2747 | */ |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 2748 | for (j = 0; j < OUTPUT_TYPE_MAX; ++j) { |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2749 | if (output[j].invalid_fields & all_output_options[i].field) { |
| 2750 | pr_warning("\'%s\' not valid for %s events. Ignoring.\n", |
| 2751 | all_output_options[i].str, event_type(j)); |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2752 | } else { |
Andi Kleen | 4b6ac81 | 2019-02-24 07:37:12 -0800 | [diff] [blame] | 2753 | if (change == REMOVE) { |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2754 | output[j].fields &= ~all_output_options[i].field; |
Andi Kleen | 4b6ac81 | 2019-02-24 07:37:12 -0800 | [diff] [blame] | 2755 | output[j].user_set_fields &= ~all_output_options[i].field; |
| 2756 | } else { |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2757 | output[j].fields |= all_output_options[i].field; |
Andi Kleen | 4b6ac81 | 2019-02-24 07:37:12 -0800 | [diff] [blame] | 2758 | output[j].user_set_fields |= all_output_options[i].field; |
| 2759 | } |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 2760 | output[j].user_set = true; |
| 2761 | output[j].wildcard_set = true; |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2762 | } |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2763 | } |
| 2764 | } else { |
| 2765 | if (output[type].invalid_fields & all_output_options[i].field) { |
| 2766 | fprintf(stderr, "\'%s\' not valid for %s events.\n", |
| 2767 | all_output_options[i].str, event_type(type)); |
| 2768 | |
| 2769 | rc = -EINVAL; |
| 2770 | goto out; |
| 2771 | } |
Jiri Olsa | 6ef362f | 2019-02-20 13:27:57 +0100 | [diff] [blame] | 2772 | if (change == REMOVE) |
| 2773 | output[type].fields &= ~all_output_options[i].field; |
| 2774 | else |
| 2775 | output[type].fields |= all_output_options[i].field; |
Andi Kleen | 37fed3d | 2018-09-18 05:32:09 -0700 | [diff] [blame] | 2776 | output[type].user_set = true; |
| 2777 | output[type].wildcard_set = true; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2778 | } |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | if (type >= 0) { |
| 2782 | if (output[type].fields == 0) { |
| 2783 | pr_debug("No fields requested for %s type. " |
| 2784 | "Events will not be displayed.\n", event_type(type)); |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2785 | } |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 2786 | } |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2787 | goto out; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2788 | |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 2789 | out_badmix: |
| 2790 | fprintf(stderr, "Cannot mix +-field with overridden fields\n"); |
| 2791 | rc = -EINVAL; |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 2792 | out: |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 2793 | free(str); |
| 2794 | return rc; |
| 2795 | } |
| 2796 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 2797 | #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \ |
| 2798 | while ((lang_dirent = readdir(scripts_dir)) != NULL) \ |
| 2799 | if ((lang_dirent->d_type == DT_DIR || \ |
| 2800 | (lang_dirent->d_type == DT_UNKNOWN && \ |
| 2801 | is_directory(scripts_path, lang_dirent))) && \ |
| 2802 | (strcmp(lang_dirent->d_name, ".")) && \ |
| 2803 | (strcmp(lang_dirent->d_name, ".."))) |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2804 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 2805 | #define for_each_script(lang_path, lang_dir, script_dirent) \ |
| 2806 | while ((script_dirent = readdir(lang_dir)) != NULL) \ |
| 2807 | if (script_dirent->d_type != DT_DIR && \ |
| 2808 | (script_dirent->d_type != DT_UNKNOWN || \ |
| 2809 | !is_directory(lang_path, script_dirent))) |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2810 | |
| 2811 | |
| 2812 | #define RECORD_SUFFIX "-record" |
| 2813 | #define REPORT_SUFFIX "-report" |
| 2814 | |
| 2815 | struct script_desc { |
| 2816 | struct list_head node; |
| 2817 | char *name; |
| 2818 | char *half_liner; |
| 2819 | char *args; |
| 2820 | }; |
| 2821 | |
Arnaldo Carvalho de Melo | eccdfe2 | 2011-01-04 16:32:52 -0200 | [diff] [blame] | 2822 | static LIST_HEAD(script_descs); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2823 | |
| 2824 | static struct script_desc *script_desc__new(const char *name) |
| 2825 | { |
| 2826 | struct script_desc *s = zalloc(sizeof(*s)); |
| 2827 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 2828 | if (s != NULL && name) |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2829 | s->name = strdup(name); |
| 2830 | |
| 2831 | return s; |
| 2832 | } |
| 2833 | |
| 2834 | static void script_desc__delete(struct script_desc *s) |
| 2835 | { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 2836 | zfree(&s->name); |
| 2837 | zfree(&s->half_liner); |
| 2838 | zfree(&s->args); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2839 | free(s); |
| 2840 | } |
| 2841 | |
| 2842 | static void script_desc__add(struct script_desc *s) |
| 2843 | { |
| 2844 | list_add_tail(&s->node, &script_descs); |
| 2845 | } |
| 2846 | |
| 2847 | static struct script_desc *script_desc__find(const char *name) |
| 2848 | { |
| 2849 | struct script_desc *s; |
| 2850 | |
| 2851 | list_for_each_entry(s, &script_descs, node) |
| 2852 | if (strcasecmp(s->name, name) == 0) |
| 2853 | return s; |
| 2854 | return NULL; |
| 2855 | } |
| 2856 | |
| 2857 | static struct script_desc *script_desc__findnew(const char *name) |
| 2858 | { |
| 2859 | struct script_desc *s = script_desc__find(name); |
| 2860 | |
| 2861 | if (s) |
| 2862 | return s; |
| 2863 | |
| 2864 | s = script_desc__new(name); |
| 2865 | if (!s) |
Dan Carpenter | 2ec5cab6 | 2017-07-22 10:36:10 +0300 | [diff] [blame] | 2866 | return NULL; |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2867 | |
| 2868 | script_desc__add(s); |
| 2869 | |
| 2870 | return s; |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2871 | } |
| 2872 | |
Stephane Eranian | 965bb6b | 2010-12-03 17:52:01 +0200 | [diff] [blame] | 2873 | static const char *ends_with(const char *str, const char *suffix) |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2874 | { |
| 2875 | size_t suffix_len = strlen(suffix); |
Stephane Eranian | 965bb6b | 2010-12-03 17:52:01 +0200 | [diff] [blame] | 2876 | const char *p = str; |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2877 | |
| 2878 | if (strlen(str) > suffix_len) { |
| 2879 | p = str + strlen(str) - suffix_len; |
| 2880 | if (!strncmp(p, suffix, suffix_len)) |
| 2881 | return p; |
| 2882 | } |
| 2883 | |
| 2884 | return NULL; |
| 2885 | } |
| 2886 | |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2887 | static int read_script_info(struct script_desc *desc, const char *filename) |
| 2888 | { |
| 2889 | char line[BUFSIZ], *p; |
| 2890 | FILE *fp; |
| 2891 | |
| 2892 | fp = fopen(filename, "r"); |
| 2893 | if (!fp) |
| 2894 | return -1; |
| 2895 | |
| 2896 | while (fgets(line, sizeof(line), fp)) { |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 2897 | p = skip_spaces(line); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2898 | if (strlen(p) == 0) |
| 2899 | continue; |
| 2900 | if (*p != '#') |
| 2901 | continue; |
| 2902 | p++; |
| 2903 | if (strlen(p) && *p == '!') |
| 2904 | continue; |
| 2905 | |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 2906 | p = skip_spaces(p); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2907 | if (strlen(p) && p[strlen(p) - 1] == '\n') |
| 2908 | p[strlen(p) - 1] = '\0'; |
| 2909 | |
| 2910 | if (!strncmp(p, "description:", strlen("description:"))) { |
| 2911 | p += strlen("description:"); |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 2912 | desc->half_liner = strdup(skip_spaces(p)); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2913 | continue; |
| 2914 | } |
| 2915 | |
| 2916 | if (!strncmp(p, "args:", strlen("args:"))) { |
| 2917 | p += strlen("args:"); |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 2918 | desc->args = strdup(skip_spaces(p)); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2919 | continue; |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | fclose(fp); |
| 2924 | |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 2928 | static char *get_script_root(struct dirent *script_dirent, const char *suffix) |
| 2929 | { |
| 2930 | char *script_root, *str; |
| 2931 | |
| 2932 | script_root = strdup(script_dirent->d_name); |
| 2933 | if (!script_root) |
| 2934 | return NULL; |
| 2935 | |
| 2936 | str = (char *)ends_with(script_root, suffix); |
| 2937 | if (!str) { |
| 2938 | free(script_root); |
| 2939 | return NULL; |
| 2940 | } |
| 2941 | |
| 2942 | *str = '\0'; |
| 2943 | return script_root; |
| 2944 | } |
| 2945 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2946 | static int list_available_scripts(const struct option *opt __maybe_unused, |
| 2947 | const char *s __maybe_unused, |
| 2948 | int unset __maybe_unused) |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2949 | { |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 2950 | struct dirent *script_dirent, *lang_dirent; |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2951 | char scripts_path[MAXPATHLEN]; |
| 2952 | DIR *scripts_dir, *lang_dir; |
| 2953 | char script_path[MAXPATHLEN]; |
| 2954 | char lang_path[MAXPATHLEN]; |
| 2955 | struct script_desc *desc; |
| 2956 | char first_half[BUFSIZ]; |
| 2957 | char *script_root; |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2958 | |
Josh Poimboeuf | 46113a5 | 2015-12-15 09:39:37 -0600 | [diff] [blame] | 2959 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2960 | |
| 2961 | scripts_dir = opendir(scripts_path); |
He Kuang | 88ded4d | 2016-08-04 11:25:42 +0000 | [diff] [blame] | 2962 | if (!scripts_dir) { |
| 2963 | fprintf(stdout, |
| 2964 | "open(%s) failed.\n" |
| 2965 | "Check \"PERF_EXEC_PATH\" env to set scripts dir.\n", |
| 2966 | scripts_path); |
| 2967 | exit(-1); |
| 2968 | } |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2969 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 2970 | for_each_lang(scripts_path, scripts_dir, lang_dirent) { |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 2971 | scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, |
| 2972 | lang_dirent->d_name); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2973 | lang_dir = opendir(lang_path); |
| 2974 | if (!lang_dir) |
| 2975 | continue; |
| 2976 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 2977 | for_each_script(lang_path, lang_dir, script_dirent) { |
| 2978 | script_root = get_script_root(script_dirent, REPORT_SUFFIX); |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 2979 | if (script_root) { |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2980 | desc = script_desc__findnew(script_root); |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 2981 | scnprintf(script_path, MAXPATHLEN, "%s/%s", |
| 2982 | lang_path, script_dirent->d_name); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2983 | read_script_info(desc, script_path); |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 2984 | free(script_root); |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2985 | } |
Tom Zanussi | 4b9c0c5 | 2009-12-15 02:53:38 -0600 | [diff] [blame] | 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | fprintf(stdout, "List of available trace scripts:\n"); |
| 2990 | list_for_each_entry(desc, &script_descs, node) { |
| 2991 | sprintf(first_half, "%s %s", desc->name, |
| 2992 | desc->args ? desc->args : ""); |
| 2993 | fprintf(stdout, " %-36s %s\n", first_half, |
| 2994 | desc->half_liner ? desc->half_liner : ""); |
| 2995 | } |
| 2996 | |
| 2997 | exit(0); |
| 2998 | } |
| 2999 | |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3000 | /* |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3001 | * Some scripts specify the required events in their "xxx-record" file, |
| 3002 | * this function will check if the events in perf.data match those |
| 3003 | * mentioned in the "xxx-record". |
| 3004 | * |
| 3005 | * Fixme: All existing "xxx-record" are all in good formats "-e event ", |
| 3006 | * which is covered well now. And new parsing code should be added to |
| 3007 | * cover the future complexing formats like event groups etc. |
| 3008 | */ |
| 3009 | static int check_ev_match(char *dir_name, char *scriptname, |
| 3010 | struct perf_session *session) |
| 3011 | { |
| 3012 | char filename[MAXPATHLEN], evname[128]; |
| 3013 | char line[BUFSIZ], *p; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3014 | struct evsel *pos; |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3015 | int match, len; |
| 3016 | FILE *fp; |
| 3017 | |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 3018 | scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3019 | |
| 3020 | fp = fopen(filename, "r"); |
| 3021 | if (!fp) |
| 3022 | return -1; |
| 3023 | |
| 3024 | while (fgets(line, sizeof(line), fp)) { |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 3025 | p = skip_spaces(line); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3026 | if (*p == '#') |
| 3027 | continue; |
| 3028 | |
| 3029 | while (strlen(p)) { |
| 3030 | p = strstr(p, "-e"); |
| 3031 | if (!p) |
| 3032 | break; |
| 3033 | |
| 3034 | p += 2; |
Arnaldo Carvalho de Melo | 3285848 | 2019-06-26 11:42:03 -0300 | [diff] [blame] | 3035 | p = skip_spaces(p); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3036 | len = strcspn(p, " \t"); |
| 3037 | if (!len) |
| 3038 | break; |
| 3039 | |
| 3040 | snprintf(evname, len + 1, "%s", p); |
| 3041 | |
| 3042 | match = 0; |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3043 | evlist__for_each_entry(session->evlist, pos) { |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3044 | if (!strcmp(perf_evsel__name(pos), evname)) { |
| 3045 | match = 1; |
| 3046 | break; |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | if (!match) { |
| 3051 | fclose(fp); |
| 3052 | return -1; |
| 3053 | } |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | fclose(fp); |
| 3058 | return 0; |
| 3059 | } |
| 3060 | |
| 3061 | /* |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3062 | * Return -1 if none is found, otherwise the actual scripts number. |
| 3063 | * |
| 3064 | * Currently the only user of this function is the script browser, which |
| 3065 | * will list all statically runnable scripts, select one, execute it and |
| 3066 | * show the output in a perf browser. |
| 3067 | */ |
Andi Kleen | 905e4af | 2019-03-11 07:45:01 -0700 | [diff] [blame] | 3068 | int find_scripts(char **scripts_array, char **scripts_path_array, int num, |
| 3069 | int pathlen) |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3070 | { |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3071 | struct dirent *script_dirent, *lang_dirent; |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3072 | char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3073 | DIR *scripts_dir, *lang_dir; |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3074 | struct perf_session *session; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3075 | struct perf_data data = { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 3076 | .path = input_name, |
| 3077 | .mode = PERF_DATA_MODE_READ, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 3078 | }; |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3079 | char *temp; |
| 3080 | int i = 0; |
| 3081 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3082 | session = perf_session__new(&data, false, NULL); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3083 | if (!session) |
| 3084 | return -1; |
| 3085 | |
Josh Poimboeuf | 46113a5 | 2015-12-15 09:39:37 -0600 | [diff] [blame] | 3086 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3087 | |
| 3088 | scripts_dir = opendir(scripts_path); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3089 | if (!scripts_dir) { |
| 3090 | perf_session__delete(session); |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3091 | return -1; |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3092 | } |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3093 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3094 | for_each_lang(scripts_path, scripts_dir, lang_dirent) { |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 3095 | scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, |
| 3096 | lang_dirent->d_name); |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 3097 | #ifndef HAVE_LIBPERL_SUPPORT |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3098 | if (strstr(lang_path, "perl")) |
| 3099 | continue; |
| 3100 | #endif |
Jin Yao | 90ce61b | 2018-04-09 18:26:47 +0800 | [diff] [blame] | 3101 | #ifndef HAVE_LIBPYTHON_SUPPORT |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3102 | if (strstr(lang_path, "python")) |
| 3103 | continue; |
| 3104 | #endif |
| 3105 | |
| 3106 | lang_dir = opendir(lang_path); |
| 3107 | if (!lang_dir) |
| 3108 | continue; |
| 3109 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3110 | for_each_script(lang_path, lang_dir, script_dirent) { |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3111 | /* Skip those real time scripts: xxxtop.p[yl] */ |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3112 | if (strstr(script_dirent->d_name, "top.")) |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3113 | continue; |
Andi Kleen | 905e4af | 2019-03-11 07:45:01 -0700 | [diff] [blame] | 3114 | if (i >= num) |
| 3115 | break; |
| 3116 | snprintf(scripts_path_array[i], pathlen, "%s/%s", |
| 3117 | lang_path, |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3118 | script_dirent->d_name); |
| 3119 | temp = strchr(script_dirent->d_name, '.'); |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3120 | snprintf(scripts_array[i], |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3121 | (temp - script_dirent->d_name) + 1, |
| 3122 | "%s", script_dirent->d_name); |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3123 | |
| 3124 | if (check_ev_match(lang_path, |
| 3125 | scripts_array[i], session)) |
| 3126 | continue; |
| 3127 | |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3128 | i++; |
| 3129 | } |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3130 | closedir(lang_dir); |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3131 | } |
| 3132 | |
Feng Tang | 49e639e | 2012-10-30 11:56:03 +0800 | [diff] [blame] | 3133 | closedir(scripts_dir); |
| 3134 | perf_session__delete(session); |
Feng Tang | e5f3705 | 2012-09-07 16:42:26 +0800 | [diff] [blame] | 3135 | return i; |
| 3136 | } |
| 3137 | |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3138 | static char *get_script_path(const char *script_root, const char *suffix) |
| 3139 | { |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3140 | struct dirent *script_dirent, *lang_dirent; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3141 | char scripts_path[MAXPATHLEN]; |
| 3142 | char script_path[MAXPATHLEN]; |
| 3143 | DIR *scripts_dir, *lang_dir; |
| 3144 | char lang_path[MAXPATHLEN]; |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 3145 | char *__script_root; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3146 | |
Josh Poimboeuf | 46113a5 | 2015-12-15 09:39:37 -0600 | [diff] [blame] | 3147 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3148 | |
| 3149 | scripts_dir = opendir(scripts_path); |
| 3150 | if (!scripts_dir) |
| 3151 | return NULL; |
| 3152 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3153 | for_each_lang(scripts_path, scripts_dir, lang_dirent) { |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 3154 | scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, |
| 3155 | lang_dirent->d_name); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3156 | lang_dir = opendir(lang_path); |
| 3157 | if (!lang_dir) |
| 3158 | continue; |
| 3159 | |
Arnaldo Carvalho de Melo | a5e8e82 | 2016-04-08 11:25:59 -0300 | [diff] [blame] | 3160 | for_each_script(lang_path, lang_dir, script_dirent) { |
| 3161 | __script_root = get_script_root(script_dirent, suffix); |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 3162 | if (__script_root && !strcmp(script_root, __script_root)) { |
| 3163 | free(__script_root); |
Namhyung Kim | 946ef2a | 2012-01-08 02:25:25 +0900 | [diff] [blame] | 3164 | closedir(lang_dir); |
| 3165 | closedir(scripts_dir); |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 3166 | scnprintf(script_path, MAXPATHLEN, "%s/%s", |
| 3167 | lang_path, script_dirent->d_name); |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 3168 | return strdup(script_path); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3169 | } |
| 3170 | free(__script_root); |
| 3171 | } |
Namhyung Kim | 946ef2a | 2012-01-08 02:25:25 +0900 | [diff] [blame] | 3172 | closedir(lang_dir); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3173 | } |
Namhyung Kim | 946ef2a | 2012-01-08 02:25:25 +0900 | [diff] [blame] | 3174 | closedir(scripts_dir); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3175 | |
Robert Richter | 38efb53 | 2011-11-25 11:38:40 +0100 | [diff] [blame] | 3176 | return NULL; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3177 | } |
| 3178 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3179 | static bool is_top_script(const char *script_path) |
| 3180 | { |
Stephane Eranian | 965bb6b | 2010-12-03 17:52:01 +0200 | [diff] [blame] | 3181 | return ends_with(script_path, "top") == NULL ? false : true; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static int has_required_arg(char *script_path) |
| 3185 | { |
| 3186 | struct script_desc *desc; |
| 3187 | int n_args = 0; |
| 3188 | char *p; |
| 3189 | |
| 3190 | desc = script_desc__new(NULL); |
| 3191 | |
| 3192 | if (read_script_info(desc, script_path)) |
| 3193 | goto out; |
| 3194 | |
| 3195 | if (!desc->args) |
| 3196 | goto out; |
| 3197 | |
| 3198 | for (p = desc->args; *p; p++) |
| 3199 | if (*p == '<') |
| 3200 | n_args++; |
| 3201 | out: |
| 3202 | script_desc__delete(desc); |
| 3203 | |
| 3204 | return n_args; |
| 3205 | } |
| 3206 | |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3207 | static int have_cmd(int argc, const char **argv) |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3208 | { |
| 3209 | char **__argv = malloc(sizeof(const char *) * argc); |
| 3210 | |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3211 | if (!__argv) { |
| 3212 | pr_err("malloc failed\n"); |
| 3213 | return -1; |
| 3214 | } |
| 3215 | |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3216 | memcpy(__argv, argv, sizeof(const char *) * argc); |
| 3217 | argc = parse_options(argc, (const char **)__argv, record_options, |
| 3218 | NULL, PARSE_OPT_STOP_AT_NON_OPTION); |
| 3219 | free(__argv); |
| 3220 | |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3221 | system_wide = (argc == 0); |
| 3222 | |
| 3223 | return 0; |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3224 | } |
| 3225 | |
Jiri Olsa | 7322d6c | 2015-08-13 09:17:24 +0200 | [diff] [blame] | 3226 | static void script__setup_sample_type(struct perf_script *script) |
| 3227 | { |
| 3228 | struct perf_session *session = script->session; |
| 3229 | u64 sample_type = perf_evlist__combined_sample_type(session->evlist); |
| 3230 | |
| 3231 | if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) { |
| 3232 | if ((sample_type & PERF_SAMPLE_REGS_USER) && |
Arnaldo Carvalho de Melo | eabad8c | 2018-01-15 16:48:46 -0300 | [diff] [blame] | 3233 | (sample_type & PERF_SAMPLE_STACK_USER)) { |
Jiri Olsa | 7322d6c | 2015-08-13 09:17:24 +0200 | [diff] [blame] | 3234 | callchain_param.record_mode = CALLCHAIN_DWARF; |
Arnaldo Carvalho de Melo | eabad8c | 2018-01-15 16:48:46 -0300 | [diff] [blame] | 3235 | dwarf_callchain_users = true; |
| 3236 | } else if (sample_type & PERF_SAMPLE_BRANCH_STACK) |
Jiri Olsa | 7322d6c | 2015-08-13 09:17:24 +0200 | [diff] [blame] | 3237 | callchain_param.record_mode = CALLCHAIN_LBR; |
| 3238 | else |
| 3239 | callchain_param.record_mode = CALLCHAIN_FP; |
| 3240 | } |
| 3241 | } |
| 3242 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3243 | static int process_stat_round_event(struct perf_session *session, |
| 3244 | union perf_event *event) |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 3245 | { |
| 3246 | struct stat_round_event *round = &event->stat_round; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3247 | struct evsel *counter; |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 3248 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3249 | evlist__for_each_entry(session->evlist, counter) { |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 3250 | perf_stat_process_counter(&stat_config, counter); |
| 3251 | process_stat(counter, round->time); |
| 3252 | } |
| 3253 | |
| 3254 | process_stat_interval(round->time); |
| 3255 | return 0; |
| 3256 | } |
| 3257 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3258 | static int process_stat_config_event(struct perf_session *session __maybe_unused, |
| 3259 | union perf_event *event) |
Jiri Olsa | 91a2c3d | 2016-01-05 22:09:07 +0100 | [diff] [blame] | 3260 | { |
| 3261 | perf_event__read_stat_config(&stat_config, &event->stat_config); |
| 3262 | return 0; |
| 3263 | } |
| 3264 | |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3265 | static int set_maps(struct perf_script *script) |
| 3266 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3267 | struct evlist *evlist = script->session->evlist; |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3268 | |
| 3269 | if (!script->cpus || !script->threads) |
| 3270 | return 0; |
| 3271 | |
| 3272 | if (WARN_ONCE(script->allocated, "stats double allocation\n")) |
| 3273 | return -EINVAL; |
| 3274 | |
Jiri Olsa | 453fa03 | 2019-07-21 13:24:43 +0200 | [diff] [blame] | 3275 | perf_evlist__set_maps(&evlist->core, script->cpus, script->threads); |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3276 | |
| 3277 | if (perf_evlist__alloc_stats(evlist, true)) |
| 3278 | return -ENOMEM; |
| 3279 | |
| 3280 | script->allocated = true; |
| 3281 | return 0; |
| 3282 | } |
| 3283 | |
| 3284 | static |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3285 | int process_thread_map_event(struct perf_session *session, |
| 3286 | union perf_event *event) |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3287 | { |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3288 | struct perf_tool *tool = session->tool; |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3289 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 3290 | |
| 3291 | if (script->threads) { |
| 3292 | pr_warning("Extra thread map event, ignoring.\n"); |
| 3293 | return 0; |
| 3294 | } |
| 3295 | |
| 3296 | script->threads = thread_map__new_event(&event->thread_map); |
| 3297 | if (!script->threads) |
| 3298 | return -ENOMEM; |
| 3299 | |
| 3300 | return set_maps(script); |
| 3301 | } |
| 3302 | |
| 3303 | static |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3304 | int process_cpu_map_event(struct perf_session *session, |
| 3305 | union perf_event *event) |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3306 | { |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3307 | struct perf_tool *tool = session->tool; |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3308 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 3309 | |
| 3310 | if (script->cpus) { |
| 3311 | pr_warning("Extra cpu map event, ignoring.\n"); |
| 3312 | return 0; |
| 3313 | } |
| 3314 | |
| 3315 | script->cpus = cpu_map__new_data(&event->cpu_map.data); |
| 3316 | if (!script->cpus) |
| 3317 | return -ENOMEM; |
| 3318 | |
| 3319 | return set_maps(script); |
| 3320 | } |
| 3321 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3322 | static int process_feature_event(struct perf_session *session, |
| 3323 | union perf_event *event) |
Ravi Bangoria | 92ead7e | 2018-06-25 18:12:20 +0530 | [diff] [blame] | 3324 | { |
| 3325 | if (event->feat.feat_id < HEADER_LAST_FEATURE) |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3326 | return perf_event__process_feature(session, event); |
Ravi Bangoria | 92ead7e | 2018-06-25 18:12:20 +0530 | [diff] [blame] | 3327 | return 0; |
| 3328 | } |
| 3329 | |
Arnaldo Carvalho de Melo | fa48c89 | 2017-11-09 16:04:26 -0300 | [diff] [blame] | 3330 | #ifdef HAVE_AUXTRACE_SUPPORT |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3331 | static int perf_script__process_auxtrace_info(struct perf_session *session, |
| 3332 | union perf_event *event) |
Arnaldo Carvalho de Melo | fa48c89 | 2017-11-09 16:04:26 -0300 | [diff] [blame] | 3333 | { |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3334 | struct perf_tool *tool = session->tool; |
| 3335 | |
| 3336 | int ret = perf_event__process_auxtrace_info(session, event); |
Arnaldo Carvalho de Melo | fa48c89 | 2017-11-09 16:04:26 -0300 | [diff] [blame] | 3337 | |
| 3338 | if (ret == 0) { |
| 3339 | struct perf_script *script = container_of(tool, struct perf_script, tool); |
| 3340 | |
| 3341 | ret = perf_script__setup_per_event_dump(script); |
| 3342 | } |
| 3343 | |
| 3344 | return ret; |
| 3345 | } |
| 3346 | #else |
| 3347 | #define perf_script__process_auxtrace_info 0 |
| 3348 | #endif |
| 3349 | |
Andi Kleen | b585ebd | 2018-09-20 11:05:36 -0700 | [diff] [blame] | 3350 | static int parse_insn_trace(const struct option *opt __maybe_unused, |
| 3351 | const char *str __maybe_unused, |
| 3352 | int unset __maybe_unused) |
| 3353 | { |
| 3354 | parse_output_fields(NULL, "+insn,-event,-period", 0); |
| 3355 | itrace_parse_synth_opts(opt, "i0ns", 0); |
Andi Kleen | 52bab88 | 2019-03-05 06:47:47 -0800 | [diff] [blame] | 3356 | symbol_conf.nanosecs = true; |
Andi Kleen | b585ebd | 2018-09-20 11:05:36 -0700 | [diff] [blame] | 3357 | return 0; |
| 3358 | } |
| 3359 | |
| 3360 | static int parse_xed(const struct option *opt __maybe_unused, |
| 3361 | const char *str __maybe_unused, |
| 3362 | int unset __maybe_unused) |
| 3363 | { |
| 3364 | force_pager("xed -F insn: -A -64 | less"); |
| 3365 | return 0; |
| 3366 | } |
| 3367 | |
Andi Kleen | d1b1552 | 2018-09-20 11:05:38 -0700 | [diff] [blame] | 3368 | static int parse_call_trace(const struct option *opt __maybe_unused, |
| 3369 | const char *str __maybe_unused, |
| 3370 | int unset __maybe_unused) |
| 3371 | { |
| 3372 | parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0); |
| 3373 | itrace_parse_synth_opts(opt, "cewp", 0); |
Andi Kleen | 52bab88 | 2019-03-05 06:47:47 -0800 | [diff] [blame] | 3374 | symbol_conf.nanosecs = true; |
Jiri Olsa | 1c49242 | 2019-05-08 15:20:05 +0200 | [diff] [blame] | 3375 | symbol_conf.pad_output_len_dso = 50; |
Andi Kleen | d1b1552 | 2018-09-20 11:05:38 -0700 | [diff] [blame] | 3376 | return 0; |
| 3377 | } |
| 3378 | |
| 3379 | static int parse_callret_trace(const struct option *opt __maybe_unused, |
| 3380 | const char *str __maybe_unused, |
| 3381 | int unset __maybe_unused) |
| 3382 | { |
| 3383 | parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent,+flags", 0); |
| 3384 | itrace_parse_synth_opts(opt, "crewp", 0); |
Andi Kleen | 52bab88 | 2019-03-05 06:47:47 -0800 | [diff] [blame] | 3385 | symbol_conf.nanosecs = true; |
Andi Kleen | d1b1552 | 2018-09-20 11:05:38 -0700 | [diff] [blame] | 3386 | return 0; |
| 3387 | } |
| 3388 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 3389 | int cmd_script(int argc, const char **argv) |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 3390 | { |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3391 | bool show_full_info = false; |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3392 | bool header = false; |
| 3393 | bool header_only = false; |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3394 | bool script_started = false; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3395 | char *rec_script_path = NULL; |
| 3396 | char *rep_script_path = NULL; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 3397 | struct perf_session *session; |
Andi Kleen | 4eb0681 | 2018-09-20 11:05:37 -0700 | [diff] [blame] | 3398 | struct itrace_synth_opts itrace_synth_opts = { |
| 3399 | .set = false, |
| 3400 | .default_no_sample = true, |
| 3401 | }; |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 3402 | struct utsname uts; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3403 | char *script_path = NULL; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3404 | const char **__argv; |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3405 | int i, j, err = 0; |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3406 | struct perf_script script = { |
| 3407 | .tool = { |
| 3408 | .sample = process_sample_event, |
| 3409 | .mmap = perf_event__process_mmap, |
| 3410 | .mmap2 = perf_event__process_mmap2, |
| 3411 | .comm = perf_event__process_comm, |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 3412 | .namespaces = perf_event__process_namespaces, |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3413 | .exit = perf_event__process_exit, |
| 3414 | .fork = perf_event__process_fork, |
Adrian Hunter | 7ea9572 | 2013-11-01 15:51:30 +0200 | [diff] [blame] | 3415 | .attr = process_attr, |
Jiri Olsa | 91daee3 | 2016-04-07 09:11:13 +0200 | [diff] [blame] | 3416 | .event_update = perf_event__process_event_update, |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3417 | .tracing_data = perf_event__process_tracing_data, |
Ravi Bangoria | 92ead7e | 2018-06-25 18:12:20 +0530 | [diff] [blame] | 3418 | .feature = process_feature_event, |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3419 | .build_id = perf_event__process_build_id, |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 3420 | .id_index = perf_event__process_id_index, |
Arnaldo Carvalho de Melo | fa48c89 | 2017-11-09 16:04:26 -0300 | [diff] [blame] | 3421 | .auxtrace_info = perf_script__process_auxtrace_info, |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 3422 | .auxtrace = perf_event__process_auxtrace, |
| 3423 | .auxtrace_error = perf_event__process_auxtrace_error, |
Jiri Olsa | e099eba | 2016-01-05 22:09:09 +0100 | [diff] [blame] | 3424 | .stat = perf_event__process_stat_event, |
| 3425 | .stat_round = process_stat_round_event, |
Jiri Olsa | 91a2c3d | 2016-01-05 22:09:07 +0100 | [diff] [blame] | 3426 | .stat_config = process_stat_config_event, |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3427 | .thread_map = process_thread_map_event, |
| 3428 | .cpu_map = process_cpu_map_event, |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 3429 | .ordered_events = true, |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3430 | .ordering_requires_timestamps = true, |
| 3431 | }, |
| 3432 | }; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3433 | struct perf_data data = { |
Yunlong Song | 06af0f2 | 2015-04-02 21:47:16 +0800 | [diff] [blame] | 3434 | .mode = PERF_DATA_MODE_READ, |
| 3435 | }; |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3436 | const struct option options[] = { |
| 3437 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 3438 | "dump raw trace in ASCII"), |
| 3439 | OPT_INCR('v', "verbose", &verbose, |
| 3440 | "be more verbose (show symbol address, etc)"), |
| 3441 | OPT_BOOLEAN('L', "Latency", &latency_format, |
| 3442 | "show latency attributes (irqs/preemption disabled, etc)"), |
| 3443 | OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts", |
| 3444 | list_available_scripts), |
| 3445 | OPT_CALLBACK('s', "script", NULL, "name", |
| 3446 | "script file name (lang:script name, script name, or *)", |
| 3447 | parse_scriptname), |
| 3448 | OPT_STRING('g', "gen-script", &generate_script_lang, "lang", |
| 3449 | "generate perf-script.xx script in specified language"), |
| 3450 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
| 3451 | OPT_BOOLEAN('d', "debug-mode", &debug_mode, |
| 3452 | "do various checks like samples ordering and lost events"), |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3453 | OPT_BOOLEAN(0, "header", &header, "Show data header."), |
| 3454 | OPT_BOOLEAN(0, "header-only", &header_only, "Show only data header."), |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3455 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 3456 | "file", "vmlinux pathname"), |
| 3457 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, |
| 3458 | "file", "kallsyms pathname"), |
| 3459 | OPT_BOOLEAN('G', "hide-call-graph", &no_callchain, |
| 3460 | "When printing symbols do not display call chain"), |
He Kuang | a706670 | 2016-05-19 11:47:37 +0000 | [diff] [blame] | 3461 | OPT_CALLBACK(0, "symfs", NULL, "directory", |
| 3462 | "Look for files with symbols relative to this directory", |
| 3463 | symbol__config_symfs), |
Yunlong Song | 06af0f2 | 2015-04-02 21:47:16 +0800 | [diff] [blame] | 3464 | OPT_CALLBACK('F', "fields", NULL, "str", |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3465 | "comma separated output fields prepend with 'type:'. " |
Andi Kleen | 36ce565 | 2017-06-02 08:48:10 -0700 | [diff] [blame] | 3466 | "+field to add and -field to remove." |
Adrian Hunter | 1405720 | 2017-06-21 13:17:19 +0300 | [diff] [blame] | 3467 | "Valid types: hw,sw,trace,raw,synth. " |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3468 | "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," |
Ravi Bangoria | 10e9cec | 2018-06-25 18:12:18 +0530 | [diff] [blame] | 3469 | "addr,symoff,srcline,period,iregs,uregs,brstack," |
| 3470 | "brstacksym,flags,bpf-output,brstackinsn,brstackoff," |
Adrian Hunter | 68fb45b | 2019-05-20 14:37:14 +0300 | [diff] [blame] | 3471 | "callindent,insn,insnlen,synth,phys_addr,metric,misc,ipc", |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 3472 | parse_output_fields), |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3473 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
| 3474 | "system-wide collection from all CPUs"), |
| 3475 | OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", |
| 3476 | "only consider these symbols"), |
Andi Kleen | b585ebd | 2018-09-20 11:05:36 -0700 | [diff] [blame] | 3477 | OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, NULL, |
| 3478 | "Decode instructions from itrace", parse_insn_trace), |
| 3479 | OPT_CALLBACK_OPTARG(0, "xed", NULL, NULL, NULL, |
| 3480 | "Run xed disassembler on output", parse_xed), |
Andi Kleen | d1b1552 | 2018-09-20 11:05:38 -0700 | [diff] [blame] | 3481 | OPT_CALLBACK_OPTARG(0, "call-trace", &itrace_synth_opts, NULL, NULL, |
| 3482 | "Decode calls from from itrace", parse_call_trace), |
| 3483 | OPT_CALLBACK_OPTARG(0, "call-ret-trace", &itrace_synth_opts, NULL, NULL, |
| 3484 | "Decode calls and returns from itrace", parse_callret_trace), |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 3485 | OPT_STRING(0, "graph-function", &symbol_conf.graph_function, "symbol[,symbol...]", |
| 3486 | "Only print symbols and callees with --call-trace/--call-ret-trace"), |
David Ahern | 64eff7d | 2016-11-25 13:00:21 -0700 | [diff] [blame] | 3487 | OPT_STRING(0, "stop-bt", &symbol_conf.bt_stop_list_str, "symbol[,symbol...]", |
| 3488 | "Stop display of callgraph at these symbols"), |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3489 | OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), |
| 3490 | OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", |
| 3491 | "only display events for these comms"), |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 3492 | OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", |
| 3493 | "only consider symbols in these pids"), |
| 3494 | OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", |
| 3495 | "only consider symbols in these tids"), |
Arnaldo Carvalho de Melo | 6125cc8 | 2016-04-14 18:15:18 -0300 | [diff] [blame] | 3496 | OPT_UINTEGER(0, "max-stack", &scripting_max_stack, |
| 3497 | "Set the maximum stack depth when parsing the callchain, " |
| 3498 | "anything beyond the specified depth will be ignored. " |
Arnaldo Carvalho de Melo | 4cb9344 | 2016-04-27 10:16:24 -0300 | [diff] [blame] | 3499 | "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), |
Andi Kleen | 90b10f4 | 2019-03-14 15:50:00 -0700 | [diff] [blame] | 3500 | OPT_BOOLEAN(0, "reltime", &reltime, "Show time stamps relative to start"), |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3501 | OPT_BOOLEAN('I', "show-info", &show_full_info, |
| 3502 | "display extended information from perf.data file"), |
| 3503 | OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, |
| 3504 | "Show the path of [kernel.kallsyms]"), |
Namhyung Kim | ad7ebb9 | 2013-11-26 17:51:12 +0900 | [diff] [blame] | 3505 | OPT_BOOLEAN('\0', "show-task-events", &script.show_task_events, |
| 3506 | "Show the fork/comm/exit events"), |
Namhyung Kim | ba1ddf4 | 2013-11-26 17:54:26 +0900 | [diff] [blame] | 3507 | OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, |
| 3508 | "Show the mmap events"), |
Adrian Hunter | 7c14898 | 2015-07-21 12:44:06 +0300 | [diff] [blame] | 3509 | OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, |
| 3510 | "Show context switch events (if recorded)"), |
Hari Bathini | 96a44bb | 2017-03-08 02:12:06 +0530 | [diff] [blame] | 3511 | OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, |
| 3512 | "Show namespace events (if recorded)"), |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 3513 | OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events, |
| 3514 | "Show lost events (if recorded)"), |
Jiri Olsa | 3233b37 | 2018-02-06 19:17:59 +0100 | [diff] [blame] | 3515 | OPT_BOOLEAN('\0', "show-round-events", &script.show_round_events, |
| 3516 | "Show round events (if recorded)"), |
Jiri Olsa | 490c8cc | 2019-05-08 15:20:08 +0200 | [diff] [blame] | 3517 | OPT_BOOLEAN('\0', "show-bpf-events", &script.show_bpf_events, |
| 3518 | "Show bpf related events (if recorded)"), |
Arnaldo Carvalho de Melo | a14390f | 2017-10-26 10:30:20 -0300 | [diff] [blame] | 3519 | OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump, |
| 3520 | "Dump trace output to files named by the monitored events"), |
Yannick Brosseau | be3d466 | 2017-01-13 13:25:27 -0500 | [diff] [blame] | 3521 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), |
Andi Kleen | 48d02a1 | 2017-02-23 15:46:34 -0800 | [diff] [blame] | 3522 | OPT_INTEGER(0, "max-blocks", &max_blocks, |
| 3523 | "Maximum number of code blocks to dump with brstackinsn"), |
Andi Kleen | 52bab88 | 2019-03-05 06:47:47 -0800 | [diff] [blame] | 3524 | OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, |
Adrian Hunter | 83e1986 | 2015-09-25 16:15:36 +0300 | [diff] [blame] | 3525 | "Use 9 decimal places when displaying time"), |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 3526 | OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", |
Andi Kleen | c12e039 | 2018-09-13 20:10:31 -0700 | [diff] [blame] | 3527 | "Instruction Tracing options\n" ITRACE_HELP, |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 3528 | itrace_parse_synth_opts), |
Andi Kleen | a9710ba | 2015-08-07 15:24:05 -0700 | [diff] [blame] | 3529 | OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, |
| 3530 | "Show full source file name path for source lines"), |
Mark Drayton | 77e0070 | 2015-08-26 12:18:15 -0700 | [diff] [blame] | 3531 | OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, |
| 3532 | "Enable symbol demangling"), |
| 3533 | OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, |
| 3534 | "Enable kernel symbol demangling"), |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 3535 | OPT_STRING(0, "time", &script.time_str, "str", |
| 3536 | "Time span of interest (start,stop)"), |
Namhyung Kim | 325fbff | 2017-05-24 15:21:26 +0900 | [diff] [blame] | 3537 | OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name, |
| 3538 | "Show inline function"), |
Arnaldo Carvalho de Melo | 15a108a | 2019-06-28 17:16:58 -0300 | [diff] [blame] | 3539 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", |
| 3540 | "guest mount directory under which every guest os" |
| 3541 | " instance has a subdir"), |
| 3542 | OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name, |
| 3543 | "file", "file saving guest os vmlinux"), |
| 3544 | OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms, |
| 3545 | "file", "file saving guest os /proc/kallsyms"), |
| 3546 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, |
| 3547 | "file", "file saving guest os /proc/modules"), |
Arnaldo Carvalho de Melo | add3a71 | 2019-08-15 11:21:21 -0300 | [diff] [blame] | 3548 | OPTS_EVSWITCH(&script.evswitch), |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3549 | OPT_END() |
| 3550 | }; |
Yunlong Song | 40cae2b | 2015-03-18 21:35:54 +0800 | [diff] [blame] | 3551 | const char * const script_subcommands[] = { "record", "report", NULL }; |
| 3552 | const char *script_usage[] = { |
Arnaldo Carvalho de Melo | 69b6470 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 3553 | "perf script [<options>]", |
| 3554 | "perf script [<options>] record <script> [<record-options>] <command>", |
| 3555 | "perf script [<options>] report <script> [script-args]", |
| 3556 | "perf script [<options>] <script> [<record-options>] <command>", |
| 3557 | "perf script [<options>] <top-script> [script-args]", |
| 3558 | NULL |
| 3559 | }; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3560 | |
Arnaldo Carvalho de Melo | 0a7c74e | 2017-04-04 13:15:04 -0300 | [diff] [blame] | 3561 | perf_set_singlethreaded(); |
| 3562 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3563 | setup_scripting(); |
| 3564 | |
Yunlong Song | 40cae2b | 2015-03-18 21:35:54 +0800 | [diff] [blame] | 3565 | argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage, |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3566 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 3567 | |
Arnaldo Carvalho de Melo | 15a108a | 2019-06-28 17:16:58 -0300 | [diff] [blame] | 3568 | if (symbol_conf.guestmount || |
| 3569 | symbol_conf.default_guest_vmlinux_name || |
| 3570 | symbol_conf.default_guest_kallsyms || |
| 3571 | symbol_conf.default_guest_modules) { |
| 3572 | /* |
| 3573 | * Enable guest sample processing. |
| 3574 | */ |
| 3575 | perf_guest = true; |
| 3576 | } |
| 3577 | |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 3578 | data.path = input_name; |
| 3579 | data.force = symbol_conf.force; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 3580 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3581 | if (argc > 1 && !strncmp(argv[0], "rec", strlen("rec"))) { |
| 3582 | rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); |
| 3583 | if (!rec_script_path) |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 3584 | return cmd_record(argc, argv); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3585 | } |
| 3586 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3587 | if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) { |
| 3588 | rep_script_path = get_script_path(argv[1], REPORT_SUFFIX); |
| 3589 | if (!rep_script_path) { |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3590 | fprintf(stderr, |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3591 | "Please specify a valid report script" |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 3592 | "(see 'perf script -l' for listing)\n"); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3593 | return -1; |
| 3594 | } |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3595 | } |
| 3596 | |
Andi Kleen | 90b10f4 | 2019-03-14 15:50:00 -0700 | [diff] [blame] | 3597 | if (script.time_str && reltime) { |
| 3598 | fprintf(stderr, "Don't combine --reltime with --time\n"); |
| 3599 | return -1; |
| 3600 | } |
| 3601 | |
Adrian Hunter | 3c5b645 | 2015-09-25 16:15:51 +0300 | [diff] [blame] | 3602 | if (itrace_synth_opts.callchain && |
| 3603 | itrace_synth_opts.callchain_sz > scripting_max_stack) |
| 3604 | scripting_max_stack = itrace_synth_opts.callchain_sz; |
| 3605 | |
Ben Hutchings | 44e668c | 2010-10-10 16:10:03 +0100 | [diff] [blame] | 3606 | /* make sure PERF_EXEC_PATH is set for scripts */ |
Josh Poimboeuf | 46113a5 | 2015-12-15 09:39:37 -0600 | [diff] [blame] | 3607 | set_argv_exec_path(get_argv_exec_path()); |
Ben Hutchings | 44e668c | 2010-10-10 16:10:03 +0100 | [diff] [blame] | 3608 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3609 | if (argc && !script_name && !rec_script_path && !rep_script_path) { |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3610 | int live_pipe[2]; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3611 | int rep_args; |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3612 | pid_t pid; |
| 3613 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3614 | rec_script_path = get_script_path(argv[0], RECORD_SUFFIX); |
| 3615 | rep_script_path = get_script_path(argv[0], REPORT_SUFFIX); |
| 3616 | |
| 3617 | if (!rec_script_path && !rep_script_path) { |
Namhyung Kim | c711836 | 2015-10-25 00:49:27 +0900 | [diff] [blame] | 3618 | usage_with_options_msg(script_usage, options, |
| 3619 | "Couldn't find script `%s'\n\n See perf" |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 3620 | " script -l for available scripts.\n", argv[0]); |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3621 | } |
| 3622 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3623 | if (is_top_script(argv[0])) { |
| 3624 | rep_args = argc - 1; |
| 3625 | } else { |
| 3626 | int rec_args; |
| 3627 | |
| 3628 | rep_args = has_required_arg(rep_script_path); |
| 3629 | rec_args = (argc - 1) - rep_args; |
| 3630 | if (rec_args < 0) { |
Namhyung Kim | c711836 | 2015-10-25 00:49:27 +0900 | [diff] [blame] | 3631 | usage_with_options_msg(script_usage, options, |
| 3632 | "`%s' script requires options." |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 3633 | "\n\n See perf script -l for available " |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3634 | "scripts and options.\n", argv[0]); |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3635 | } |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | if (pipe(live_pipe) < 0) { |
| 3639 | perror("failed to create pipe"); |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3640 | return -1; |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | pid = fork(); |
| 3644 | if (pid < 0) { |
| 3645 | perror("failed to fork"); |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3646 | return -1; |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | if (!pid) { |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3650 | j = 0; |
| 3651 | |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3652 | dup2(live_pipe[1], 1); |
| 3653 | close(live_pipe[0]); |
| 3654 | |
Robert Richter | 317df65 | 2011-11-25 15:05:25 +0100 | [diff] [blame] | 3655 | if (is_top_script(argv[0])) { |
| 3656 | system_wide = true; |
| 3657 | } else if (!system_wide) { |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3658 | if (have_cmd(argc - rep_args, &argv[rep_args]) != 0) { |
| 3659 | err = -1; |
| 3660 | goto out; |
| 3661 | } |
Robert Richter | 317df65 | 2011-11-25 15:05:25 +0100 | [diff] [blame] | 3662 | } |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3663 | |
| 3664 | __argv = malloc((argc + 6) * sizeof(const char *)); |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3665 | if (!__argv) { |
| 3666 | pr_err("malloc failed\n"); |
| 3667 | err = -ENOMEM; |
| 3668 | goto out; |
| 3669 | } |
Tom Zanussi | e8719ad | 2010-11-10 07:52:32 -0600 | [diff] [blame] | 3670 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3671 | __argv[j++] = "/bin/sh"; |
| 3672 | __argv[j++] = rec_script_path; |
| 3673 | if (system_wide) |
| 3674 | __argv[j++] = "-a"; |
| 3675 | __argv[j++] = "-q"; |
| 3676 | __argv[j++] = "-o"; |
| 3677 | __argv[j++] = "-"; |
| 3678 | for (i = rep_args + 1; i < argc; i++) |
| 3679 | __argv[j++] = argv[i]; |
| 3680 | __argv[j++] = NULL; |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3681 | |
| 3682 | execvp("/bin/sh", (char **)__argv); |
Tom Zanussi | e8719ad | 2010-11-10 07:52:32 -0600 | [diff] [blame] | 3683 | free(__argv); |
Tom Zanussi | a0cccc2 | 2010-04-01 23:59:25 -0500 | [diff] [blame] | 3684 | exit(-1); |
| 3685 | } |
| 3686 | |
| 3687 | dup2(live_pipe[0], 0); |
| 3688 | close(live_pipe[1]); |
| 3689 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3690 | __argv = malloc((argc + 4) * sizeof(const char *)); |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3691 | if (!__argv) { |
| 3692 | pr_err("malloc failed\n"); |
| 3693 | err = -ENOMEM; |
| 3694 | goto out; |
| 3695 | } |
| 3696 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3697 | j = 0; |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3698 | __argv[j++] = "/bin/sh"; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3699 | __argv[j++] = rep_script_path; |
| 3700 | for (i = 1; i < rep_args + 1; i++) |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3701 | __argv[j++] = argv[i]; |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3702 | __argv[j++] = "-i"; |
| 3703 | __argv[j++] = "-"; |
Tom Zanussi | 34c86ea | 2010-11-10 08:15:43 -0600 | [diff] [blame] | 3704 | __argv[j++] = NULL; |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3705 | |
| 3706 | execvp("/bin/sh", (char **)__argv); |
Tom Zanussi | e8719ad | 2010-11-10 07:52:32 -0600 | [diff] [blame] | 3707 | free(__argv); |
Tom Zanussi | 3875294 | 2009-12-15 02:53:39 -0600 | [diff] [blame] | 3708 | exit(-1); |
| 3709 | } |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3710 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3711 | if (rec_script_path) |
| 3712 | script_path = rec_script_path; |
| 3713 | if (rep_script_path) |
| 3714 | script_path = rep_script_path; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3715 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3716 | if (script_path) { |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3717 | j = 0; |
| 3718 | |
Robert Richter | 317df65 | 2011-11-25 15:05:25 +0100 | [diff] [blame] | 3719 | if (!rec_script_path) |
| 3720 | system_wide = false; |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3721 | else if (!system_wide) { |
| 3722 | if (have_cmd(argc - 1, &argv[1]) != 0) { |
| 3723 | err = -1; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | } |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3727 | |
| 3728 | __argv = malloc((argc + 2) * sizeof(const char *)); |
David Ahern | d54b1a9 | 2012-08-26 12:24:46 -0600 | [diff] [blame] | 3729 | if (!__argv) { |
| 3730 | pr_err("malloc failed\n"); |
| 3731 | err = -ENOMEM; |
| 3732 | goto out; |
| 3733 | } |
| 3734 | |
Tom Zanussi | b5b8731 | 2010-11-10 08:16:51 -0600 | [diff] [blame] | 3735 | __argv[j++] = "/bin/sh"; |
| 3736 | __argv[j++] = script_path; |
| 3737 | if (system_wide) |
| 3738 | __argv[j++] = "-a"; |
| 3739 | for (i = 2; i < argc; i++) |
| 3740 | __argv[j++] = argv[i]; |
| 3741 | __argv[j++] = NULL; |
| 3742 | |
| 3743 | execvp("/bin/sh", (char **)__argv); |
| 3744 | free(__argv); |
| 3745 | exit(-1); |
| 3746 | } |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 3747 | |
Milian Wolff | c1c9b96 | 2018-10-21 21:14:23 +0200 | [diff] [blame] | 3748 | if (!script_name) { |
Tom Zanussi | cf4fee5 | 2010-03-03 01:04:33 -0600 | [diff] [blame] | 3749 | setup_pager(); |
Milian Wolff | c1c9b96 | 2018-10-21 21:14:23 +0200 | [diff] [blame] | 3750 | use_browser = 0; |
| 3751 | } |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 3752 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3753 | session = perf_session__new(&data, false, &script.tool); |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 3754 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 3755 | return -1; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 3756 | |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3757 | if (header || header_only) { |
David Carrillo-Cisneros | 114f709 | 2017-07-17 21:25:47 -0700 | [diff] [blame] | 3758 | script.tool.show_feat_hdr = SHOW_FEAT_HEADER; |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3759 | perf_session__fprintf_info(session, stdout, show_full_info); |
| 3760 | if (header_only) |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3761 | goto out_delete; |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3762 | } |
David Carrillo-Cisneros | 114f709 | 2017-07-17 21:25:47 -0700 | [diff] [blame] | 3763 | if (show_full_info) |
| 3764 | script.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO; |
Jiri Olsa | e90debd | 2013-12-09 11:02:50 +0100 | [diff] [blame] | 3765 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 3766 | if (symbol__init(&session->header.env) < 0) |
Namhyung Kim | 38520dc | 2014-08-12 15:40:42 +0900 | [diff] [blame] | 3767 | goto out_delete; |
| 3768 | |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 3769 | uname(&uts); |
Song Liu | 9d49169 | 2019-06-20 18:44:38 -0700 | [diff] [blame] | 3770 | if (data.is_pipe || /* assume pipe_mode indicates native_arch */ |
| 3771 | !strcmp(uts.machine, session->header.env.arch) || |
Andi Kleen | 3ab481a | 2019-03-05 06:47:45 -0800 | [diff] [blame] | 3772 | (!strcmp(uts.machine, "x86_64") && |
| 3773 | !strcmp(session->header.env.arch, "i386"))) |
| 3774 | native_arch = true; |
| 3775 | |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3776 | script.session = session; |
Jiri Olsa | 7322d6c | 2015-08-13 09:17:24 +0200 | [diff] [blame] | 3777 | script__setup_sample_type(&script); |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3778 | |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 3779 | if ((output[PERF_TYPE_HARDWARE].fields & PERF_OUTPUT_CALLINDENT) || |
| 3780 | symbol_conf.graph_function) |
Adrian Hunter | e216708 | 2016-06-23 16:40:58 +0300 | [diff] [blame] | 3781 | itrace_synth_opts.thread_stack = true; |
| 3782 | |
Adrian Hunter | 7a680eb | 2015-04-09 18:53:56 +0300 | [diff] [blame] | 3783 | session->itrace_synth_opts = &itrace_synth_opts; |
| 3784 | |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 3785 | if (cpu_list) { |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3786 | err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap); |
| 3787 | if (err < 0) |
| 3788 | goto out_delete; |
Adrian Hunter | 644e084 | 2017-05-26 11:17:38 +0300 | [diff] [blame] | 3789 | itrace_synth_opts.cpu_bitmap = cpu_bitmap; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 3790 | } |
| 3791 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 3792 | if (!no_callchain) |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 3793 | symbol_conf.use_callchain = true; |
| 3794 | else |
| 3795 | symbol_conf.use_callchain = false; |
| 3796 | |
Arnaldo Carvalho de Melo | 9ee6742 | 2015-08-03 16:27:40 -0300 | [diff] [blame] | 3797 | if (session->tevent.pevent && |
Tzvetomir Stoyanov (VMware) | ece2a4f | 2018-08-08 14:02:55 -0400 | [diff] [blame] | 3798 | tep_set_function_resolver(session->tevent.pevent, |
| 3799 | machine__resolve_kernel_addr, |
| 3800 | &session->machines.host) < 0) { |
Arnaldo Carvalho de Melo | ccb3a82 | 2015-07-22 16:43:37 -0300 | [diff] [blame] | 3801 | pr_err("%s: failed to set libtraceevent function resolver\n", __func__); |
Christophe JAILLET | db49bc1 | 2017-09-16 08:25:37 +0200 | [diff] [blame] | 3802 | err = -1; |
| 3803 | goto out_delete; |
Arnaldo Carvalho de Melo | ccb3a82 | 2015-07-22 16:43:37 -0300 | [diff] [blame] | 3804 | } |
| 3805 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3806 | if (generate_script_lang) { |
| 3807 | struct stat perf_stat; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 3808 | int input; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3809 | |
David Ahern | 2c9e45f7 | 2011-03-17 10:03:21 -0600 | [diff] [blame] | 3810 | if (output_set_by_user()) { |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 3811 | fprintf(stderr, |
| 3812 | "custom fields not supported for generated scripts"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3813 | err = -EINVAL; |
| 3814 | goto out_delete; |
David Ahern | 745f43e | 2011-03-09 22:23:26 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 3817 | input = open(data.path, O_RDONLY); /* input_name */ |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3818 | if (input < 0) { |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3819 | err = -errno; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3820 | perror("failed to open file"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3821 | goto out_delete; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | err = fstat(input, &perf_stat); |
| 3825 | if (err < 0) { |
| 3826 | perror("failed to stat file"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3827 | goto out_delete; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | if (!perf_stat.st_size) { |
| 3831 | fprintf(stderr, "zero-sized file, nothing to do!\n"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3832 | goto out_delete; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | scripting_ops = script_spec__lookup(generate_script_lang); |
| 3836 | if (!scripting_ops) { |
| 3837 | fprintf(stderr, "invalid language specifier"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3838 | err = -ENOENT; |
| 3839 | goto out_delete; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3840 | } |
| 3841 | |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 3842 | err = scripting_ops->generate_script(session->tevent.pevent, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 3843 | "perf-script"); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3844 | goto out_delete; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | if (script_name) { |
Tom Zanussi | 586bc5c | 2009-12-15 02:53:35 -0600 | [diff] [blame] | 3848 | err = scripting_ops->start_script(script_name, argc, argv); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3849 | if (err) |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3850 | goto out_delete; |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 3851 | pr_debug("perf script started with script %s\n\n", script_name); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3852 | script_started = true; |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3853 | } |
| 3854 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 3855 | |
| 3856 | err = perf_session__check_output_opt(session); |
| 3857 | if (err < 0) |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3858 | goto out_delete; |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 3859 | |
Jin Yao | 284c4e1 | 2019-03-01 18:13:06 +0800 | [diff] [blame] | 3860 | if (script.time_str) { |
| 3861 | err = perf_time__parse_for_ranges(script.time_str, session, |
| 3862 | &script.ptime_range, |
| 3863 | &script.range_size, |
| 3864 | &script.range_num); |
| 3865 | if (err < 0) |
Jin Yao | 2ab046c | 2017-12-08 21:13:46 +0800 | [diff] [blame] | 3866 | goto out_delete; |
Adrian Hunter | 400ae98 | 2019-06-04 16:00:00 +0300 | [diff] [blame] | 3867 | |
| 3868 | itrace_synth_opts__set_time_range(&itrace_synth_opts, |
| 3869 | script.ptime_range, |
| 3870 | script.range_num); |
David Ahern | a91f4c4 | 2016-11-29 10:15:43 -0700 | [diff] [blame] | 3871 | } |
| 3872 | |
Arnaldo Carvalho de Melo | 124e02b | 2019-08-15 11:31:29 -0300 | [diff] [blame] | 3873 | err = evswitch__init(&script.evswitch, session->evlist, stderr); |
| 3874 | if (err) |
| 3875 | goto out_delete; |
Arnaldo Carvalho de Melo | dd41f66 | 2019-08-14 16:51:28 -0300 | [diff] [blame] | 3876 | |
Adrian Hunter | 6f3e5ed | 2013-10-22 10:34:07 +0300 | [diff] [blame] | 3877 | err = __cmd_script(&script); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3878 | |
Adrian Hunter | d445dd2 | 2014-08-15 22:08:37 +0300 | [diff] [blame] | 3879 | flush_scripting(); |
| 3880 | |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3881 | out_delete: |
Adrian Hunter | 400ae98 | 2019-06-04 16:00:00 +0300 | [diff] [blame] | 3882 | if (script.ptime_range) { |
| 3883 | itrace_synth_opts__clear_time_range(&itrace_synth_opts); |
Jin Yao | 284c4e1 | 2019-03-01 18:13:06 +0800 | [diff] [blame] | 3884 | zfree(&script.ptime_range); |
Adrian Hunter | 400ae98 | 2019-06-04 16:00:00 +0300 | [diff] [blame] | 3885 | } |
Jin Yao | cc2ef58 | 2018-01-10 23:00:33 +0800 | [diff] [blame] | 3886 | |
Jiri Olsa | cfc8874 | 2016-01-05 22:09:06 +0100 | [diff] [blame] | 3887 | perf_evlist__free_stats(session->evlist); |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 3888 | perf_session__delete(session); |
Namhyung Kim | 6cc870f | 2014-08-12 15:40:33 +0900 | [diff] [blame] | 3889 | |
| 3890 | if (script_started) |
| 3891 | cleanup_scripting(); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 3892 | out: |
| 3893 | return err; |
Frederic Weisbecker | 5f9c39d | 2009-08-17 16:18:08 +0200 | [diff] [blame] | 3894 | } |