Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 1 | #include <errno.h> |
Arnaldo Carvalho de Melo | c23c2a0 | 2017-09-11 10:50:26 -0300 | [diff] [blame] | 2 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 3 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 4 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 5 | #include <linux/types.h> |
Arnaldo Carvalho de Melo | 87ffb6c | 2019-09-10 16:29:02 +0100 | [diff] [blame] | 6 | #include <perf/cpumap.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 7 | #include <sys/types.h> |
| 8 | #include <sys/stat.h> |
| 9 | #include <unistd.h> |
David Carrillo-Cisneros | 16eb813 | 2017-04-11 23:49:19 -0700 | [diff] [blame] | 10 | #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ |
Arnaldo Carvalho de Melo | 5ab8c68 | 2017-04-25 15:30:47 -0300 | [diff] [blame] | 11 | #include <linux/perf_event.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 12 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | 87ffb6c | 2019-09-10 16:29:02 +0100 | [diff] [blame] | 13 | #include "cpumap.h" |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 14 | #include "dso.h" |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 15 | #include "event.h" |
| 16 | #include "debug.h" |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 17 | #include "hist.h" |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 18 | #include "machine.h" |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 19 | #include "sort.h" |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 20 | #include "string2.h" |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 21 | #include "strlist.h" |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 22 | #include "thread.h" |
Arnaldo Carvalho de Melo | 7c940c1 | 2011-02-11 11:45:54 -0200 | [diff] [blame] | 23 | #include "thread_map.h" |
Arnaldo Carvalho de Melo | f371102 | 2019-08-29 15:16:27 -0300 | [diff] [blame] | 24 | #include "time-utils.h" |
Arnaldo Carvalho de Melo | 3052ba5 | 2019-06-25 17:27:31 -0300 | [diff] [blame] | 25 | #include <linux/ctype.h> |
Arnaldo Carvalho de Melo | 1101f69 | 2019-01-27 13:42:37 +0100 | [diff] [blame] | 26 | #include "map.h" |
Arnaldo Carvalho de Melo | 055c67e | 2019-09-18 16:08:52 -0300 | [diff] [blame] | 27 | #include "util/namespaces.h" |
Arnaldo Carvalho de Melo | daecf9e | 2019-01-28 00:03:34 +0100 | [diff] [blame] | 28 | #include "symbol.h" |
Arnaldo Carvalho de Melo | c506c96 | 2013-12-11 09:15:00 -0300 | [diff] [blame] | 29 | #include "symbol/kallsyms.h" |
Jiri Olsa | 6742434 | 2015-10-25 15:51:28 +0100 | [diff] [blame] | 30 | #include "asm/bug.h" |
| 31 | #include "stat.h" |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 32 | #include "session.h" |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 33 | #include "bpf-event.h" |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 34 | #include "tool.h" |
Arnaldo Carvalho de Melo | c1a604d | 2019-08-29 15:20:59 -0300 | [diff] [blame] | 35 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 37 | static const char *perf_event__names[] = { |
Frederic Weisbecker | 3cb6d15 | 2011-05-23 13:06:27 +0200 | [diff] [blame] | 38 | [0] = "TOTAL", |
| 39 | [PERF_RECORD_MMAP] = "MMAP", |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 40 | [PERF_RECORD_MMAP2] = "MMAP2", |
Frederic Weisbecker | 3cb6d15 | 2011-05-23 13:06:27 +0200 | [diff] [blame] | 41 | [PERF_RECORD_LOST] = "LOST", |
| 42 | [PERF_RECORD_COMM] = "COMM", |
| 43 | [PERF_RECORD_EXIT] = "EXIT", |
| 44 | [PERF_RECORD_THROTTLE] = "THROTTLE", |
| 45 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", |
| 46 | [PERF_RECORD_FORK] = "FORK", |
| 47 | [PERF_RECORD_READ] = "READ", |
| 48 | [PERF_RECORD_SAMPLE] = "SAMPLE", |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 49 | [PERF_RECORD_AUX] = "AUX", |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 50 | [PERF_RECORD_ITRACE_START] = "ITRACE_START", |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 51 | [PERF_RECORD_LOST_SAMPLES] = "LOST_SAMPLES", |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 52 | [PERF_RECORD_SWITCH] = "SWITCH", |
| 53 | [PERF_RECORD_SWITCH_CPU_WIDE] = "SWITCH_CPU_WIDE", |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 54 | [PERF_RECORD_NAMESPACES] = "NAMESPACES", |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 55 | [PERF_RECORD_KSYMBOL] = "KSYMBOL", |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 56 | [PERF_RECORD_BPF_EVENT] = "BPF_EVENT", |
Frederic Weisbecker | 3cb6d15 | 2011-05-23 13:06:27 +0200 | [diff] [blame] | 57 | [PERF_RECORD_HEADER_ATTR] = "ATTR", |
| 58 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", |
| 59 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", |
| 60 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", |
| 61 | [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND", |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 62 | [PERF_RECORD_ID_INDEX] = "ID_INDEX", |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 63 | [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO", |
| 64 | [PERF_RECORD_AUXTRACE] = "AUXTRACE", |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 65 | [PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR", |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 66 | [PERF_RECORD_THREAD_MAP] = "THREAD_MAP", |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 67 | [PERF_RECORD_CPU_MAP] = "CPU_MAP", |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 68 | [PERF_RECORD_STAT_CONFIG] = "STAT_CONFIG", |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 69 | [PERF_RECORD_STAT] = "STAT", |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 70 | [PERF_RECORD_STAT_ROUND] = "STAT_ROUND", |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 71 | [PERF_RECORD_EVENT_UPDATE] = "EVENT_UPDATE", |
Adrian Hunter | 46bc29b | 2016-03-08 10:38:44 +0200 | [diff] [blame] | 72 | [PERF_RECORD_TIME_CONV] = "TIME_CONV", |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 73 | [PERF_RECORD_HEADER_FEATURE] = "FEATURE", |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 74 | [PERF_RECORD_COMPRESSED] = "COMPRESSED", |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 75 | }; |
| 76 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 77 | const char *perf_event__name(unsigned int id) |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 78 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 79 | if (id >= ARRAY_SIZE(perf_event__names)) |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 80 | return "INVALID"; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 81 | if (!perf_event__names[id]) |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 82 | return "UNKNOWN"; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 83 | return perf_event__names[id]; |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 86 | struct process_symbol_args { |
| 87 | const char *name; |
| 88 | u64 start; |
| 89 | }; |
| 90 | |
Arnaldo Carvalho de Melo | 3b01a41 | 2010-12-22 01:08:36 -0200 | [diff] [blame] | 91 | static int find_symbol_cb(void *arg, const char *name, char type, |
Cody P Schafer | 8215152 | 2012-08-10 15:22:48 -0700 | [diff] [blame] | 92 | u64 start) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 93 | { |
| 94 | struct process_symbol_args *args = arg; |
| 95 | |
Arnaldo Carvalho de Melo | 881516e | 2010-01-15 18:08:27 -0200 | [diff] [blame] | 96 | /* |
| 97 | * Must be a function or at least an alias, as in PARISC64, where "_text" is |
| 98 | * an 'A' to the same address as "_stext". |
| 99 | */ |
Arnaldo Carvalho de Melo | e85e0e0 | 2018-04-25 17:16:31 -0300 | [diff] [blame] | 100 | if (!(kallsyms__is_function(type) || |
Arnaldo Carvalho de Melo | 881516e | 2010-01-15 18:08:27 -0200 | [diff] [blame] | 101 | type == 'A') || strcmp(name, args->name)) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 102 | return 0; |
| 103 | |
| 104 | args->start = start; |
| 105 | return 1; |
| 106 | } |
| 107 | |
Arnaldo Carvalho de Melo | b843f62 | 2017-04-27 21:21:09 -0300 | [diff] [blame] | 108 | int kallsyms__get_function_start(const char *kallsyms_filename, |
| 109 | const char *symbol_name, u64 *addr) |
Adrian Hunter | 29b596b | 2014-01-29 16:14:37 +0200 | [diff] [blame] | 110 | { |
| 111 | struct process_symbol_args args = { .name = symbol_name, }; |
| 112 | |
| 113 | if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0) |
Arnaldo Carvalho de Melo | b843f62 | 2017-04-27 21:21:09 -0300 | [diff] [blame] | 114 | return -1; |
Adrian Hunter | 29b596b | 2014-01-29 16:14:37 +0200 | [diff] [blame] | 115 | |
Arnaldo Carvalho de Melo | b843f62 | 2017-04-27 21:21:09 -0300 | [diff] [blame] | 116 | *addr = args.start; |
| 117 | return 0; |
Adrian Hunter | 29b596b | 2014-01-29 16:14:37 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Jiri Olsa | 8e38159 | 2015-10-25 15:51:29 +0100 | [diff] [blame] | 120 | void perf_event__read_stat_config(struct perf_stat_config *config, |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 121 | struct perf_record_stat_config *event) |
Jiri Olsa | 8e38159 | 2015-10-25 15:51:29 +0100 | [diff] [blame] | 122 | { |
| 123 | unsigned i; |
| 124 | |
| 125 | for (i = 0; i < event->nr; i++) { |
| 126 | |
| 127 | switch (event->data[i].tag) { |
| 128 | #define CASE(__term, __val) \ |
| 129 | case PERF_STAT_CONFIG_TERM__##__term: \ |
| 130 | config->__val = event->data[i].val; \ |
| 131 | break; |
| 132 | |
| 133 | CASE(AGGR_MODE, aggr_mode) |
| 134 | CASE(SCALE, scale) |
| 135 | CASE(INTERVAL, interval) |
| 136 | #undef CASE |
| 137 | default: |
Jiri Olsa | c5f416e | 2019-08-28 15:57:09 +0200 | [diff] [blame] | 138 | pr_warning("unknown stat config term %" PRI_lu64 "\n", |
Jiri Olsa | 8e38159 | 2015-10-25 15:51:29 +0100 | [diff] [blame] | 139 | event->data[i].tag); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 144 | size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp) |
| 145 | { |
Adrian Hunter | 022c50d | 2014-07-14 13:02:27 +0300 | [diff] [blame] | 146 | const char *s; |
| 147 | |
| 148 | if (event->header.misc & PERF_RECORD_MISC_COMM_EXEC) |
| 149 | s = " exec"; |
| 150 | else |
| 151 | s = ""; |
| 152 | |
Arnaldo Carvalho de Melo | 5067406 | 2015-02-24 17:20:31 -0300 | [diff] [blame] | 153 | return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid); |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 154 | } |
| 155 | |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 156 | size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp) |
| 157 | { |
| 158 | size_t ret = 0; |
| 159 | struct perf_ns_link_info *ns_link_info; |
| 160 | u32 nr_namespaces, idx; |
| 161 | |
| 162 | ns_link_info = event->namespaces.link_info; |
| 163 | nr_namespaces = event->namespaces.nr_namespaces; |
| 164 | |
| 165 | ret += fprintf(fp, " %d/%d - nr_namespaces: %u\n\t\t[", |
| 166 | event->namespaces.pid, |
| 167 | event->namespaces.tid, |
| 168 | nr_namespaces); |
| 169 | |
| 170 | for (idx = 0; idx < nr_namespaces; idx++) { |
| 171 | if (idx && (idx % 4 == 0)) |
| 172 | ret += fprintf(fp, "\n\t\t "); |
| 173 | |
| 174 | ret += fprintf(fp, "%u/%s: %" PRIu64 "/%#" PRIx64 "%s", idx, |
| 175 | perf_ns__name(idx), (u64)ns_link_info[idx].dev, |
| 176 | (u64)ns_link_info[idx].ino, |
| 177 | ((idx + 1) != nr_namespaces) ? ", " : "]\n"); |
| 178 | } |
| 179 | |
| 180 | return ret; |
| 181 | } |
| 182 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 183 | int perf_event__process_comm(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 184 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 185 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 186 | struct machine *machine) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 187 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 188 | return machine__process_comm_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 189 | } |
| 190 | |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 191 | int perf_event__process_namespaces(struct perf_tool *tool __maybe_unused, |
| 192 | union perf_event *event, |
| 193 | struct perf_sample *sample, |
| 194 | struct machine *machine) |
| 195 | { |
| 196 | return machine__process_namespaces_event(machine, event, sample); |
| 197 | } |
| 198 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 199 | int perf_event__process_lost(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 200 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 201 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 202 | struct machine *machine) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 203 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 204 | return machine__process_lost_event(machine, event, sample); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 207 | int perf_event__process_aux(struct perf_tool *tool __maybe_unused, |
| 208 | union perf_event *event, |
| 209 | struct perf_sample *sample __maybe_unused, |
| 210 | struct machine *machine) |
| 211 | { |
| 212 | return machine__process_aux_event(machine, event); |
| 213 | } |
| 214 | |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 215 | int perf_event__process_itrace_start(struct perf_tool *tool __maybe_unused, |
| 216 | union perf_event *event, |
| 217 | struct perf_sample *sample __maybe_unused, |
| 218 | struct machine *machine) |
| 219 | { |
| 220 | return machine__process_itrace_start_event(machine, event); |
| 221 | } |
| 222 | |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 223 | int perf_event__process_lost_samples(struct perf_tool *tool __maybe_unused, |
| 224 | union perf_event *event, |
| 225 | struct perf_sample *sample, |
| 226 | struct machine *machine) |
| 227 | { |
| 228 | return machine__process_lost_samples_event(machine, event, sample); |
| 229 | } |
| 230 | |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 231 | int perf_event__process_switch(struct perf_tool *tool __maybe_unused, |
| 232 | union perf_event *event, |
| 233 | struct perf_sample *sample __maybe_unused, |
| 234 | struct machine *machine) |
| 235 | { |
| 236 | return machine__process_switch_event(machine, event); |
| 237 | } |
| 238 | |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 239 | int perf_event__process_ksymbol(struct perf_tool *tool __maybe_unused, |
| 240 | union perf_event *event, |
| 241 | struct perf_sample *sample __maybe_unused, |
| 242 | struct machine *machine) |
| 243 | { |
| 244 | return machine__process_ksymbol(machine, event, sample); |
| 245 | } |
| 246 | |
Arnaldo Carvalho de Melo | 3f604b5 | 2019-08-26 19:28:13 -0300 | [diff] [blame] | 247 | int perf_event__process_bpf(struct perf_tool *tool __maybe_unused, |
| 248 | union perf_event *event, |
| 249 | struct perf_sample *sample, |
| 250 | struct machine *machine) |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 251 | { |
Arnaldo Carvalho de Melo | 3f604b5 | 2019-08-26 19:28:13 -0300 | [diff] [blame] | 252 | return machine__process_bpf(machine, event, sample); |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 255 | size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp) |
| 256 | { |
Jiri Olsa | 1345e2e | 2019-08-25 20:17:41 +0200 | [diff] [blame] | 257 | return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 "]: %c %s\n", |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 258 | event->mmap.pid, event->mmap.tid, event->mmap.start, |
Arnaldo Carvalho de Melo | 62605dc50 | 2013-11-11 09:44:09 -0300 | [diff] [blame] | 259 | event->mmap.len, event->mmap.pgoff, |
| 260 | (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x', |
| 261 | event->mmap.filename); |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 262 | } |
| 263 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 264 | size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp) |
| 265 | { |
Jiri Olsa | b66ced1 | 2019-08-25 20:17:42 +0200 | [diff] [blame] | 266 | return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 |
| 267 | " %02x:%02x %"PRI_lu64" %"PRI_lu64"]: %c%c%c%c %s\n", |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 268 | event->mmap2.pid, event->mmap2.tid, event->mmap2.start, |
| 269 | event->mmap2.len, event->mmap2.pgoff, event->mmap2.maj, |
| 270 | event->mmap2.min, event->mmap2.ino, |
| 271 | event->mmap2.ino_generation, |
Don Zickus | 7ef8070 | 2014-05-19 15:13:49 -0400 | [diff] [blame] | 272 | (event->mmap2.prot & PROT_READ) ? 'r' : '-', |
| 273 | (event->mmap2.prot & PROT_WRITE) ? 'w' : '-', |
| 274 | (event->mmap2.prot & PROT_EXEC) ? 'x' : '-', |
| 275 | (event->mmap2.flags & MAP_SHARED) ? 's' : 'p', |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 276 | event->mmap2.filename); |
| 277 | } |
| 278 | |
Jiri Olsa | ec7fa596 | 2015-10-25 15:51:22 +0100 | [diff] [blame] | 279 | size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp) |
| 280 | { |
Jiri Olsa | 9749b90 | 2019-07-21 13:23:50 +0200 | [diff] [blame] | 281 | struct perf_thread_map *threads = thread_map__new_event(&event->thread_map); |
Jiri Olsa | ec7fa596 | 2015-10-25 15:51:22 +0100 | [diff] [blame] | 282 | size_t ret; |
| 283 | |
| 284 | ret = fprintf(fp, " nr: "); |
| 285 | |
| 286 | if (threads) |
| 287 | ret += thread_map__fprintf(threads, fp); |
| 288 | else |
| 289 | ret += fprintf(fp, "failed to get threads from event\n"); |
| 290 | |
Jiri Olsa | 7836e52 | 2019-07-21 13:24:20 +0200 | [diff] [blame] | 291 | perf_thread_map__put(threads); |
Jiri Olsa | ec7fa596 | 2015-10-25 15:51:22 +0100 | [diff] [blame] | 292 | return ret; |
| 293 | } |
| 294 | |
Jiri Olsa | eb12a1a | 2015-10-25 15:51:26 +0100 | [diff] [blame] | 295 | size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp) |
| 296 | { |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 297 | struct perf_cpu_map *cpus = cpu_map__new_data(&event->cpu_map.data); |
Jiri Olsa | eb12a1a | 2015-10-25 15:51:26 +0100 | [diff] [blame] | 298 | size_t ret; |
| 299 | |
Jiri Olsa | a24020e | 2016-06-28 13:29:04 +0200 | [diff] [blame] | 300 | ret = fprintf(fp, ": "); |
Jiri Olsa | eb12a1a | 2015-10-25 15:51:26 +0100 | [diff] [blame] | 301 | |
| 302 | if (cpus) |
| 303 | ret += cpu_map__fprintf(cpus, fp); |
| 304 | else |
| 305 | ret += fprintf(fp, "failed to get cpumap from event\n"); |
| 306 | |
Jiri Olsa | 38f01d8 | 2019-07-21 13:24:17 +0200 | [diff] [blame] | 307 | perf_cpu_map__put(cpus); |
Jiri Olsa | eb12a1a | 2015-10-25 15:51:26 +0100 | [diff] [blame] | 308 | return ret; |
| 309 | } |
| 310 | |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 311 | int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 312 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 313 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 314 | struct machine *machine) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 315 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 316 | return machine__process_mmap_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 317 | } |
| 318 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 319 | int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused, |
| 320 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 321 | struct perf_sample *sample, |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 322 | struct machine *machine) |
| 323 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 324 | return machine__process_mmap2_event(machine, event, sample); |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 327 | size_t perf_event__fprintf_task(union perf_event *event, FILE *fp) |
| 328 | { |
| 329 | return fprintf(fp, "(%d:%d):(%d:%d)\n", |
| 330 | event->fork.pid, event->fork.tid, |
| 331 | event->fork.ppid, event->fork.ptid); |
| 332 | } |
| 333 | |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 334 | int perf_event__process_fork(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 335 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 336 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 337 | struct machine *machine) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 338 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 339 | return machine__process_fork_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 340 | } |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 341 | |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 342 | int perf_event__process_exit(struct perf_tool *tool __maybe_unused, |
| 343 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 344 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 345 | struct machine *machine) |
| 346 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 347 | return machine__process_exit_event(machine, event, sample); |
Arnaldo Carvalho de Melo | f62d3f0 | 2012-10-06 15:44:59 -0300 | [diff] [blame] | 348 | } |
| 349 | |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 350 | size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp) |
| 351 | { |
Jiri Olsa | aedebdc | 2019-08-28 15:57:05 +0200 | [diff] [blame] | 352 | return fprintf(fp, " offset: %#"PRI_lx64" size: %#"PRI_lx64" flags: %#"PRI_lx64" [%s%s%s]\n", |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 353 | event->aux.aux_offset, event->aux.aux_size, |
| 354 | event->aux.flags, |
| 355 | event->aux.flags & PERF_AUX_FLAG_TRUNCATED ? "T" : "", |
Alexander Shishkin | 05a1f47 | 2017-03-16 18:41:59 +0200 | [diff] [blame] | 356 | event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : "", |
| 357 | event->aux.flags & PERF_AUX_FLAG_PARTIAL ? "P" : ""); |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 358 | } |
| 359 | |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 360 | size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp) |
| 361 | { |
| 362 | return fprintf(fp, " pid: %u tid: %u\n", |
| 363 | event->itrace_start.pid, event->itrace_start.tid); |
| 364 | } |
| 365 | |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 366 | size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp) |
| 367 | { |
| 368 | bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; |
Alexey Budankov | b3f35b5 | 2018-04-09 10:26:05 +0300 | [diff] [blame] | 369 | const char *in_out = !out ? "IN " : |
| 370 | !(event->header.misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT) ? |
| 371 | "OUT " : "OUT preempt"; |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 372 | |
| 373 | if (event->header.type == PERF_RECORD_SWITCH) |
| 374 | return fprintf(fp, " %s\n", in_out); |
| 375 | |
| 376 | return fprintf(fp, " %s %s pid/tid: %5u/%-5u\n", |
| 377 | in_out, out ? "next" : "prev", |
| 378 | event->context_switch.next_prev_pid, |
| 379 | event->context_switch.next_prev_tid); |
| 380 | } |
| 381 | |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 382 | static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp) |
| 383 | { |
Jiri Olsa | 5290ed6 | 2019-08-25 20:17:46 +0200 | [diff] [blame] | 384 | return fprintf(fp, " lost %" PRI_lu64 "\n", event->lost.lost); |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 387 | size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp) |
| 388 | { |
Jiri Olsa | f15e3c2 | 2019-08-25 20:17:50 +0200 | [diff] [blame] | 389 | return fprintf(fp, " addr %" PRI_lx64 " len %u type %u flags 0x%x name %s\n", |
Arnaldo Carvalho de Melo | ebdba16 | 2019-08-26 19:15:18 -0300 | [diff] [blame] | 390 | event->ksymbol.addr, event->ksymbol.len, |
| 391 | event->ksymbol.ksym_type, |
| 392 | event->ksymbol.flags, event->ksymbol.name); |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Arnaldo Carvalho de Melo | 3f604b5 | 2019-08-26 19:28:13 -0300 | [diff] [blame] | 395 | size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp) |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 396 | { |
Jiri Olsa | 8201787 | 2019-05-08 15:20:09 +0200 | [diff] [blame] | 397 | return fprintf(fp, " type %u, flags %u, id %u\n", |
Arnaldo Carvalho de Melo | 6a1b359 | 2019-08-26 19:20:35 -0300 | [diff] [blame] | 398 | event->bpf.type, event->bpf.flags, event->bpf.id); |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 401 | size_t perf_event__fprintf(union perf_event *event, FILE *fp) |
| 402 | { |
| 403 | size_t ret = fprintf(fp, "PERF_RECORD_%s", |
| 404 | perf_event__name(event->header.type)); |
| 405 | |
| 406 | switch (event->header.type) { |
| 407 | case PERF_RECORD_COMM: |
| 408 | ret += perf_event__fprintf_comm(event, fp); |
| 409 | break; |
| 410 | case PERF_RECORD_FORK: |
| 411 | case PERF_RECORD_EXIT: |
| 412 | ret += perf_event__fprintf_task(event, fp); |
| 413 | break; |
| 414 | case PERF_RECORD_MMAP: |
| 415 | ret += perf_event__fprintf_mmap(event, fp); |
| 416 | break; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 417 | case PERF_RECORD_NAMESPACES: |
| 418 | ret += perf_event__fprintf_namespaces(event, fp); |
| 419 | break; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 420 | case PERF_RECORD_MMAP2: |
| 421 | ret += perf_event__fprintf_mmap2(event, fp); |
| 422 | break; |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 423 | case PERF_RECORD_AUX: |
| 424 | ret += perf_event__fprintf_aux(event, fp); |
| 425 | break; |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 426 | case PERF_RECORD_ITRACE_START: |
| 427 | ret += perf_event__fprintf_itrace_start(event, fp); |
| 428 | break; |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 429 | case PERF_RECORD_SWITCH: |
| 430 | case PERF_RECORD_SWITCH_CPU_WIDE: |
| 431 | ret += perf_event__fprintf_switch(event, fp); |
| 432 | break; |
Jiri Olsa | 3d7c27b | 2018-01-07 17:03:53 +0100 | [diff] [blame] | 433 | case PERF_RECORD_LOST: |
| 434 | ret += perf_event__fprintf_lost(event, fp); |
| 435 | break; |
Song Liu | 9aa0bfa | 2019-01-17 08:15:17 -0800 | [diff] [blame] | 436 | case PERF_RECORD_KSYMBOL: |
| 437 | ret += perf_event__fprintf_ksymbol(event, fp); |
| 438 | break; |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 439 | case PERF_RECORD_BPF_EVENT: |
Arnaldo Carvalho de Melo | 3f604b5 | 2019-08-26 19:28:13 -0300 | [diff] [blame] | 440 | ret += perf_event__fprintf_bpf(event, fp); |
Song Liu | 45178a9 | 2019-01-17 08:15:18 -0800 | [diff] [blame] | 441 | break; |
Arnaldo Carvalho de Melo | 482ad89 | 2011-12-02 11:06:37 -0200 | [diff] [blame] | 442 | default: |
| 443 | ret += fprintf(fp, "\n"); |
| 444 | } |
| 445 | |
| 446 | return ret; |
| 447 | } |
| 448 | |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 449 | int perf_event__process(struct perf_tool *tool __maybe_unused, |
| 450 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 451 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 452 | struct machine *machine) |
Srikar Dronamraju | b83f920 | 2010-08-02 18:08:51 +0530 | [diff] [blame] | 453 | { |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 454 | return machine__process_event(machine, event, sample); |
Srikar Dronamraju | b83f920 | 2010-08-02 18:08:51 +0530 | [diff] [blame] | 455 | } |
| 456 | |
Arnaldo Carvalho de Melo | 3183f8c | 2018-04-26 16:52:34 -0300 | [diff] [blame] | 457 | struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, |
| 458 | struct addr_location *al) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 459 | { |
Arnaldo Carvalho de Melo | 93d5731 | 2014-03-21 17:57:01 -0300 | [diff] [blame] | 460 | struct map_groups *mg = thread->mg; |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 461 | struct machine *machine = mg->machine; |
Adrian Hunter | 5b7ba82 | 2013-08-07 14:38:46 +0300 | [diff] [blame] | 462 | bool load_map = false; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 463 | |
Arnaldo Carvalho de Melo | d3a022c | 2019-11-04 09:59:48 -0300 | [diff] [blame] | 464 | al->mg = mg; |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 465 | al->thread = thread; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 466 | al->addr = addr; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 467 | al->cpumode = cpumode; |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 468 | al->filtered = 0; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 469 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 470 | if (machine == NULL) { |
| 471 | al->map = NULL; |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 472 | return NULL; |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 473 | } |
| 474 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 475 | if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 476 | al->level = 'k'; |
Arnaldo Carvalho de Melo | d3a022c | 2019-11-04 09:59:48 -0300 | [diff] [blame] | 477 | al->mg = mg = &machine->kmaps; |
Adrian Hunter | 5b7ba82 | 2013-08-07 14:38:46 +0300 | [diff] [blame] | 478 | load_map = true; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 479 | } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 480 | al->level = '.'; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 481 | } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { |
| 482 | al->level = 'g'; |
Arnaldo Carvalho de Melo | d3a022c | 2019-11-04 09:59:48 -0300 | [diff] [blame] | 483 | al->mg = mg = &machine->kmaps; |
Adrian Hunter | 5b7ba82 | 2013-08-07 14:38:46 +0300 | [diff] [blame] | 484 | load_map = true; |
Dongsheng Yang | fb50bb4 | 2013-12-20 15:52:56 -0500 | [diff] [blame] | 485 | } else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) { |
| 486 | al->level = 'u'; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 487 | } else { |
Dongsheng Yang | fb50bb4 | 2013-12-20 15:52:56 -0500 | [diff] [blame] | 488 | al->level = 'H'; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 489 | al->map = NULL; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 490 | |
| 491 | if ((cpumode == PERF_RECORD_MISC_GUEST_USER || |
| 492 | cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && |
| 493 | !perf_guest) |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 494 | al->filtered |= (1 << HIST_FILTER__GUEST); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 495 | if ((cpumode == PERF_RECORD_MISC_USER || |
| 496 | cpumode == PERF_RECORD_MISC_KERNEL) && |
| 497 | !perf_host) |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 498 | al->filtered |= (1 << HIST_FILTER__HOST); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 499 | |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 500 | return NULL; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 501 | } |
Arnaldo Carvalho de Melo | edeb0c9 | 2018-10-16 17:08:29 -0300 | [diff] [blame] | 502 | |
Arnaldo Carvalho de Melo | 3183f8c | 2018-04-26 16:52:34 -0300 | [diff] [blame] | 503 | al->map = map_groups__find(mg, al->addr); |
Arnaldo Carvalho de Melo | edeb0c9 | 2018-10-16 17:08:29 -0300 | [diff] [blame] | 504 | if (al->map != NULL) { |
Adrian Hunter | 5b7ba82 | 2013-08-07 14:38:46 +0300 | [diff] [blame] | 505 | /* |
| 506 | * Kernel maps might be changed when loading symbols so loading |
| 507 | * must be done prior to using kernel maps. |
| 508 | */ |
| 509 | if (load_map) |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 510 | map__load(al->map); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 511 | al->addr = al->map->map_ip(al->map, al->addr); |
Adrian Hunter | 5b7ba82 | 2013-08-07 14:38:46 +0300 | [diff] [blame] | 512 | } |
Arnaldo Carvalho de Melo | 71a84b5 | 2018-04-24 11:58:56 -0300 | [diff] [blame] | 513 | |
| 514 | return al->map; |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 515 | } |
| 516 | |
Adrian Hunter | 8e80ad9 | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 517 | /* |
| 518 | * For branch stacks or branch samples, the sample cpumode might not be correct |
| 519 | * because it applies only to the sample 'ip' and not necessary to 'addr' or |
| 520 | * branch stack addresses. If possible, use a fallback to deal with those cases. |
| 521 | */ |
| 522 | struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, |
| 523 | struct addr_location *al) |
| 524 | { |
| 525 | struct map *map = thread__find_map(thread, cpumode, addr, al); |
| 526 | struct machine *machine = thread->mg->machine; |
| 527 | u8 addr_cpumode = machine__addr_cpumode(machine, cpumode, addr); |
| 528 | |
| 529 | if (map || addr_cpumode == cpumode) |
| 530 | return map; |
| 531 | |
| 532 | return thread__find_map(thread, addr_cpumode, addr, al); |
| 533 | } |
| 534 | |
Arnaldo Carvalho de Melo | 117d3c2 | 2018-04-25 18:16:53 -0300 | [diff] [blame] | 535 | struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, |
| 536 | u64 addr, struct addr_location *al) |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 537 | { |
Arnaldo Carvalho de Melo | d9a5f27 | 2018-04-24 12:05:48 -0300 | [diff] [blame] | 538 | al->sym = NULL; |
Arnaldo Carvalho de Melo | 404eb5a | 2018-04-26 09:34:37 -0300 | [diff] [blame] | 539 | if (thread__find_map(thread, cpumode, addr, al)) |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 540 | al->sym = map__find_symbol(al->map, al->addr); |
Arnaldo Carvalho de Melo | d9a5f27 | 2018-04-24 12:05:48 -0300 | [diff] [blame] | 541 | return al->sym; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 542 | } |
| 543 | |
Adrian Hunter | 8e80ad9 | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 544 | struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, |
| 545 | u64 addr, struct addr_location *al) |
| 546 | { |
| 547 | al->sym = NULL; |
| 548 | if (thread__find_map_fb(thread, cpumode, addr, al)) |
| 549 | al->sym = map__find_symbol(al->map, al->addr); |
| 550 | return al->sym; |
| 551 | } |
| 552 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 553 | /* |
| 554 | * Callers need to drop the reference to al->thread, obtained in |
| 555 | * machine__findnew_thread() |
| 556 | */ |
Arnaldo Carvalho de Melo | bb3eb56 | 2016-03-22 18:39:09 -0300 | [diff] [blame] | 557 | int machine__resolve(struct machine *machine, struct addr_location *al, |
| 558 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 559 | { |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 560 | struct thread *thread = machine__findnew_thread(machine, sample->pid, |
Namhyung Kim | 13ce34d | 2014-05-12 09:56:42 +0900 | [diff] [blame] | 561 | sample->tid); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 562 | |
| 563 | if (thread == NULL) |
| 564 | return -1; |
| 565 | |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 566 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); |
Arnaldo Carvalho de Melo | f07a2d3 | 2018-04-24 10:49:50 -0300 | [diff] [blame] | 567 | thread__find_map(thread, sample->cpumode, sample->ip, al); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 568 | dump_printf(" ...... dso: %s\n", |
| 569 | al->map ? al->map->dso->long_name : |
| 570 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
Namhyung Kim | 466fa76 | 2014-03-17 17:12:27 -0300 | [diff] [blame] | 571 | |
| 572 | if (thread__is_filtered(thread)) |
| 573 | al->filtered |= (1 << HIST_FILTER__THREAD); |
| 574 | |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 575 | al->sym = NULL; |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 576 | al->cpu = sample->cpu; |
Kan Liang | 0c4c4deb | 2015-09-04 10:45:42 -0400 | [diff] [blame] | 577 | al->socket = -1; |
Milian Wolff | 1fb7d06 | 2017-10-19 13:38:35 +0200 | [diff] [blame] | 578 | al->srcline = NULL; |
Kan Liang | 0c4c4deb | 2015-09-04 10:45:42 -0400 | [diff] [blame] | 579 | |
| 580 | if (al->cpu >= 0) { |
| 581 | struct perf_env *env = machine->env; |
| 582 | |
| 583 | if (env && env->cpu) |
| 584 | al->socket = env->cpu[al->cpu].socket_id; |
| 585 | } |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 586 | |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 587 | if (al->map) { |
Namhyung Kim | cb8f4e9 | 2011-12-13 00:16:55 +0900 | [diff] [blame] | 588 | struct dso *dso = al->map->dso; |
| 589 | |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 590 | if (symbol_conf.dso_list && |
Namhyung Kim | cb8f4e9 | 2011-12-13 00:16:55 +0900 | [diff] [blame] | 591 | (!dso || !(strlist__has_entry(symbol_conf.dso_list, |
| 592 | dso->short_name) || |
| 593 | (dso->short_name != dso->long_name && |
| 594 | strlist__has_entry(symbol_conf.dso_list, |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 595 | dso->long_name))))) { |
| 596 | al->filtered |= (1 << HIST_FILTER__DSO); |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 597 | } |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 598 | |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 599 | al->sym = map__find_symbol(al->map, al->addr); |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 600 | } |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 601 | |
Feng Tang | 1500b93 | 2012-09-07 16:42:23 +0800 | [diff] [blame] | 602 | if (symbol_conf.sym_list && |
| 603 | (!al->sym || !strlist__has_entry(symbol_conf.sym_list, |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 604 | al->sym->name))) { |
| 605 | al->filtered |= (1 << HIST_FILTER__SYMBOL); |
Namhyung Kim | b3cef7f | 2014-03-17 16:59:21 -0300 | [diff] [blame] | 606 | } |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 607 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 608 | return 0; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 609 | } |
Adrian Hunter | 9b0d2d8 | 2014-07-22 16:17:39 +0300 | [diff] [blame] | 610 | |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 611 | /* |
| 612 | * The preprocess_sample method will return with reference counts for the |
| 613 | * in it, when done using (and perhaps getting ref counts if needing to |
| 614 | * keep a pointer to one of those entries) it must be paired with |
| 615 | * addr_location__put(), so that the refcounts can be decremented. |
| 616 | */ |
| 617 | void addr_location__put(struct addr_location *al) |
| 618 | { |
| 619 | thread__zput(al->thread); |
| 620 | } |
| 621 | |
Adrian Hunter | 9b0d2d8 | 2014-07-22 16:17:39 +0300 | [diff] [blame] | 622 | bool is_bts_event(struct perf_event_attr *attr) |
| 623 | { |
| 624 | return attr->type == PERF_TYPE_HARDWARE && |
| 625 | (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && |
| 626 | attr->sample_period == 1; |
| 627 | } |
| 628 | |
| 629 | bool sample_addr_correlates_sym(struct perf_event_attr *attr) |
| 630 | { |
| 631 | if (attr->type == PERF_TYPE_SOFTWARE && |
| 632 | (attr->config == PERF_COUNT_SW_PAGE_FAULTS || |
| 633 | attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN || |
| 634 | attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)) |
| 635 | return true; |
| 636 | |
| 637 | if (is_bts_event(attr)) |
| 638 | return true; |
| 639 | |
| 640 | return false; |
| 641 | } |
| 642 | |
Arnaldo Carvalho de Melo | c2740a8 | 2016-03-22 18:44:46 -0300 | [diff] [blame] | 643 | void thread__resolve(struct thread *thread, struct addr_location *al, |
| 644 | struct perf_sample *sample) |
Adrian Hunter | 9b0d2d8 | 2014-07-22 16:17:39 +0300 | [diff] [blame] | 645 | { |
Adrian Hunter | 225f99e | 2018-11-06 23:07:11 +0200 | [diff] [blame] | 646 | thread__find_map_fb(thread, sample->cpumode, sample->addr, al); |
Adrian Hunter | 9b0d2d8 | 2014-07-22 16:17:39 +0300 | [diff] [blame] | 647 | |
| 648 | al->cpu = sample->cpu; |
| 649 | al->sym = NULL; |
| 650 | |
| 651 | if (al->map) |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 652 | al->sym = map__find_symbol(al->map, al->addr); |
Adrian Hunter | 9b0d2d8 | 2014-07-22 16:17:39 +0300 | [diff] [blame] | 653 | } |