Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 2 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 3 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 4 | #include <linux/kernel.h> |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 5 | #include <traceevent/event-parse.h> |
Alexander Shishkin | 05a1f47 | 2017-03-16 18:41:59 +0200 | [diff] [blame] | 6 | #include <api/fs/fs.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 7 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 8 | #include <byteswap.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 9 | #include <unistd.h> |
| 10 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | a41794c | 2010-05-18 18:29:23 -0300 | [diff] [blame] | 11 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 12 | |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 13 | #include "evlist.h" |
| 14 | #include "evsel.h" |
Arnaldo Carvalho de Melo | 98521b3 | 2017-04-25 15:45:35 -0300 | [diff] [blame] | 15 | #include "memswap.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 16 | #include "session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 17 | #include "tool.h" |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 18 | #include "sort.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 19 | #include "util.h" |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 20 | #include "cpumap.h" |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 21 | #include "perf_regs.h" |
Jiri Olsa | b0a4520 | 2014-06-12 09:50:11 +0200 | [diff] [blame] | 22 | #include "asm/bug.h" |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 23 | #include "auxtrace.h" |
Arnaldo Carvalho de Melo | e7ff892 | 2017-04-19 21:34:35 -0300 | [diff] [blame] | 24 | #include "thread.h" |
Adrian Hunter | a5499b3 | 2015-05-29 16:33:30 +0300 | [diff] [blame] | 25 | #include "thread-stack.h" |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 26 | #include "stat.h" |
Adrian Hunter | ec1891a | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 27 | #include "arch/common.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 28 | |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 29 | static int perf_session__deliver_event(struct perf_session *session, |
| 30 | union perf_event *event, |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 31 | struct perf_tool *tool, |
| 32 | u64 file_offset); |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 33 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 34 | static int perf_session__open(struct perf_session *session) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 35 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 36 | struct perf_data *data = session->data; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 37 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 38 | if (perf_session__read_header(session) < 0) { |
Arnaldo Carvalho de Melo | e87b491 | 2015-11-09 17:12:03 -0300 | [diff] [blame] | 39 | pr_err("incompatible file format (rerun with -v to learn more)\n"); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 40 | return -1; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 41 | } |
| 42 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 43 | if (perf_data__is_pipe(data)) |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 44 | return 0; |
| 45 | |
Jiri Olsa | 3ba78bd | 2015-11-05 15:40:47 +0100 | [diff] [blame] | 46 | if (perf_header__has_feat(&session->header, HEADER_STAT)) |
| 47 | return 0; |
| 48 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 49 | if (!perf_evlist__valid_sample_type(session->evlist)) { |
Arnaldo Carvalho de Melo | e87b491 | 2015-11-09 17:12:03 -0300 | [diff] [blame] | 50 | pr_err("non matching sample_type\n"); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 51 | return -1; |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 52 | } |
| 53 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 54 | if (!perf_evlist__valid_sample_id_all(session->evlist)) { |
Arnaldo Carvalho de Melo | e87b491 | 2015-11-09 17:12:03 -0300 | [diff] [blame] | 55 | pr_err("non matching sample_id_all\n"); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 56 | return -1; |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 57 | } |
| 58 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 59 | if (!perf_evlist__valid_read_format(session->evlist)) { |
Arnaldo Carvalho de Melo | e87b491 | 2015-11-09 17:12:03 -0300 | [diff] [blame] | 60 | pr_err("non matching read_format\n"); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 61 | return -1; |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 64 | return 0; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 65 | } |
| 66 | |
Arnaldo Carvalho de Melo | 7b56cce | 2012-08-01 19:31:00 -0300 | [diff] [blame] | 67 | void perf_session__set_id_hdr_size(struct perf_session *session) |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 68 | { |
Arnaldo Carvalho de Melo | 7b56cce | 2012-08-01 19:31:00 -0300 | [diff] [blame] | 69 | u16 id_hdr_size = perf_evlist__id_hdr_size(session->evlist); |
| 70 | |
Arnaldo Carvalho de Melo | 7b56cce | 2012-08-01 19:31:00 -0300 | [diff] [blame] | 71 | machines__set_id_hdr_size(&session->machines, id_hdr_size); |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 72 | } |
| 73 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 74 | int perf_session__create_kernel_maps(struct perf_session *session) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 75 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 76 | int ret = machine__create_kernel_maps(&session->machines.host); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 77 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 78 | if (ret >= 0) |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 79 | ret = machines__create_guest_kernel_maps(&session->machines); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 80 | return ret; |
| 81 | } |
| 82 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 83 | static void perf_session__destroy_kernel_maps(struct perf_session *session) |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 84 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 85 | machines__destroy_kernel_maps(&session->machines); |
Arnaldo Carvalho de Melo | 076c6e45 | 2010-08-02 18:18:28 -0300 | [diff] [blame] | 86 | } |
| 87 | |
Adrian Hunter | cfe1c41 | 2014-07-31 09:00:45 +0300 | [diff] [blame] | 88 | static bool perf_session__has_comm_exec(struct perf_session *session) |
| 89 | { |
| 90 | struct perf_evsel *evsel; |
| 91 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 92 | evlist__for_each_entry(session->evlist, evsel) { |
Adrian Hunter | cfe1c41 | 2014-07-31 09:00:45 +0300 | [diff] [blame] | 93 | if (evsel->attr.comm_exec) |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | static void perf_session__set_comm_exec(struct perf_session *session) |
| 101 | { |
| 102 | bool comm_exec = perf_session__has_comm_exec(session); |
| 103 | |
| 104 | machines__set_comm_exec(&session->machines, comm_exec); |
| 105 | } |
| 106 | |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 107 | static int ordered_events__deliver_event(struct ordered_events *oe, |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 108 | struct ordered_event *event) |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 109 | { |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 110 | struct perf_session *session = container_of(oe, struct perf_session, |
| 111 | ordered_events); |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 112 | |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 113 | return perf_session__deliver_event(session, event->event, |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 114 | session->tool, event->file_offset); |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 115 | } |
| 116 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 117 | struct perf_session *perf_session__new(struct perf_data *data, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 118 | bool repipe, struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 119 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 120 | struct perf_session *session = zalloc(sizeof(*session)); |
Robert Richter | efad141 | 2011-12-07 10:02:54 +0100 | [diff] [blame] | 121 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 122 | if (!session) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 123 | goto out; |
| 124 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 125 | session->repipe = repipe; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 126 | session->tool = tool; |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 127 | INIT_LIST_HEAD(&session->auxtrace_index); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 128 | machines__init(&session->machines); |
Jiri Olsa | a4a6668 | 2018-11-07 16:58:36 +0100 | [diff] [blame^] | 129 | ordered_events__init(&session->ordered_events, |
| 130 | ordered_events__deliver_event, NULL); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 131 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 132 | if (data) { |
| 133 | if (perf_data__open(data)) |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 134 | goto out_delete; |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 135 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 136 | session->data = data; |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 137 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 138 | if (perf_data__is_read(data)) { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 139 | if (perf_session__open(session) < 0) |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 140 | goto out_close; |
| 141 | |
David Carrillo-Cisneros | 0973ad9 | 2017-04-10 13:14:30 -0700 | [diff] [blame] | 142 | /* |
| 143 | * set session attributes that are present in perf.data |
| 144 | * but not in pipe-mode. |
| 145 | */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 146 | if (!data->is_pipe) { |
David Carrillo-Cisneros | 0973ad9 | 2017-04-10 13:14:30 -0700 | [diff] [blame] | 147 | perf_session__set_id_hdr_size(session); |
| 148 | perf_session__set_comm_exec(session); |
| 149 | } |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 150 | } |
Arnaldo Carvalho de Melo | 4cde998 | 2015-09-09 12:25:00 -0300 | [diff] [blame] | 151 | } else { |
| 152 | session->machines.host.env = &perf_env; |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Adrian Hunter | ec1891a | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 155 | session->machines.host.single_address_space = |
| 156 | perf_env__single_address_space(session->machines.host.env); |
| 157 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 158 | if (!data || perf_data__is_write(data)) { |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 159 | /* |
| 160 | * In O_RDONLY mode this will be performed when reading the |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 161 | * kernel MMAP event, in perf_event__process_mmap(). |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 162 | */ |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 163 | if (perf_session__create_kernel_maps(session) < 0) |
Andi Kleen | a5c2a4c | 2014-09-24 14:39:54 -0700 | [diff] [blame] | 164 | pr_warning("Cannot read kernel map\n"); |
Arnaldo Carvalho de Melo | 64abebf7 | 2010-01-27 21:05:52 -0200 | [diff] [blame] | 165 | } |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 166 | |
David Carrillo-Cisneros | 0973ad9 | 2017-04-10 13:14:30 -0700 | [diff] [blame] | 167 | /* |
| 168 | * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is |
| 169 | * processed, so perf_evlist__sample_id_all is not meaningful here. |
| 170 | */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 171 | if ((!data || !data->is_pipe) && tool && tool->ordering_requires_timestamps && |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 172 | tool->ordered_events && !perf_evlist__sample_id_all(session->evlist)) { |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 173 | dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 174 | tool->ordered_events = false; |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 175 | } |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 176 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 177 | return session; |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 178 | |
| 179 | out_close: |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 180 | perf_data__close(data); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 181 | out_delete: |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 182 | perf_session__delete(session); |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 183 | out: |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 184 | return NULL; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 185 | } |
| 186 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 187 | static void perf_session__delete_threads(struct perf_session *session) |
| 188 | { |
Arnaldo Carvalho de Melo | 876650e6 | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 189 | machine__delete_threads(&session->machines.host); |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 190 | } |
| 191 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 192 | void perf_session__delete(struct perf_session *session) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 193 | { |
Arnaldo Carvalho de Melo | e144655 | 2016-06-22 10:02:16 -0300 | [diff] [blame] | 194 | if (session == NULL) |
| 195 | return; |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 196 | auxtrace__free(session); |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 197 | auxtrace_index__free(&session->auxtrace_index); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 198 | perf_session__destroy_kernel_maps(session); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 199 | perf_session__delete_threads(session); |
Arnaldo Carvalho de Melo | f0ce888 | 2015-09-08 13:30:00 -0300 | [diff] [blame] | 200 | perf_env__exit(&session->header.env); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 201 | machines__exit(&session->machines); |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 202 | if (session->data) |
| 203 | perf_data__close(session->data); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 204 | free(session); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 205 | } |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 206 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 207 | static int process_event_synth_tracing_data_stub(struct perf_session *session |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 208 | __maybe_unused, |
| 209 | union perf_event *event |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 210 | __maybe_unused) |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 211 | { |
| 212 | dump_printf(": unhandled!\n"); |
| 213 | return 0; |
| 214 | } |
| 215 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 216 | static int process_event_synth_attr_stub(struct perf_tool *tool __maybe_unused, |
| 217 | union perf_event *event __maybe_unused, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 218 | struct perf_evlist **pevlist |
| 219 | __maybe_unused) |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 220 | { |
| 221 | dump_printf(": unhandled!\n"); |
| 222 | return 0; |
| 223 | } |
| 224 | |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 225 | static int process_event_synth_event_update_stub(struct perf_tool *tool __maybe_unused, |
| 226 | union perf_event *event __maybe_unused, |
| 227 | struct perf_evlist **pevlist |
| 228 | __maybe_unused) |
| 229 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 230 | if (dump_trace) |
| 231 | perf_event__fprintf_event_update(event, stdout); |
| 232 | |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 233 | dump_printf(": unhandled!\n"); |
| 234 | return 0; |
| 235 | } |
| 236 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 237 | static int process_event_sample_stub(struct perf_tool *tool __maybe_unused, |
| 238 | union perf_event *event __maybe_unused, |
| 239 | struct perf_sample *sample __maybe_unused, |
| 240 | struct perf_evsel *evsel __maybe_unused, |
| 241 | struct machine *machine __maybe_unused) |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 242 | { |
| 243 | dump_printf(": unhandled!\n"); |
| 244 | return 0; |
| 245 | } |
| 246 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 247 | static int process_event_stub(struct perf_tool *tool __maybe_unused, |
| 248 | union perf_event *event __maybe_unused, |
| 249 | struct perf_sample *sample __maybe_unused, |
| 250 | struct machine *machine __maybe_unused) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 251 | { |
| 252 | dump_printf(": unhandled!\n"); |
| 253 | return 0; |
| 254 | } |
| 255 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 256 | static int process_finished_round_stub(struct perf_tool *tool __maybe_unused, |
| 257 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 258 | struct ordered_events *oe __maybe_unused) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 259 | { |
| 260 | dump_printf(": unhandled!\n"); |
| 261 | return 0; |
| 262 | } |
| 263 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 264 | static int process_finished_round(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 265 | union perf_event *event, |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 266 | struct ordered_events *oe); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 267 | |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 268 | static int skipn(int fd, off_t n) |
| 269 | { |
| 270 | char buf[4096]; |
| 271 | ssize_t ret; |
| 272 | |
| 273 | while (n > 0) { |
| 274 | ret = read(fd, buf, min(n, (off_t)sizeof(buf))); |
| 275 | if (ret <= 0) |
| 276 | return ret; |
| 277 | n -= ret; |
| 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Jiri Olsa | 7336555 | 2018-09-13 14:54:04 +0200 | [diff] [blame] | 283 | static s64 process_event_auxtrace_stub(struct perf_session *session __maybe_unused, |
| 284 | union perf_event *event) |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 285 | { |
| 286 | dump_printf(": unhandled!\n"); |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 287 | if (perf_data__is_pipe(session->data)) |
| 288 | skipn(perf_data__fd(session->data), event->auxtrace.size); |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 289 | return event->auxtrace.size; |
| 290 | } |
| 291 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 292 | static int process_event_op2_stub(struct perf_session *session __maybe_unused, |
| 293 | union perf_event *event __maybe_unused) |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 294 | { |
| 295 | dump_printf(": unhandled!\n"); |
| 296 | return 0; |
| 297 | } |
| 298 | |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 299 | |
| 300 | static |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 301 | int process_event_thread_map_stub(struct perf_session *session __maybe_unused, |
| 302 | union perf_event *event __maybe_unused) |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 303 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 304 | if (dump_trace) |
| 305 | perf_event__fprintf_thread_map(event, stdout); |
| 306 | |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 307 | dump_printf(": unhandled!\n"); |
| 308 | return 0; |
| 309 | } |
| 310 | |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 311 | static |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 312 | int process_event_cpu_map_stub(struct perf_session *session __maybe_unused, |
| 313 | union perf_event *event __maybe_unused) |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 314 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 315 | if (dump_trace) |
| 316 | perf_event__fprintf_cpu_map(event, stdout); |
| 317 | |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 318 | dump_printf(": unhandled!\n"); |
| 319 | return 0; |
| 320 | } |
| 321 | |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 322 | static |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 323 | int process_event_stat_config_stub(struct perf_session *session __maybe_unused, |
| 324 | union perf_event *event __maybe_unused) |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 325 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 326 | if (dump_trace) |
| 327 | perf_event__fprintf_stat_config(event, stdout); |
| 328 | |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 329 | dump_printf(": unhandled!\n"); |
| 330 | return 0; |
| 331 | } |
| 332 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 333 | static int process_stat_stub(struct perf_session *perf_session __maybe_unused, |
| 334 | union perf_event *event) |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 335 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 336 | if (dump_trace) |
| 337 | perf_event__fprintf_stat(event, stdout); |
| 338 | |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 339 | dump_printf(": unhandled!\n"); |
| 340 | return 0; |
| 341 | } |
| 342 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 343 | static int process_stat_round_stub(struct perf_session *perf_session __maybe_unused, |
| 344 | union perf_event *event) |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 345 | { |
Jiri Olsa | 2d2aea6 | 2015-10-25 15:51:42 +0100 | [diff] [blame] | 346 | if (dump_trace) |
| 347 | perf_event__fprintf_stat_round(event, stdout); |
| 348 | |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 349 | dump_printf(": unhandled!\n"); |
| 350 | return 0; |
| 351 | } |
| 352 | |
David Ahern | 9c50140 | 2013-08-02 14:05:41 -0600 | [diff] [blame] | 353 | void perf_tool__fill_defaults(struct perf_tool *tool) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 354 | { |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 355 | if (tool->sample == NULL) |
| 356 | tool->sample = process_event_sample_stub; |
| 357 | if (tool->mmap == NULL) |
| 358 | tool->mmap = process_event_stub; |
David Ahern | 6adb0b0 | 2013-09-22 19:44:59 -0600 | [diff] [blame] | 359 | if (tool->mmap2 == NULL) |
| 360 | tool->mmap2 = process_event_stub; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 361 | if (tool->comm == NULL) |
| 362 | tool->comm = process_event_stub; |
Namhyung Kim | 7f0cd23 | 2017-10-17 22:29:00 +0900 | [diff] [blame] | 363 | if (tool->namespaces == NULL) |
| 364 | tool->namespaces = process_event_stub; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 365 | if (tool->fork == NULL) |
| 366 | tool->fork = process_event_stub; |
| 367 | if (tool->exit == NULL) |
| 368 | tool->exit = process_event_stub; |
| 369 | if (tool->lost == NULL) |
| 370 | tool->lost = perf_event__process_lost; |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 371 | if (tool->lost_samples == NULL) |
| 372 | tool->lost_samples = perf_event__process_lost_samples; |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 373 | if (tool->aux == NULL) |
| 374 | tool->aux = perf_event__process_aux; |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 375 | if (tool->itrace_start == NULL) |
| 376 | tool->itrace_start = perf_event__process_itrace_start; |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 377 | if (tool->context_switch == NULL) |
| 378 | tool->context_switch = perf_event__process_switch; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 379 | if (tool->read == NULL) |
| 380 | tool->read = process_event_sample_stub; |
| 381 | if (tool->throttle == NULL) |
| 382 | tool->throttle = process_event_stub; |
| 383 | if (tool->unthrottle == NULL) |
| 384 | tool->unthrottle = process_event_stub; |
| 385 | if (tool->attr == NULL) |
| 386 | tool->attr = process_event_synth_attr_stub; |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 387 | if (tool->event_update == NULL) |
| 388 | tool->event_update = process_event_synth_event_update_stub; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 389 | if (tool->tracing_data == NULL) |
| 390 | tool->tracing_data = process_event_synth_tracing_data_stub; |
| 391 | if (tool->build_id == NULL) |
Adrian Hunter | 5fb0ac1 | 2016-03-07 16:44:39 -0300 | [diff] [blame] | 392 | tool->build_id = process_event_op2_stub; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 393 | if (tool->finished_round == NULL) { |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 394 | if (tool->ordered_events) |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 395 | tool->finished_round = process_finished_round; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 396 | else |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 397 | tool->finished_round = process_finished_round_stub; |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 398 | } |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 399 | if (tool->id_index == NULL) |
Adrian Hunter | 5fb0ac1 | 2016-03-07 16:44:39 -0300 | [diff] [blame] | 400 | tool->id_index = process_event_op2_stub; |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 401 | if (tool->auxtrace_info == NULL) |
Adrian Hunter | 5fb0ac1 | 2016-03-07 16:44:39 -0300 | [diff] [blame] | 402 | tool->auxtrace_info = process_event_op2_stub; |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 403 | if (tool->auxtrace == NULL) |
| 404 | tool->auxtrace = process_event_auxtrace_stub; |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 405 | if (tool->auxtrace_error == NULL) |
Adrian Hunter | 5fb0ac1 | 2016-03-07 16:44:39 -0300 | [diff] [blame] | 406 | tool->auxtrace_error = process_event_op2_stub; |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 407 | if (tool->thread_map == NULL) |
| 408 | tool->thread_map = process_event_thread_map_stub; |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 409 | if (tool->cpu_map == NULL) |
| 410 | tool->cpu_map = process_event_cpu_map_stub; |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 411 | if (tool->stat_config == NULL) |
| 412 | tool->stat_config = process_event_stat_config_stub; |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 413 | if (tool->stat == NULL) |
| 414 | tool->stat = process_stat_stub; |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 415 | if (tool->stat_round == NULL) |
| 416 | tool->stat_round = process_stat_round_stub; |
Adrian Hunter | 46bc29b | 2016-03-08 10:38:44 +0200 | [diff] [blame] | 417 | if (tool->time_conv == NULL) |
| 418 | tool->time_conv = process_event_op2_stub; |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 419 | if (tool->feature == NULL) |
| 420 | tool->feature = process_event_op2_stub; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 421 | } |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 422 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 423 | static void swap_sample_id_all(union perf_event *event, void *data) |
| 424 | { |
| 425 | void *end = (void *) event + event->header.size; |
| 426 | int size = end - data; |
| 427 | |
| 428 | BUG_ON(size % sizeof(u64)); |
| 429 | mem_bswap_64(data, size); |
| 430 | } |
| 431 | |
| 432 | static void perf_event__all64_swap(union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 433 | bool sample_id_all __maybe_unused) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 434 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 435 | struct perf_event_header *hdr = &event->header; |
| 436 | mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr)); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 437 | } |
| 438 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 439 | static void perf_event__comm_swap(union perf_event *event, bool sample_id_all) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 440 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 441 | event->comm.pid = bswap_32(event->comm.pid); |
| 442 | event->comm.tid = bswap_32(event->comm.tid); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 443 | |
| 444 | if (sample_id_all) { |
| 445 | void *data = &event->comm.comm; |
| 446 | |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 447 | data += PERF_ALIGN(strlen(data) + 1, sizeof(u64)); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 448 | swap_sample_id_all(event, data); |
| 449 | } |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 450 | } |
| 451 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 452 | static void perf_event__mmap_swap(union perf_event *event, |
| 453 | bool sample_id_all) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 454 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 455 | event->mmap.pid = bswap_32(event->mmap.pid); |
| 456 | event->mmap.tid = bswap_32(event->mmap.tid); |
| 457 | event->mmap.start = bswap_64(event->mmap.start); |
| 458 | event->mmap.len = bswap_64(event->mmap.len); |
| 459 | event->mmap.pgoff = bswap_64(event->mmap.pgoff); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 460 | |
| 461 | if (sample_id_all) { |
| 462 | void *data = &event->mmap.filename; |
| 463 | |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 464 | data += PERF_ALIGN(strlen(data) + 1, sizeof(u64)); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 465 | swap_sample_id_all(event, data); |
| 466 | } |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 467 | } |
| 468 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 469 | static void perf_event__mmap2_swap(union perf_event *event, |
| 470 | bool sample_id_all) |
| 471 | { |
| 472 | event->mmap2.pid = bswap_32(event->mmap2.pid); |
| 473 | event->mmap2.tid = bswap_32(event->mmap2.tid); |
| 474 | event->mmap2.start = bswap_64(event->mmap2.start); |
| 475 | event->mmap2.len = bswap_64(event->mmap2.len); |
| 476 | event->mmap2.pgoff = bswap_64(event->mmap2.pgoff); |
| 477 | event->mmap2.maj = bswap_32(event->mmap2.maj); |
| 478 | event->mmap2.min = bswap_32(event->mmap2.min); |
| 479 | event->mmap2.ino = bswap_64(event->mmap2.ino); |
| 480 | |
| 481 | if (sample_id_all) { |
| 482 | void *data = &event->mmap2.filename; |
| 483 | |
| 484 | data += PERF_ALIGN(strlen(data) + 1, sizeof(u64)); |
| 485 | swap_sample_id_all(event, data); |
| 486 | } |
| 487 | } |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 488 | static void perf_event__task_swap(union perf_event *event, bool sample_id_all) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 489 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 490 | event->fork.pid = bswap_32(event->fork.pid); |
| 491 | event->fork.tid = bswap_32(event->fork.tid); |
| 492 | event->fork.ppid = bswap_32(event->fork.ppid); |
| 493 | event->fork.ptid = bswap_32(event->fork.ptid); |
| 494 | event->fork.time = bswap_64(event->fork.time); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 495 | |
| 496 | if (sample_id_all) |
| 497 | swap_sample_id_all(event, &event->fork + 1); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 498 | } |
| 499 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 500 | static void perf_event__read_swap(union perf_event *event, bool sample_id_all) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 501 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 502 | event->read.pid = bswap_32(event->read.pid); |
| 503 | event->read.tid = bswap_32(event->read.tid); |
| 504 | event->read.value = bswap_64(event->read.value); |
| 505 | event->read.time_enabled = bswap_64(event->read.time_enabled); |
| 506 | event->read.time_running = bswap_64(event->read.time_running); |
| 507 | event->read.id = bswap_64(event->read.id); |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 508 | |
| 509 | if (sample_id_all) |
| 510 | swap_sample_id_all(event, &event->read + 1); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 511 | } |
| 512 | |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 513 | static void perf_event__aux_swap(union perf_event *event, bool sample_id_all) |
| 514 | { |
| 515 | event->aux.aux_offset = bswap_64(event->aux.aux_offset); |
| 516 | event->aux.aux_size = bswap_64(event->aux.aux_size); |
| 517 | event->aux.flags = bswap_64(event->aux.flags); |
| 518 | |
| 519 | if (sample_id_all) |
| 520 | swap_sample_id_all(event, &event->aux + 1); |
| 521 | } |
| 522 | |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 523 | static void perf_event__itrace_start_swap(union perf_event *event, |
| 524 | bool sample_id_all) |
| 525 | { |
| 526 | event->itrace_start.pid = bswap_32(event->itrace_start.pid); |
| 527 | event->itrace_start.tid = bswap_32(event->itrace_start.tid); |
| 528 | |
| 529 | if (sample_id_all) |
| 530 | swap_sample_id_all(event, &event->itrace_start + 1); |
| 531 | } |
| 532 | |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 533 | static void perf_event__switch_swap(union perf_event *event, bool sample_id_all) |
| 534 | { |
| 535 | if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) { |
| 536 | event->context_switch.next_prev_pid = |
| 537 | bswap_32(event->context_switch.next_prev_pid); |
| 538 | event->context_switch.next_prev_tid = |
| 539 | bswap_32(event->context_switch.next_prev_tid); |
| 540 | } |
| 541 | |
| 542 | if (sample_id_all) |
| 543 | swap_sample_id_all(event, &event->context_switch + 1); |
| 544 | } |
| 545 | |
Jiri Olsa | dd96c46 | 2013-09-01 12:36:15 +0200 | [diff] [blame] | 546 | static void perf_event__throttle_swap(union perf_event *event, |
| 547 | bool sample_id_all) |
| 548 | { |
| 549 | event->throttle.time = bswap_64(event->throttle.time); |
| 550 | event->throttle.id = bswap_64(event->throttle.id); |
| 551 | event->throttle.stream_id = bswap_64(event->throttle.stream_id); |
| 552 | |
| 553 | if (sample_id_all) |
| 554 | swap_sample_id_all(event, &event->throttle + 1); |
| 555 | } |
| 556 | |
Jiri Olsa | e108c66 | 2012-05-16 08:59:03 +0200 | [diff] [blame] | 557 | static u8 revbyte(u8 b) |
| 558 | { |
| 559 | int rev = (b >> 4) | ((b & 0xf) << 4); |
| 560 | rev = ((rev & 0xcc) >> 2) | ((rev & 0x33) << 2); |
| 561 | rev = ((rev & 0xaa) >> 1) | ((rev & 0x55) << 1); |
| 562 | return (u8) rev; |
| 563 | } |
| 564 | |
| 565 | /* |
| 566 | * XXX this is hack in attempt to carry flags bitfield |
Adam Buchbinder | bd1a0be5 | 2016-02-24 10:02:25 -0800 | [diff] [blame] | 567 | * through endian village. ABI says: |
Jiri Olsa | e108c66 | 2012-05-16 08:59:03 +0200 | [diff] [blame] | 568 | * |
| 569 | * Bit-fields are allocated from right to left (least to most significant) |
| 570 | * on little-endian implementations and from left to right (most to least |
| 571 | * significant) on big-endian implementations. |
| 572 | * |
| 573 | * The above seems to be byte specific, so we need to reverse each |
| 574 | * byte of the bitfield. 'Internet' also says this might be implementation |
| 575 | * specific and we probably need proper fix and carry perf_event_attr |
| 576 | * bitfield flags in separate data file FEAT_ section. Thought this seems |
| 577 | * to work for now. |
| 578 | */ |
| 579 | static void swap_bitfield(u8 *p, unsigned len) |
| 580 | { |
| 581 | unsigned i; |
| 582 | |
| 583 | for (i = 0; i < len; i++) { |
| 584 | *p = revbyte(*p); |
| 585 | p++; |
| 586 | } |
| 587 | } |
| 588 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 589 | /* exported for swapping attributes in file header */ |
| 590 | void perf_event__attr_swap(struct perf_event_attr *attr) |
| 591 | { |
| 592 | attr->type = bswap_32(attr->type); |
| 593 | attr->size = bswap_32(attr->size); |
Jiri Olsa | e108c66 | 2012-05-16 08:59:03 +0200 | [diff] [blame] | 594 | |
Wang Nan | b30b617 | 2015-06-17 09:56:39 +0000 | [diff] [blame] | 595 | #define bswap_safe(f, n) \ |
| 596 | (attr->size > (offsetof(struct perf_event_attr, f) + \ |
| 597 | sizeof(attr->f) * (n))) |
| 598 | #define bswap_field(f, sz) \ |
| 599 | do { \ |
| 600 | if (bswap_safe(f, 0)) \ |
| 601 | attr->f = bswap_##sz(attr->f); \ |
| 602 | } while(0) |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 603 | #define bswap_field_16(f) bswap_field(f, 16) |
Wang Nan | b30b617 | 2015-06-17 09:56:39 +0000 | [diff] [blame] | 604 | #define bswap_field_32(f) bswap_field(f, 32) |
| 605 | #define bswap_field_64(f) bswap_field(f, 64) |
| 606 | |
| 607 | bswap_field_64(config); |
| 608 | bswap_field_64(sample_period); |
| 609 | bswap_field_64(sample_type); |
| 610 | bswap_field_64(read_format); |
| 611 | bswap_field_32(wakeup_events); |
| 612 | bswap_field_32(bp_type); |
| 613 | bswap_field_64(bp_addr); |
| 614 | bswap_field_64(bp_len); |
| 615 | bswap_field_64(branch_sample_type); |
| 616 | bswap_field_64(sample_regs_user); |
| 617 | bswap_field_32(sample_stack_user); |
| 618 | bswap_field_32(aux_watermark); |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 619 | bswap_field_16(sample_max_stack); |
Wang Nan | b30b617 | 2015-06-17 09:56:39 +0000 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * After read_format are bitfields. Check read_format because |
| 623 | * we are unable to use offsetof on bitfield. |
| 624 | */ |
| 625 | if (bswap_safe(read_format, 1)) |
| 626 | swap_bitfield((u8 *) (&attr->read_format + 1), |
| 627 | sizeof(u64)); |
| 628 | #undef bswap_field_64 |
| 629 | #undef bswap_field_32 |
| 630 | #undef bswap_field |
| 631 | #undef bswap_safe |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 632 | } |
| 633 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 634 | static void perf_event__hdr_attr_swap(union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 635 | bool sample_id_all __maybe_unused) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 636 | { |
| 637 | size_t size; |
| 638 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 639 | perf_event__attr_swap(&event->attr.attr); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 640 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 641 | size = event->header.size; |
| 642 | size -= (void *)&event->attr.id - (void *)event; |
| 643 | mem_bswap_64(event->attr.id, size); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 646 | static void perf_event__event_update_swap(union perf_event *event, |
| 647 | bool sample_id_all __maybe_unused) |
| 648 | { |
| 649 | event->event_update.type = bswap_64(event->event_update.type); |
| 650 | event->event_update.id = bswap_64(event->event_update.id); |
| 651 | } |
| 652 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 653 | static void perf_event__event_type_swap(union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 654 | bool sample_id_all __maybe_unused) |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 655 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 656 | event->event_type.event_type.event_id = |
| 657 | bswap_64(event->event_type.event_type.event_id); |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 660 | static void perf_event__tracing_data_swap(union perf_event *event, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 661 | bool sample_id_all __maybe_unused) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 662 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 663 | event->tracing_data.size = bswap_32(event->tracing_data.size); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 664 | } |
| 665 | |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 666 | static void perf_event__auxtrace_info_swap(union perf_event *event, |
| 667 | bool sample_id_all __maybe_unused) |
| 668 | { |
| 669 | size_t size; |
| 670 | |
| 671 | event->auxtrace_info.type = bswap_32(event->auxtrace_info.type); |
| 672 | |
| 673 | size = event->header.size; |
| 674 | size -= (void *)&event->auxtrace_info.priv - (void *)event; |
| 675 | mem_bswap_64(event->auxtrace_info.priv, size); |
| 676 | } |
| 677 | |
| 678 | static void perf_event__auxtrace_swap(union perf_event *event, |
| 679 | bool sample_id_all __maybe_unused) |
| 680 | { |
| 681 | event->auxtrace.size = bswap_64(event->auxtrace.size); |
| 682 | event->auxtrace.offset = bswap_64(event->auxtrace.offset); |
| 683 | event->auxtrace.reference = bswap_64(event->auxtrace.reference); |
| 684 | event->auxtrace.idx = bswap_32(event->auxtrace.idx); |
| 685 | event->auxtrace.tid = bswap_32(event->auxtrace.tid); |
| 686 | event->auxtrace.cpu = bswap_32(event->auxtrace.cpu); |
| 687 | } |
| 688 | |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 689 | static void perf_event__auxtrace_error_swap(union perf_event *event, |
| 690 | bool sample_id_all __maybe_unused) |
| 691 | { |
| 692 | event->auxtrace_error.type = bswap_32(event->auxtrace_error.type); |
| 693 | event->auxtrace_error.code = bswap_32(event->auxtrace_error.code); |
| 694 | event->auxtrace_error.cpu = bswap_32(event->auxtrace_error.cpu); |
| 695 | event->auxtrace_error.pid = bswap_32(event->auxtrace_error.pid); |
| 696 | event->auxtrace_error.tid = bswap_32(event->auxtrace_error.tid); |
| 697 | event->auxtrace_error.ip = bswap_64(event->auxtrace_error.ip); |
| 698 | } |
| 699 | |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 700 | static void perf_event__thread_map_swap(union perf_event *event, |
| 701 | bool sample_id_all __maybe_unused) |
| 702 | { |
| 703 | unsigned i; |
| 704 | |
| 705 | event->thread_map.nr = bswap_64(event->thread_map.nr); |
| 706 | |
| 707 | for (i = 0; i < event->thread_map.nr; i++) |
| 708 | event->thread_map.entries[i].pid = bswap_64(event->thread_map.entries[i].pid); |
| 709 | } |
| 710 | |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 711 | static void perf_event__cpu_map_swap(union perf_event *event, |
| 712 | bool sample_id_all __maybe_unused) |
| 713 | { |
| 714 | struct cpu_map_data *data = &event->cpu_map.data; |
| 715 | struct cpu_map_entries *cpus; |
| 716 | struct cpu_map_mask *mask; |
| 717 | unsigned i; |
| 718 | |
| 719 | data->type = bswap_64(data->type); |
| 720 | |
| 721 | switch (data->type) { |
| 722 | case PERF_CPU_MAP__CPUS: |
| 723 | cpus = (struct cpu_map_entries *)data->data; |
| 724 | |
| 725 | cpus->nr = bswap_16(cpus->nr); |
| 726 | |
| 727 | for (i = 0; i < cpus->nr; i++) |
| 728 | cpus->cpu[i] = bswap_16(cpus->cpu[i]); |
| 729 | break; |
| 730 | case PERF_CPU_MAP__MASK: |
| 731 | mask = (struct cpu_map_mask *) data->data; |
| 732 | |
| 733 | mask->nr = bswap_16(mask->nr); |
| 734 | mask->long_size = bswap_16(mask->long_size); |
| 735 | |
| 736 | switch (mask->long_size) { |
| 737 | case 4: mem_bswap_32(&mask->mask, mask->nr); break; |
| 738 | case 8: mem_bswap_64(&mask->mask, mask->nr); break; |
| 739 | default: |
| 740 | pr_err("cpu_map swap: unsupported long size\n"); |
| 741 | } |
| 742 | default: |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 747 | static void perf_event__stat_config_swap(union perf_event *event, |
| 748 | bool sample_id_all __maybe_unused) |
| 749 | { |
| 750 | u64 size; |
| 751 | |
| 752 | size = event->stat_config.nr * sizeof(event->stat_config.data[0]); |
| 753 | size += 1; /* nr item itself */ |
| 754 | mem_bswap_64(&event->stat_config.nr, size); |
| 755 | } |
| 756 | |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 757 | static void perf_event__stat_swap(union perf_event *event, |
| 758 | bool sample_id_all __maybe_unused) |
| 759 | { |
| 760 | event->stat.id = bswap_64(event->stat.id); |
| 761 | event->stat.thread = bswap_32(event->stat.thread); |
| 762 | event->stat.cpu = bswap_32(event->stat.cpu); |
| 763 | event->stat.val = bswap_64(event->stat.val); |
| 764 | event->stat.ena = bswap_64(event->stat.ena); |
| 765 | event->stat.run = bswap_64(event->stat.run); |
| 766 | } |
| 767 | |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 768 | static void perf_event__stat_round_swap(union perf_event *event, |
| 769 | bool sample_id_all __maybe_unused) |
| 770 | { |
| 771 | event->stat_round.type = bswap_64(event->stat_round.type); |
| 772 | event->stat_round.time = bswap_64(event->stat_round.time); |
| 773 | } |
| 774 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 775 | typedef void (*perf_event__swap_op)(union perf_event *event, |
| 776 | bool sample_id_all); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 777 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 778 | static perf_event__swap_op perf_event__swap_ops[] = { |
| 779 | [PERF_RECORD_MMAP] = perf_event__mmap_swap, |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 780 | [PERF_RECORD_MMAP2] = perf_event__mmap2_swap, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 781 | [PERF_RECORD_COMM] = perf_event__comm_swap, |
| 782 | [PERF_RECORD_FORK] = perf_event__task_swap, |
| 783 | [PERF_RECORD_EXIT] = perf_event__task_swap, |
| 784 | [PERF_RECORD_LOST] = perf_event__all64_swap, |
| 785 | [PERF_RECORD_READ] = perf_event__read_swap, |
Jiri Olsa | dd96c46 | 2013-09-01 12:36:15 +0200 | [diff] [blame] | 786 | [PERF_RECORD_THROTTLE] = perf_event__throttle_swap, |
| 787 | [PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 788 | [PERF_RECORD_SAMPLE] = perf_event__all64_swap, |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 789 | [PERF_RECORD_AUX] = perf_event__aux_swap, |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 790 | [PERF_RECORD_ITRACE_START] = perf_event__itrace_start_swap, |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 791 | [PERF_RECORD_LOST_SAMPLES] = perf_event__all64_swap, |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 792 | [PERF_RECORD_SWITCH] = perf_event__switch_swap, |
| 793 | [PERF_RECORD_SWITCH_CPU_WIDE] = perf_event__switch_swap, |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 794 | [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 795 | [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, |
| 796 | [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap, |
| 797 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 798 | [PERF_RECORD_ID_INDEX] = perf_event__all64_swap, |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 799 | [PERF_RECORD_AUXTRACE_INFO] = perf_event__auxtrace_info_swap, |
| 800 | [PERF_RECORD_AUXTRACE] = perf_event__auxtrace_swap, |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 801 | [PERF_RECORD_AUXTRACE_ERROR] = perf_event__auxtrace_error_swap, |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 802 | [PERF_RECORD_THREAD_MAP] = perf_event__thread_map_swap, |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 803 | [PERF_RECORD_CPU_MAP] = perf_event__cpu_map_swap, |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 804 | [PERF_RECORD_STAT_CONFIG] = perf_event__stat_config_swap, |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 805 | [PERF_RECORD_STAT] = perf_event__stat_swap, |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 806 | [PERF_RECORD_STAT_ROUND] = perf_event__stat_round_swap, |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 807 | [PERF_RECORD_EVENT_UPDATE] = perf_event__event_update_swap, |
Adrian Hunter | 46bc29b | 2016-03-08 10:38:44 +0200 | [diff] [blame] | 808 | [PERF_RECORD_TIME_CONV] = perf_event__all64_swap, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 809 | [PERF_RECORD_HEADER_MAX] = NULL, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 810 | }; |
| 811 | |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 812 | /* |
| 813 | * When perf record finishes a pass on every buffers, it records this pseudo |
| 814 | * event. |
| 815 | * We record the max timestamp t found in the pass n. |
| 816 | * Assuming these timestamps are monotonic across cpus, we know that if |
| 817 | * a buffer still has events with timestamps below t, they will be all |
| 818 | * available and then read in the pass n + 1. |
| 819 | * Hence when we start to read the pass n + 2, we can safely flush every |
| 820 | * events with timestamps below t. |
| 821 | * |
| 822 | * ============ PASS n ================= |
| 823 | * CPU 0 | CPU 1 |
| 824 | * | |
| 825 | * cnt1 timestamps | cnt2 timestamps |
| 826 | * 1 | 2 |
| 827 | * 2 | 3 |
| 828 | * - | 4 <--- max recorded |
| 829 | * |
| 830 | * ============ PASS n + 1 ============== |
| 831 | * CPU 0 | CPU 1 |
| 832 | * | |
| 833 | * cnt1 timestamps | cnt2 timestamps |
| 834 | * 3 | 5 |
| 835 | * 4 | 6 |
| 836 | * 5 | 7 <---- max recorded |
| 837 | * |
| 838 | * Flush every events below timestamp 4 |
| 839 | * |
| 840 | * ============ PASS n + 2 ============== |
| 841 | * CPU 0 | CPU 1 |
| 842 | * | |
| 843 | * cnt1 timestamps | cnt2 timestamps |
| 844 | * 6 | 8 |
| 845 | * 7 | 9 |
| 846 | * - | 10 |
| 847 | * |
| 848 | * Flush every events below timestamp 7 |
| 849 | * etc... |
| 850 | */ |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 851 | static int process_finished_round(struct perf_tool *tool __maybe_unused, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 852 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 853 | struct ordered_events *oe) |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 854 | { |
Adrian Hunter | 5531e16 | 2015-06-23 10:52:48 +0300 | [diff] [blame] | 855 | if (dump_trace) |
| 856 | fprintf(stdout, "\n"); |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 857 | return ordered_events__flush(oe, OE_FLUSH__ROUND); |
Frederic Weisbecker | d6b17be | 2010-05-03 15:14:33 +0200 | [diff] [blame] | 858 | } |
| 859 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 860 | int perf_session__queue_event(struct perf_session *s, union perf_event *event, |
Jiri Olsa | dc83e13 | 2017-08-03 13:24:33 +0200 | [diff] [blame] | 861 | u64 timestamp, u64 file_offset) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 862 | { |
Jiri Olsa | dc83e13 | 2017-08-03 13:24:33 +0200 | [diff] [blame] | 863 | return ordered_events__queue(&s->ordered_events, event, timestamp, file_offset); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 864 | } |
| 865 | |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 866 | static void callchain__lbr_callstack_printf(struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 867 | { |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 868 | struct ip_callchain *callchain = sample->callchain; |
| 869 | struct branch_stack *lbr_stack = sample->branch_stack; |
| 870 | u64 kernel_callchain_nr = callchain->nr; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 871 | unsigned int i; |
| 872 | |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 873 | for (i = 0; i < kernel_callchain_nr; i++) { |
| 874 | if (callchain->ips[i] == PERF_CONTEXT_USER) |
| 875 | break; |
| 876 | } |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 877 | |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 878 | if ((i != kernel_callchain_nr) && lbr_stack->nr) { |
| 879 | u64 total_nr; |
| 880 | /* |
| 881 | * LBR callstack can only get user call chain, |
| 882 | * i is kernel call chain number, |
| 883 | * 1 is PERF_CONTEXT_USER. |
| 884 | * |
| 885 | * The user call chain is stored in LBR registers. |
| 886 | * LBR are pair registers. The caller is stored |
| 887 | * in "from" register, while the callee is stored |
| 888 | * in "to" register. |
| 889 | * For example, there is a call stack |
| 890 | * "A"->"B"->"C"->"D". |
| 891 | * The LBR registers will recorde like |
| 892 | * "C"->"D", "B"->"C", "A"->"B". |
| 893 | * So only the first "to" register and all "from" |
| 894 | * registers are needed to construct the whole stack. |
| 895 | */ |
| 896 | total_nr = i + 1 + lbr_stack->nr + 1; |
| 897 | kernel_callchain_nr = i + 1; |
| 898 | |
| 899 | printf("... LBR call chain: nr:%" PRIu64 "\n", total_nr); |
| 900 | |
| 901 | for (i = 0; i < kernel_callchain_nr; i++) |
| 902 | printf("..... %2d: %016" PRIx64 "\n", |
| 903 | i, callchain->ips[i]); |
| 904 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 905 | printf("..... %2d: %016" PRIx64 "\n", |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 906 | (int)(kernel_callchain_nr), lbr_stack->entries[0].to); |
| 907 | for (i = 0; i < lbr_stack->nr; i++) |
| 908 | printf("..... %2d: %016" PRIx64 "\n", |
| 909 | (int)(i + kernel_callchain_nr + 1), lbr_stack->entries[i].from); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | static void callchain__printf(struct perf_evsel *evsel, |
| 914 | struct perf_sample *sample) |
| 915 | { |
| 916 | unsigned int i; |
| 917 | struct ip_callchain *callchain = sample->callchain; |
| 918 | |
Arnaldo Carvalho de Melo | acf2abb | 2016-04-18 10:35:03 -0300 | [diff] [blame] | 919 | if (perf_evsel__has_branch_callstack(evsel)) |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 920 | callchain__lbr_callstack_printf(sample); |
| 921 | |
| 922 | printf("... FP chain: nr:%" PRIu64 "\n", callchain->nr); |
| 923 | |
| 924 | for (i = 0; i < callchain->nr; i++) |
| 925 | printf("..... %2d: %016" PRIx64 "\n", |
| 926 | i, callchain->ips[i]); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 927 | } |
| 928 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 929 | static void branch_stack__printf(struct perf_sample *sample) |
| 930 | { |
| 931 | uint64_t i; |
| 932 | |
| 933 | printf("... branch stack: nr:%" PRIu64 "\n", sample->branch_stack->nr); |
| 934 | |
Andi Kleen | 0e332f0 | 2015-07-18 08:24:46 -0700 | [diff] [blame] | 935 | for (i = 0; i < sample->branch_stack->nr; i++) { |
| 936 | struct branch_entry *e = &sample->branch_stack->entries[i]; |
| 937 | |
| 938 | printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %s%s%s%s %x\n", |
| 939 | i, e->from, e->to, |
Arnaldo Carvalho de Melo | 8074bf5 | 2017-02-17 12:27:26 -0300 | [diff] [blame] | 940 | (unsigned short)e->flags.cycles, |
Andi Kleen | 0e332f0 | 2015-07-18 08:24:46 -0700 | [diff] [blame] | 941 | e->flags.mispred ? "M" : " ", |
| 942 | e->flags.predicted ? "P" : " ", |
| 943 | e->flags.abort ? "A" : " ", |
| 944 | e->flags.in_tx ? "T" : " ", |
| 945 | (unsigned)e->flags.reserved); |
| 946 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 949 | static void regs_dump__printf(u64 mask, u64 *regs) |
| 950 | { |
| 951 | unsigned rid, i = 0; |
| 952 | |
| 953 | for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) { |
| 954 | u64 val = regs[i++]; |
| 955 | |
| 956 | printf(".... %-5s 0x%" PRIx64 "\n", |
| 957 | perf_reg_name(rid), val); |
| 958 | } |
| 959 | } |
| 960 | |
Stephane Eranian | 6a21c0b | 2014-09-24 13:48:39 +0200 | [diff] [blame] | 961 | static const char *regs_abi[] = { |
| 962 | [PERF_SAMPLE_REGS_ABI_NONE] = "none", |
| 963 | [PERF_SAMPLE_REGS_ABI_32] = "32-bit", |
| 964 | [PERF_SAMPLE_REGS_ABI_64] = "64-bit", |
| 965 | }; |
| 966 | |
| 967 | static inline const char *regs_dump_abi(struct regs_dump *d) |
| 968 | { |
| 969 | if (d->abi > PERF_SAMPLE_REGS_ABI_64) |
| 970 | return "unknown"; |
| 971 | |
| 972 | return regs_abi[d->abi]; |
| 973 | } |
| 974 | |
| 975 | static void regs__printf(const char *type, struct regs_dump *regs) |
| 976 | { |
| 977 | u64 mask = regs->mask; |
| 978 | |
| 979 | printf("... %s regs: mask 0x%" PRIx64 " ABI %s\n", |
| 980 | type, |
| 981 | mask, |
| 982 | regs_dump_abi(regs)); |
| 983 | |
| 984 | regs_dump__printf(mask, regs->regs); |
| 985 | } |
| 986 | |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 987 | static void regs_user__printf(struct perf_sample *sample) |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 988 | { |
| 989 | struct regs_dump *user_regs = &sample->user_regs; |
| 990 | |
Stephane Eranian | 6a21c0b | 2014-09-24 13:48:39 +0200 | [diff] [blame] | 991 | if (user_regs->regs) |
| 992 | regs__printf("user", user_regs); |
| 993 | } |
| 994 | |
| 995 | static void regs_intr__printf(struct perf_sample *sample) |
| 996 | { |
| 997 | struct regs_dump *intr_regs = &sample->intr_regs; |
| 998 | |
| 999 | if (intr_regs->regs) |
| 1000 | regs__printf("intr", intr_regs); |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | static void stack_user__printf(struct stack_dump *dump) |
| 1004 | { |
| 1005 | printf("... ustack: size %" PRIu64 ", offset 0x%x\n", |
| 1006 | dump->size, dump->offset); |
| 1007 | } |
| 1008 | |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1009 | static void perf_evlist__print_tstamp(struct perf_evlist *evlist, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1010 | union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 1011 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 1012 | { |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1013 | u64 sample_type = __perf_evlist__combined_sample_type(evlist); |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1014 | |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 1015 | if (event->header.type != PERF_RECORD_SAMPLE && |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1016 | !perf_evlist__sample_id_all(evlist)) { |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 1017 | fputs("-1 -1 ", stdout); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1021 | if ((sample_type & PERF_SAMPLE_CPU)) |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 1022 | printf("%u ", sample->cpu); |
| 1023 | |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1024 | if (sample_type & PERF_SAMPLE_TIME) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1025 | printf("%" PRIu64 " ", sample->time); |
Arnaldo Carvalho de Melo | 9c90a61 | 2010-12-02 10:25:28 -0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1028 | static void sample_read__printf(struct perf_sample *sample, u64 read_format) |
| 1029 | { |
| 1030 | printf("... sample_read:\n"); |
| 1031 | |
| 1032 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) |
| 1033 | printf("...... time enabled %016" PRIx64 "\n", |
| 1034 | sample->read.time_enabled); |
| 1035 | |
| 1036 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) |
| 1037 | printf("...... time running %016" PRIx64 "\n", |
| 1038 | sample->read.time_running); |
| 1039 | |
| 1040 | if (read_format & PERF_FORMAT_GROUP) { |
| 1041 | u64 i; |
| 1042 | |
| 1043 | printf(".... group nr %" PRIu64 "\n", sample->read.group.nr); |
| 1044 | |
| 1045 | for (i = 0; i < sample->read.group.nr; i++) { |
| 1046 | struct sample_read_value *value; |
| 1047 | |
| 1048 | value = &sample->read.group.values[i]; |
| 1049 | printf("..... id %016" PRIx64 |
| 1050 | ", value %016" PRIx64 "\n", |
| 1051 | value->id, value->value); |
| 1052 | } |
| 1053 | } else |
| 1054 | printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n", |
| 1055 | sample->read.one.id, sample->read.one.value); |
| 1056 | } |
| 1057 | |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1058 | static void dump_event(struct perf_evlist *evlist, union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 1059 | u64 file_offset, struct perf_sample *sample) |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1060 | { |
| 1061 | if (!dump_trace) |
| 1062 | return; |
| 1063 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1064 | printf("\n%#" PRIx64 " [%#x]: event: %d\n", |
| 1065 | file_offset, event->header.size, event->header.type); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1066 | |
| 1067 | trace_event(event); |
| 1068 | |
| 1069 | if (sample) |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1070 | perf_evlist__print_tstamp(evlist, event, sample); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1071 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1072 | printf("%#" PRIx64 " [%#x]: PERF_RECORD_%s", file_offset, |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1073 | event->header.size, perf_event__name(event->header.type)); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1076 | static void dump_sample(struct perf_evsel *evsel, union perf_event *event, |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 1077 | struct perf_sample *sample) |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1078 | { |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1079 | u64 sample_type; |
| 1080 | |
Arnaldo Carvalho de Melo | ddbc24b | 2010-12-09 12:20:20 -0200 | [diff] [blame] | 1081 | if (!dump_trace) |
| 1082 | return; |
| 1083 | |
Don Zickus | 0ea590a | 2014-02-25 22:43:46 -0500 | [diff] [blame] | 1084 | printf("(IP, 0x%x): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n", |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1085 | event->header.misc, sample->pid, sample->tid, sample->ip, |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1086 | sample->period, sample->addr); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1087 | |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1088 | sample_type = evsel->attr.sample_type; |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1089 | |
Arnaldo Carvalho de Melo | 27de9b2 | 2018-05-28 16:00:29 -0300 | [diff] [blame] | 1090 | if (evsel__has_callchain(evsel)) |
Kan Liang | 384b605 | 2015-01-05 13:23:05 -0500 | [diff] [blame] | 1091 | callchain__printf(evsel, sample); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1092 | |
Arnaldo Carvalho de Melo | acf2abb | 2016-04-18 10:35:03 -0300 | [diff] [blame] | 1093 | if ((sample_type & PERF_SAMPLE_BRANCH_STACK) && !perf_evsel__has_branch_callstack(evsel)) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1094 | branch_stack__printf(sample); |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1095 | |
| 1096 | if (sample_type & PERF_SAMPLE_REGS_USER) |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1097 | regs_user__printf(sample); |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1098 | |
Stephane Eranian | 6a21c0b | 2014-09-24 13:48:39 +0200 | [diff] [blame] | 1099 | if (sample_type & PERF_SAMPLE_REGS_INTR) |
| 1100 | regs_intr__printf(sample); |
| 1101 | |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1102 | if (sample_type & PERF_SAMPLE_STACK_USER) |
| 1103 | stack_user__printf(&sample->user_stack); |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 1104 | |
| 1105 | if (sample_type & PERF_SAMPLE_WEIGHT) |
| 1106 | printf("... weight: %" PRIu64 "\n", sample->weight); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 1107 | |
| 1108 | if (sample_type & PERF_SAMPLE_DATA_SRC) |
| 1109 | printf(" . data_src: 0x%"PRIx64"\n", sample->data_src); |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1110 | |
Kan Liang | 8780fb2 | 2017-08-29 13:11:09 -0400 | [diff] [blame] | 1111 | if (sample_type & PERF_SAMPLE_PHYS_ADDR) |
| 1112 | printf(" .. phys_addr: 0x%"PRIx64"\n", sample->phys_addr); |
| 1113 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1114 | if (sample_type & PERF_SAMPLE_TRANSACTION) |
| 1115 | printf("... transaction: %" PRIx64 "\n", sample->transaction); |
| 1116 | |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1117 | if (sample_type & PERF_SAMPLE_READ) |
| 1118 | sample_read__printf(sample, evsel->attr.read_format); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
Jiri Olsa | dac7f6b | 2017-08-24 18:27:32 +0200 | [diff] [blame] | 1121 | static void dump_read(struct perf_evsel *evsel, union perf_event *event) |
| 1122 | { |
| 1123 | struct read_event *read_event = &event->read; |
| 1124 | u64 read_format; |
| 1125 | |
| 1126 | if (!dump_trace) |
| 1127 | return; |
| 1128 | |
| 1129 | printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, |
| 1130 | evsel ? perf_evsel__name(evsel) : "FAIL", |
| 1131 | event->read.value); |
| 1132 | |
| 1133 | read_format = evsel->attr.read_format; |
| 1134 | |
| 1135 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) |
| 1136 | printf("... time enabled : %" PRIu64 "\n", read_event->time_enabled); |
| 1137 | |
| 1138 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) |
| 1139 | printf("... time running : %" PRIu64 "\n", read_event->time_running); |
| 1140 | |
| 1141 | if (read_format & PERF_FORMAT_ID) |
| 1142 | printf("... id : %" PRIu64 "\n", read_event->id); |
| 1143 | } |
| 1144 | |
Arnaldo Carvalho de Melo | 54245fd | 2015-02-14 14:26:15 -0300 | [diff] [blame] | 1145 | static struct machine *machines__find_for_cpumode(struct machines *machines, |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 1146 | union perf_event *event, |
| 1147 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1148 | { |
Dongsheng Yang | ad85ace | 2013-12-20 13:41:47 -0500 | [diff] [blame] | 1149 | struct machine *machine; |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1150 | |
David Ahern | 7c0f4a4 | 2012-07-20 17:25:48 -0600 | [diff] [blame] | 1151 | if (perf_guest && |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 1152 | ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || |
| 1153 | (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) { |
Nikunj A. Dadhania | 7fb0a5e | 2012-04-09 13:52:23 +0530 | [diff] [blame] | 1154 | u32 pid; |
| 1155 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1156 | if (event->header.type == PERF_RECORD_MMAP |
| 1157 | || event->header.type == PERF_RECORD_MMAP2) |
Nikunj A. Dadhania | 7fb0a5e | 2012-04-09 13:52:23 +0530 | [diff] [blame] | 1158 | pid = event->mmap.pid; |
| 1159 | else |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 1160 | pid = sample->pid; |
Nikunj A. Dadhania | 7fb0a5e | 2012-04-09 13:52:23 +0530 | [diff] [blame] | 1161 | |
Arnaldo Carvalho de Melo | 54245fd | 2015-02-14 14:26:15 -0300 | [diff] [blame] | 1162 | machine = machines__find(machines, pid); |
Dongsheng Yang | ad85ace | 2013-12-20 13:41:47 -0500 | [diff] [blame] | 1163 | if (!machine) |
Ravi Bangoria | 3caeaa5 | 2015-12-07 12:25:02 +0530 | [diff] [blame] | 1164 | machine = machines__findnew(machines, DEFAULT_GUEST_KERNEL_ID); |
Dongsheng Yang | ad85ace | 2013-12-20 13:41:47 -0500 | [diff] [blame] | 1165 | return machine; |
Nikunj A. Dadhania | 7fb0a5e | 2012-04-09 13:52:23 +0530 | [diff] [blame] | 1166 | } |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1167 | |
Arnaldo Carvalho de Melo | 54245fd | 2015-02-14 14:26:15 -0300 | [diff] [blame] | 1168 | return &machines->host; |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1171 | static int deliver_sample_value(struct perf_evlist *evlist, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1172 | struct perf_tool *tool, |
| 1173 | union perf_event *event, |
| 1174 | struct perf_sample *sample, |
| 1175 | struct sample_read_value *v, |
| 1176 | struct machine *machine) |
| 1177 | { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1178 | struct perf_sample_id *sid = perf_evlist__id2sid(evlist, v->id); |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1179 | |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1180 | if (sid) { |
| 1181 | sample->id = v->id; |
| 1182 | sample->period = v->value - sid->period; |
| 1183 | sid->period = v->value; |
| 1184 | } |
| 1185 | |
| 1186 | if (!sid || sid->evsel == NULL) { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1187 | ++evlist->stats.nr_unknown_id; |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | return tool->sample(tool, event, sample, sid->evsel, machine); |
| 1192 | } |
| 1193 | |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1194 | static int deliver_sample_group(struct perf_evlist *evlist, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1195 | struct perf_tool *tool, |
| 1196 | union perf_event *event, |
| 1197 | struct perf_sample *sample, |
| 1198 | struct machine *machine) |
| 1199 | { |
| 1200 | int ret = -EINVAL; |
| 1201 | u64 i; |
| 1202 | |
| 1203 | for (i = 0; i < sample->read.group.nr; i++) { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1204 | ret = deliver_sample_value(evlist, tool, event, sample, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1205 | &sample->read.group.values[i], |
| 1206 | machine); |
| 1207 | if (ret) |
| 1208 | break; |
| 1209 | } |
| 1210 | |
| 1211 | return ret; |
| 1212 | } |
| 1213 | |
| 1214 | static int |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1215 | perf_evlist__deliver_sample(struct perf_evlist *evlist, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1216 | struct perf_tool *tool, |
| 1217 | union perf_event *event, |
| 1218 | struct perf_sample *sample, |
| 1219 | struct perf_evsel *evsel, |
| 1220 | struct machine *machine) |
| 1221 | { |
| 1222 | /* We know evsel != NULL. */ |
| 1223 | u64 sample_type = evsel->attr.sample_type; |
| 1224 | u64 read_format = evsel->attr.read_format; |
| 1225 | |
Soramichi AKIYAMA | d94386f | 2017-01-17 22:22:33 +0900 | [diff] [blame] | 1226 | /* Standard sample delivery. */ |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1227 | if (!(sample_type & PERF_SAMPLE_READ)) |
| 1228 | return tool->sample(tool, event, sample, evsel, machine); |
| 1229 | |
| 1230 | /* For PERF_SAMPLE_READ we have either single or group mode. */ |
| 1231 | if (read_format & PERF_FORMAT_GROUP) |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1232 | return deliver_sample_group(evlist, tool, event, sample, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1233 | machine); |
| 1234 | else |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1235 | return deliver_sample_value(evlist, tool, event, sample, |
Jiri Olsa | e4caec0 | 2012-10-10 18:52:24 +0200 | [diff] [blame] | 1236 | &sample->read.one, machine); |
| 1237 | } |
| 1238 | |
Arnaldo Carvalho de Melo | d10eb1e | 2015-03-03 12:20:38 -0300 | [diff] [blame] | 1239 | static int machines__deliver_event(struct machines *machines, |
| 1240 | struct perf_evlist *evlist, |
| 1241 | union perf_event *event, |
| 1242 | struct perf_sample *sample, |
| 1243 | struct perf_tool *tool, u64 file_offset) |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1244 | { |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1245 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1246 | struct machine *machine; |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1247 | |
Arnaldo Carvalho de Melo | 9fa8727 | 2015-02-14 15:08:51 -0300 | [diff] [blame] | 1248 | dump_event(evlist, event, file_offset, sample); |
Thomas Gleixner | 532e726 | 2010-12-07 12:48:55 +0000 | [diff] [blame] | 1249 | |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1250 | evsel = perf_evlist__id2evsel(evlist, sample->id); |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1251 | |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1252 | machine = machines__find_for_cpumode(machines, event, sample); |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1253 | |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1254 | switch (event->header.type) { |
| 1255 | case PERF_RECORD_SAMPLE: |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1256 | if (evsel == NULL) { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1257 | ++evlist->stats.nr_unknown_id; |
Jiri Olsa | 6782206 | 2012-04-12 14:21:01 +0200 | [diff] [blame] | 1258 | return 0; |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1259 | } |
Kan Liang | 1b29ac5 | 2015-09-03 08:31:00 -0400 | [diff] [blame] | 1260 | dump_sample(evsel, event, sample); |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1261 | if (machine == NULL) { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1262 | ++evlist->stats.nr_unprocessable_samples; |
Jiri Olsa | 6782206 | 2012-04-12 14:21:01 +0200 | [diff] [blame] | 1263 | return 0; |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1264 | } |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1265 | return perf_evlist__deliver_sample(evlist, tool, event, sample, evsel, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1266 | case PERF_RECORD_MMAP: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1267 | return tool->mmap(tool, event, sample, machine); |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1268 | case PERF_RECORD_MMAP2: |
Kan Liang | 930e6fc | 2015-06-17 09:51:10 -0400 | [diff] [blame] | 1269 | if (event->header.misc & PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT) |
| 1270 | ++evlist->stats.nr_proc_map_timeout; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1271 | return tool->mmap2(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1272 | case PERF_RECORD_COMM: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1273 | return tool->comm(tool, event, sample, machine); |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 1274 | case PERF_RECORD_NAMESPACES: |
| 1275 | return tool->namespaces(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1276 | case PERF_RECORD_FORK: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1277 | return tool->fork(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1278 | case PERF_RECORD_EXIT: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1279 | return tool->exit(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1280 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1281 | if (tool->lost == perf_event__process_lost) |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1282 | evlist->stats.total_lost += event->lost.lost; |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1283 | return tool->lost(tool, event, sample, machine); |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 1284 | case PERF_RECORD_LOST_SAMPLES: |
| 1285 | if (tool->lost_samples == perf_event__process_lost_samples) |
| 1286 | evlist->stats.total_lost_samples += event->lost_samples.lost; |
| 1287 | return tool->lost_samples(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1288 | case PERF_RECORD_READ: |
Jiri Olsa | dac7f6b | 2017-08-24 18:27:32 +0200 | [diff] [blame] | 1289 | dump_read(evsel, event); |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1290 | return tool->read(tool, event, sample, evsel, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1291 | case PERF_RECORD_THROTTLE: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1292 | return tool->throttle(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1293 | case PERF_RECORD_UNTHROTTLE: |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1294 | return tool->unthrottle(tool, event, sample, machine); |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 1295 | case PERF_RECORD_AUX: |
Alexander Shishkin | 05a1f47 | 2017-03-16 18:41:59 +0200 | [diff] [blame] | 1296 | if (tool->aux == perf_event__process_aux) { |
| 1297 | if (event->aux.flags & PERF_AUX_FLAG_TRUNCATED) |
| 1298 | evlist->stats.total_aux_lost += 1; |
| 1299 | if (event->aux.flags & PERF_AUX_FLAG_PARTIAL) |
| 1300 | evlist->stats.total_aux_partial += 1; |
| 1301 | } |
Adrian Hunter | 4a96f7a | 2015-04-30 17:37:29 +0300 | [diff] [blame] | 1302 | return tool->aux(tool, event, sample, machine); |
Adrian Hunter | 0ad21f6 | 2015-04-30 17:37:30 +0300 | [diff] [blame] | 1303 | case PERF_RECORD_ITRACE_START: |
| 1304 | return tool->itrace_start(tool, event, sample, machine); |
Adrian Hunter | 0286039 | 2015-07-21 12:44:03 +0300 | [diff] [blame] | 1305 | case PERF_RECORD_SWITCH: |
| 1306 | case PERF_RECORD_SWITCH_CPU_WIDE: |
| 1307 | return tool->context_switch(tool, event, sample, machine); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1308 | default: |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1309 | ++evlist->stats.nr_unknown_events; |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1310 | return -1; |
| 1311 | } |
| 1312 | } |
| 1313 | |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1314 | static int perf_session__deliver_event(struct perf_session *session, |
| 1315 | union perf_event *event, |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1316 | struct perf_tool *tool, |
| 1317 | u64 file_offset) |
| 1318 | { |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1319 | struct perf_sample sample; |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1320 | int ret; |
| 1321 | |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1322 | ret = perf_evlist__parse_sample(session->evlist, event, &sample); |
| 1323 | if (ret) { |
| 1324 | pr_err("Can't parse sample, err = %d\n", ret); |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
| 1328 | ret = auxtrace__process_event(session, event, &sample, tool); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1329 | if (ret < 0) |
| 1330 | return ret; |
| 1331 | if (ret > 0) |
| 1332 | return 0; |
| 1333 | |
| 1334 | return machines__deliver_event(&session->machines, session->evlist, |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1335 | event, &sample, tool, file_offset); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1336 | } |
| 1337 | |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1338 | static s64 perf_session__process_user_event(struct perf_session *session, |
| 1339 | union perf_event *event, |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1340 | u64 file_offset) |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1341 | { |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 1342 | struct ordered_events *oe = &session->ordered_events; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1343 | struct perf_tool *tool = session->tool; |
Arnaldo Carvalho de Melo | f250b09 | 2017-11-23 15:35:04 -0300 | [diff] [blame] | 1344 | struct perf_sample sample = { .time = 0, }; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1345 | int fd = perf_data__fd(session->data); |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 1346 | int err; |
| 1347 | |
Arnaldo Carvalho de Melo | f250b09 | 2017-11-23 15:35:04 -0300 | [diff] [blame] | 1348 | dump_event(session->evlist, event, file_offset, &sample); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1349 | |
| 1350 | /* These events are processed right away */ |
| 1351 | switch (event->header.type) { |
| 1352 | case PERF_RECORD_HEADER_ATTR: |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 1353 | err = tool->attr(tool, event, &session->evlist); |
Adrian Hunter | cfe1c41 | 2014-07-31 09:00:45 +0300 | [diff] [blame] | 1354 | if (err == 0) { |
Arnaldo Carvalho de Melo | 7b56cce | 2012-08-01 19:31:00 -0300 | [diff] [blame] | 1355 | perf_session__set_id_hdr_size(session); |
Adrian Hunter | cfe1c41 | 2014-07-31 09:00:45 +0300 | [diff] [blame] | 1356 | perf_session__set_comm_exec(session); |
| 1357 | } |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 1358 | return err; |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 1359 | case PERF_RECORD_EVENT_UPDATE: |
| 1360 | return tool->event_update(tool, event, &session->evlist); |
Jiri Olsa | f67697b | 2014-02-04 15:37:48 +0100 | [diff] [blame] | 1361 | case PERF_RECORD_HEADER_EVENT_TYPE: |
| 1362 | /* |
| 1363 | * Depreceated, but we need to handle it for sake |
| 1364 | * of old data files create in pipe mode. |
| 1365 | */ |
| 1366 | return 0; |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1367 | case PERF_RECORD_HEADER_TRACING_DATA: |
| 1368 | /* setup for reading amidst mmap */ |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 1369 | lseek(fd, file_offset, SEEK_SET); |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1370 | return tool->tracing_data(session, event); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1371 | case PERF_RECORD_HEADER_BUILD_ID: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1372 | return tool->build_id(session, event); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1373 | case PERF_RECORD_FINISHED_ROUND: |
Arnaldo Carvalho de Melo | d704ebd | 2015-03-03 12:37:54 -0300 | [diff] [blame] | 1374 | return tool->finished_round(tool, event, oe); |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 1375 | case PERF_RECORD_ID_INDEX: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1376 | return tool->id_index(session, event); |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 1377 | case PERF_RECORD_AUXTRACE_INFO: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1378 | return tool->auxtrace_info(session, event); |
Adrian Hunter | a16ac02 | 2015-04-09 18:53:43 +0300 | [diff] [blame] | 1379 | case PERF_RECORD_AUXTRACE: |
| 1380 | /* setup for reading amidst mmap */ |
| 1381 | lseek(fd, file_offset + event->header.size, SEEK_SET); |
Jiri Olsa | 7336555 | 2018-09-13 14:54:04 +0200 | [diff] [blame] | 1382 | return tool->auxtrace(session, event); |
Adrian Hunter | e9bf54d | 2015-04-09 18:53:47 +0300 | [diff] [blame] | 1383 | case PERF_RECORD_AUXTRACE_ERROR: |
Adrian Hunter | 85ed472 | 2015-04-09 18:53:50 +0300 | [diff] [blame] | 1384 | perf_session__auxtrace_error_inc(session, event); |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1385 | return tool->auxtrace_error(session, event); |
Jiri Olsa | 5f3339d | 2015-10-25 15:51:19 +0100 | [diff] [blame] | 1386 | case PERF_RECORD_THREAD_MAP: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1387 | return tool->thread_map(session, event); |
Jiri Olsa | 6640b6c | 2015-10-25 15:51:23 +0100 | [diff] [blame] | 1388 | case PERF_RECORD_CPU_MAP: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1389 | return tool->cpu_map(session, event); |
Jiri Olsa | 374fb9e | 2015-10-25 15:51:27 +0100 | [diff] [blame] | 1390 | case PERF_RECORD_STAT_CONFIG: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1391 | return tool->stat_config(session, event); |
Jiri Olsa | d80518c | 2015-10-25 15:51:30 +0100 | [diff] [blame] | 1392 | case PERF_RECORD_STAT: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1393 | return tool->stat(session, event); |
Jiri Olsa | 2d8f0f1 | 2015-10-25 15:51:33 +0100 | [diff] [blame] | 1394 | case PERF_RECORD_STAT_ROUND: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1395 | return tool->stat_round(session, event); |
Adrian Hunter | 46bc29b | 2016-03-08 10:38:44 +0200 | [diff] [blame] | 1396 | case PERF_RECORD_TIME_CONV: |
| 1397 | session->time_conv = event->time_conv; |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1398 | return tool->time_conv(session, event); |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 1399 | case PERF_RECORD_HEADER_FEATURE: |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 1400 | return tool->feature(session, event); |
Thomas Gleixner | ba74f06 | 2010-12-07 12:49:01 +0000 | [diff] [blame] | 1401 | default: |
| 1402 | return -EINVAL; |
| 1403 | } |
| 1404 | } |
| 1405 | |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 1406 | int perf_session__deliver_synth_event(struct perf_session *session, |
| 1407 | union perf_event *event, |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1408 | struct perf_sample *sample) |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 1409 | { |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1410 | struct perf_evlist *evlist = session->evlist; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1411 | struct perf_tool *tool = session->tool; |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1412 | |
| 1413 | events_stats__inc(&evlist->stats, event->header.type); |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 1414 | |
| 1415 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1416 | return perf_session__process_user_event(session, event, 0); |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 1417 | |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1418 | return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0); |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 1419 | } |
| 1420 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 1421 | static void event_swap(union perf_event *event, bool sample_id_all) |
| 1422 | { |
| 1423 | perf_event__swap_op swap; |
| 1424 | |
| 1425 | swap = perf_event__swap_ops[event->header.type]; |
| 1426 | if (swap) |
| 1427 | swap(event, sample_id_all); |
| 1428 | } |
| 1429 | |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1430 | int perf_session__peek_event(struct perf_session *session, off_t file_offset, |
| 1431 | void *buf, size_t buf_sz, |
| 1432 | union perf_event **event_ptr, |
| 1433 | struct perf_sample *sample) |
| 1434 | { |
| 1435 | union perf_event *event; |
| 1436 | size_t hdr_sz, rest; |
| 1437 | int fd; |
| 1438 | |
| 1439 | if (session->one_mmap && !session->header.needs_swap) { |
| 1440 | event = file_offset - session->one_mmap_offset + |
| 1441 | session->one_mmap_addr; |
| 1442 | goto out_parse_sample; |
| 1443 | } |
| 1444 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1445 | if (perf_data__is_pipe(session->data)) |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1446 | return -1; |
| 1447 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1448 | fd = perf_data__fd(session->data); |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1449 | hdr_sz = sizeof(struct perf_event_header); |
| 1450 | |
| 1451 | if (buf_sz < hdr_sz) |
| 1452 | return -1; |
| 1453 | |
| 1454 | if (lseek(fd, file_offset, SEEK_SET) == (off_t)-1 || |
Adrian Hunter | 554e92e | 2015-05-19 16:05:45 +0300 | [diff] [blame] | 1455 | readn(fd, buf, hdr_sz) != (ssize_t)hdr_sz) |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1456 | return -1; |
| 1457 | |
| 1458 | event = (union perf_event *)buf; |
| 1459 | |
| 1460 | if (session->header.needs_swap) |
| 1461 | perf_event_header__bswap(&event->header); |
| 1462 | |
Adrian Hunter | 554e92e | 2015-05-19 16:05:45 +0300 | [diff] [blame] | 1463 | if (event->header.size < hdr_sz || event->header.size > buf_sz) |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1464 | return -1; |
| 1465 | |
| 1466 | rest = event->header.size - hdr_sz; |
| 1467 | |
Adrian Hunter | 554e92e | 2015-05-19 16:05:45 +0300 | [diff] [blame] | 1468 | if (readn(fd, buf, rest) != (ssize_t)rest) |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 1469 | return -1; |
| 1470 | |
| 1471 | if (session->header.needs_swap) |
| 1472 | event_swap(event, perf_evlist__sample_id_all(session->evlist)); |
| 1473 | |
| 1474 | out_parse_sample: |
| 1475 | |
| 1476 | if (sample && event->header.type < PERF_RECORD_USER_TYPE_START && |
| 1477 | perf_evlist__parse_sample(session->evlist, event, sample)) |
| 1478 | return -1; |
| 1479 | |
| 1480 | *event_ptr = event; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1485 | static s64 perf_session__process_event(struct perf_session *session, |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1486 | union perf_event *event, u64 file_offset) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1487 | { |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1488 | struct perf_evlist *evlist = session->evlist; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1489 | struct perf_tool *tool = session->tool; |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1490 | int ret; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 1491 | |
Jiri Olsa | 268fb20 | 2012-05-30 14:23:43 +0200 | [diff] [blame] | 1492 | if (session->header.needs_swap) |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1493 | event_swap(event, perf_evlist__sample_id_all(evlist)); |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 1494 | |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1495 | if (event->header.type >= PERF_RECORD_HEADER_MAX) |
| 1496 | return -EINVAL; |
Arnaldo Carvalho de Melo | 640c03c | 2010-12-02 14:10:21 -0200 | [diff] [blame] | 1497 | |
Arnaldo Carvalho de Melo | 313e53b | 2015-02-14 15:05:28 -0300 | [diff] [blame] | 1498 | events_stats__inc(&evlist->stats, event->header.type); |
Thomas Gleixner | 9aefcab0 | 2010-12-07 12:48:47 +0000 | [diff] [blame] | 1499 | |
| 1500 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1501 | return perf_session__process_user_event(session, event, file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1502 | |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 1503 | if (tool->ordered_events) { |
Mathieu Poirier | 631e8f0 | 2018-01-10 13:31:52 -0700 | [diff] [blame] | 1504 | u64 timestamp = -1ULL; |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1505 | |
| 1506 | ret = perf_evlist__parse_sample_timestamp(evlist, event, ×tamp); |
Mathieu Poirier | 631e8f0 | 2018-01-10 13:31:52 -0700 | [diff] [blame] | 1507 | if (ret && ret != -1) |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1508 | return ret; |
| 1509 | |
| 1510 | ret = perf_session__queue_event(session, event, timestamp, file_offset); |
Thomas Gleixner | cbf4164 | 2010-12-05 14:32:55 +0100 | [diff] [blame] | 1511 | if (ret != -ETIME) |
| 1512 | return ret; |
| 1513 | } |
| 1514 | |
Jiri Olsa | 93d10af | 2017-08-03 13:21:14 +0200 | [diff] [blame] | 1515 | return perf_session__deliver_event(session, event, tool, file_offset); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1516 | } |
| 1517 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1518 | void perf_event_header__bswap(struct perf_event_header *hdr) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1519 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1520 | hdr->type = bswap_32(hdr->type); |
| 1521 | hdr->misc = bswap_16(hdr->misc); |
| 1522 | hdr->size = bswap_16(hdr->size); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 1525 | struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) |
| 1526 | { |
Adrian Hunter | 1fcb876 | 2014-07-14 13:02:25 +0300 | [diff] [blame] | 1527 | return machine__findnew_thread(&session->machines.host, -1, pid); |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 1528 | } |
| 1529 | |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 1530 | int perf_session__register_idle_thread(struct perf_session *session) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1531 | { |
Adrian Hunter | 1fcb876 | 2014-07-14 13:02:25 +0300 | [diff] [blame] | 1532 | struct thread *thread; |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 1533 | int err = 0; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1534 | |
Adrian Hunter | 1fcb876 | 2014-07-14 13:02:25 +0300 | [diff] [blame] | 1535 | thread = machine__findnew_thread(&session->machines.host, 0, 0); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1536 | if (thread == NULL || thread__set_comm(thread, "swapper", 0)) { |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1537 | pr_err("problem inserting idle task.\n"); |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 1538 | err = -1; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1539 | } |
| 1540 | |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 1541 | if (thread == NULL || thread__set_namespaces(thread, 0, NULL)) { |
| 1542 | pr_err("problem inserting idle task.\n"); |
| 1543 | err = -1; |
| 1544 | } |
| 1545 | |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 1546 | /* machine__findnew_thread() got the thread, so put it */ |
| 1547 | thread__put(thread); |
| 1548 | return err; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1549 | } |
| 1550 | |
Wang Nan | f06149c | 2016-07-14 08:34:46 +0000 | [diff] [blame] | 1551 | static void |
| 1552 | perf_session__warn_order(const struct perf_session *session) |
| 1553 | { |
| 1554 | const struct ordered_events *oe = &session->ordered_events; |
| 1555 | struct perf_evsel *evsel; |
| 1556 | bool should_warn = true; |
| 1557 | |
| 1558 | evlist__for_each_entry(session->evlist, evsel) { |
| 1559 | if (evsel->attr.write_backward) |
| 1560 | should_warn = false; |
| 1561 | } |
| 1562 | |
| 1563 | if (!should_warn) |
| 1564 | return; |
| 1565 | if (oe->nr_unordered_events != 0) |
| 1566 | ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events); |
| 1567 | } |
| 1568 | |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1569 | static void perf_session__warn_about_errors(const struct perf_session *session) |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1570 | { |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1571 | const struct events_stats *stats = &session->evlist->stats; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1572 | |
| 1573 | if (session->tool->lost == perf_event__process_lost && |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1574 | stats->nr_events[PERF_RECORD_LOST] != 0) { |
Arnaldo Carvalho de Melo | 7b27509 | 2011-10-29 12:15:04 -0200 | [diff] [blame] | 1575 | ui__warning("Processed %d events and lost %d chunks!\n\n" |
| 1576 | "Check IO/CPU overload!\n\n", |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1577 | stats->nr_events[0], |
| 1578 | stats->nr_events[PERF_RECORD_LOST]); |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1579 | } |
| 1580 | |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 1581 | if (session->tool->lost_samples == perf_event__process_lost_samples) { |
| 1582 | double drop_rate; |
| 1583 | |
| 1584 | drop_rate = (double)stats->total_lost_samples / |
| 1585 | (double) (stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples); |
| 1586 | if (drop_rate > 0.05) { |
Arnaldo Carvalho de Melo | 41a43da | 2018-04-05 14:34:09 -0300 | [diff] [blame] | 1587 | ui__warning("Processed %" PRIu64 " samples and lost %3.2f%%!\n\n", |
Kan Liang | c4937a9 | 2015-05-10 15:13:15 -0400 | [diff] [blame] | 1588 | stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples, |
| 1589 | drop_rate * 100.0); |
| 1590 | } |
| 1591 | } |
| 1592 | |
Adrian Hunter | a38f48e | 2015-09-25 16:15:37 +0300 | [diff] [blame] | 1593 | if (session->tool->aux == perf_event__process_aux && |
| 1594 | stats->total_aux_lost != 0) { |
| 1595 | ui__warning("AUX data lost %" PRIu64 " times out of %u!\n\n", |
| 1596 | stats->total_aux_lost, |
| 1597 | stats->nr_events[PERF_RECORD_AUX]); |
| 1598 | } |
| 1599 | |
Alexander Shishkin | 05a1f47 | 2017-03-16 18:41:59 +0200 | [diff] [blame] | 1600 | if (session->tool->aux == perf_event__process_aux && |
| 1601 | stats->total_aux_partial != 0) { |
| 1602 | bool vmm_exclusive = false; |
| 1603 | |
| 1604 | (void)sysfs__read_bool("module/kvm_intel/parameters/vmm_exclusive", |
| 1605 | &vmm_exclusive); |
| 1606 | |
| 1607 | ui__warning("AUX data had gaps in it %" PRIu64 " times out of %u!\n\n" |
| 1608 | "Are you running a KVM guest in the background?%s\n\n", |
| 1609 | stats->total_aux_partial, |
| 1610 | stats->nr_events[PERF_RECORD_AUX], |
| 1611 | vmm_exclusive ? |
| 1612 | "\nReloading kvm_intel module with vmm_exclusive=0\n" |
| 1613 | "will reduce the gaps to only guest's timeslices." : |
| 1614 | ""); |
| 1615 | } |
| 1616 | |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1617 | if (stats->nr_unknown_events != 0) { |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1618 | ui__warning("Found %u unknown events!\n\n" |
| 1619 | "Is this an older tool processing a perf.data " |
| 1620 | "file generated by a more recent tool?\n\n" |
| 1621 | "If that is not the case, consider " |
| 1622 | "reporting to linux-kernel@vger.kernel.org.\n\n", |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1623 | stats->nr_unknown_events); |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1624 | } |
| 1625 | |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1626 | if (stats->nr_unknown_id != 0) { |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1627 | ui__warning("%u samples with id not present in the header\n", |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1628 | stats->nr_unknown_id); |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 1629 | } |
| 1630 | |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1631 | if (stats->nr_invalid_chains != 0) { |
Arnaldo Carvalho de Melo | 75be989 | 2015-02-14 14:50:11 -0300 | [diff] [blame] | 1632 | ui__warning("Found invalid callchains!\n\n" |
| 1633 | "%u out of %u events were discarded for this reason.\n\n" |
| 1634 | "Consider reporting to linux-kernel@vger.kernel.org.\n\n", |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1635 | stats->nr_invalid_chains, |
| 1636 | stats->nr_events[PERF_RECORD_SAMPLE]); |
Arnaldo Carvalho de Melo | 75be989 | 2015-02-14 14:50:11 -0300 | [diff] [blame] | 1637 | } |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1638 | |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1639 | if (stats->nr_unprocessable_samples != 0) { |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1640 | ui__warning("%u unprocessable samples recorded.\n" |
| 1641 | "Do you have a KVM guest running and not using 'perf kvm'?\n", |
Arnaldo Carvalho de Melo | ccda068 | 2015-02-14 14:57:13 -0300 | [diff] [blame] | 1642 | stats->nr_unprocessable_samples); |
Joerg Roedel | 0c09571 | 2012-02-10 18:05:04 +0100 | [diff] [blame] | 1643 | } |
Jiri Olsa | f61ff6c | 2014-11-26 16:39:31 +0100 | [diff] [blame] | 1644 | |
Wang Nan | f06149c | 2016-07-14 08:34:46 +0000 | [diff] [blame] | 1645 | perf_session__warn_order(session); |
Adrian Hunter | 85ed472 | 2015-04-09 18:53:50 +0300 | [diff] [blame] | 1646 | |
| 1647 | events_stats__auxtrace_error_warn(stats); |
Kan Liang | 930e6fc | 2015-06-17 09:51:10 -0400 | [diff] [blame] | 1648 | |
| 1649 | if (stats->nr_proc_map_timeout != 0) { |
| 1650 | ui__warning("%d map information files for pre-existing threads were\n" |
| 1651 | "not processed, if there are samples for addresses they\n" |
| 1652 | "will not be resolved, you may find out which are these\n" |
| 1653 | "threads by running with -v and redirecting the output\n" |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 1654 | "to a file.\n" |
| 1655 | "The time limit to process proc map is too short?\n" |
| 1656 | "Increase it by --proc-map-timeout\n", |
Kan Liang | 930e6fc | 2015-06-17 09:51:10 -0400 | [diff] [blame] | 1657 | stats->nr_proc_map_timeout); |
| 1658 | } |
Arnaldo Carvalho de Melo | 1109599 | 2011-01-04 16:25:15 -0200 | [diff] [blame] | 1659 | } |
| 1660 | |
Adrian Hunter | a5499b3 | 2015-05-29 16:33:30 +0300 | [diff] [blame] | 1661 | static int perf_session__flush_thread_stack(struct thread *thread, |
| 1662 | void *p __maybe_unused) |
| 1663 | { |
| 1664 | return thread_stack__flush(thread); |
| 1665 | } |
| 1666 | |
| 1667 | static int perf_session__flush_thread_stacks(struct perf_session *session) |
| 1668 | { |
| 1669 | return machines__for_each_thread(&session->machines, |
| 1670 | perf_session__flush_thread_stack, |
| 1671 | NULL); |
| 1672 | } |
| 1673 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1674 | volatile int session_done; |
| 1675 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1676 | static int __perf_session__process_pipe_events(struct perf_session *session) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1677 | { |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1678 | struct ordered_events *oe = &session->ordered_events; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1679 | struct perf_tool *tool = session->tool; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1680 | int fd = perf_data__fd(session->data); |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1681 | union perf_event *event; |
| 1682 | uint32_t size, cur_size = 0; |
| 1683 | void *buf = NULL; |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1684 | s64 skip = 0; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1685 | u64 head; |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 1686 | ssize_t err; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1687 | void *p; |
| 1688 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1689 | perf_tool__fill_defaults(tool); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1690 | |
| 1691 | head = 0; |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1692 | cur_size = sizeof(union perf_event); |
| 1693 | |
| 1694 | buf = malloc(cur_size); |
| 1695 | if (!buf) |
| 1696 | return -errno; |
David Carrillo-Cisneros | 1e0d4f0 | 2017-04-10 13:14:27 -0700 | [diff] [blame] | 1697 | ordered_events__set_copy_on_queue(oe, true); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1698 | more: |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1699 | event = buf; |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 1700 | err = readn(fd, event, sizeof(struct perf_event_header)); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1701 | if (err <= 0) { |
| 1702 | if (err == 0) |
| 1703 | goto done; |
| 1704 | |
| 1705 | pr_err("failed to read event header\n"); |
| 1706 | goto out_err; |
| 1707 | } |
| 1708 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1709 | if (session->header.needs_swap) |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1710 | perf_event_header__bswap(&event->header); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1711 | |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1712 | size = event->header.size; |
Adrian Hunter | 27389d7 | 2013-07-04 16:20:27 +0300 | [diff] [blame] | 1713 | if (size < sizeof(struct perf_event_header)) { |
| 1714 | pr_err("bad event header size\n"); |
| 1715 | goto out_err; |
| 1716 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1717 | |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1718 | if (size > cur_size) { |
| 1719 | void *new = realloc(buf, size); |
| 1720 | if (!new) { |
| 1721 | pr_err("failed to allocate memory to read event\n"); |
| 1722 | goto out_err; |
| 1723 | } |
| 1724 | buf = new; |
| 1725 | cur_size = size; |
| 1726 | event = buf; |
| 1727 | } |
| 1728 | p = event; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1729 | p += sizeof(struct perf_event_header); |
| 1730 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1731 | if (size - sizeof(struct perf_event_header)) { |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 1732 | err = readn(fd, p, size - sizeof(struct perf_event_header)); |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1733 | if (err <= 0) { |
| 1734 | if (err == 0) { |
| 1735 | pr_err("unexpected end of event stream\n"); |
| 1736 | goto done; |
| 1737 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1738 | |
Tom Zanussi | 794e43b | 2010-05-05 00:27:40 -0500 | [diff] [blame] | 1739 | pr_err("failed to read event data\n"); |
| 1740 | goto out_err; |
| 1741 | } |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1742 | } |
| 1743 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1744 | if ((skip = perf_session__process_event(session, event, head)) < 0) { |
Jiri Olsa | 9389a46 | 2012-04-16 20:42:51 +0200 | [diff] [blame] | 1745 | pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n", |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1746 | head, event->header.size, event->header.type); |
Jiri Olsa | 9389a46 | 2012-04-16 20:42:51 +0200 | [diff] [blame] | 1747 | err = -EINVAL; |
| 1748 | goto out_err; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | head += size; |
| 1752 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1753 | if (skip > 0) |
| 1754 | head += skip; |
| 1755 | |
| 1756 | if (!session_done()) |
| 1757 | goto more; |
| 1758 | done: |
Adrian Hunter | 8c16b64 | 2013-10-18 15:29:02 +0300 | [diff] [blame] | 1759 | /* do the final flush for ordered samples */ |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1760 | err = ordered_events__flush(oe, OE_FLUSH__FINAL); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1761 | if (err) |
| 1762 | goto out_err; |
| 1763 | err = auxtrace__flush_events(session, tool); |
Adrian Hunter | a5499b3 | 2015-05-29 16:33:30 +0300 | [diff] [blame] | 1764 | if (err) |
| 1765 | goto out_err; |
| 1766 | err = perf_session__flush_thread_stacks(session); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1767 | out_err: |
Stephane Eranian | 444d286 | 2012-05-15 13:28:12 +0200 | [diff] [blame] | 1768 | free(buf); |
Jiri Olsa | 075ca1e | 2018-01-07 17:03:54 +0100 | [diff] [blame] | 1769 | if (!tool->no_warn) |
| 1770 | perf_session__warn_about_errors(session); |
Jiri Olsa | adc56ed | 2014-06-10 22:50:03 +0200 | [diff] [blame] | 1771 | ordered_events__free(&session->ordered_events); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1772 | auxtrace__free_events(session); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1773 | return err; |
| 1774 | } |
| 1775 | |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1776 | static union perf_event * |
| 1777 | fetch_mmaped_event(struct perf_session *session, |
| 1778 | u64 head, size_t mmap_size, char *buf) |
| 1779 | { |
| 1780 | union perf_event *event; |
| 1781 | |
| 1782 | /* |
| 1783 | * Ensure we have enough space remaining to read |
| 1784 | * the size of the event in the headers. |
| 1785 | */ |
| 1786 | if (head + sizeof(event->header) > mmap_size) |
| 1787 | return NULL; |
| 1788 | |
| 1789 | event = (union perf_event *)(buf + head); |
| 1790 | |
| 1791 | if (session->header.needs_swap) |
| 1792 | perf_event_header__bswap(&event->header); |
| 1793 | |
Adrian Hunter | 27389d7 | 2013-07-04 16:20:27 +0300 | [diff] [blame] | 1794 | if (head + event->header.size > mmap_size) { |
| 1795 | /* We're not fetching the event so swap back again */ |
| 1796 | if (session->header.needs_swap) |
| 1797 | perf_event_header__bswap(&event->header); |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1798 | return NULL; |
Adrian Hunter | 27389d7 | 2013-07-04 16:20:27 +0300 | [diff] [blame] | 1799 | } |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1800 | |
| 1801 | return event; |
| 1802 | } |
| 1803 | |
David Miller | 35d48dd | 2012-11-10 14:12:19 -0500 | [diff] [blame] | 1804 | /* |
| 1805 | * On 64bit we can mmap the data file in one go. No need for tiny mmap |
| 1806 | * slices. On 32bit we use 32MB. |
| 1807 | */ |
| 1808 | #if BITS_PER_LONG == 64 |
| 1809 | #define MMAP_SIZE ULLONG_MAX |
| 1810 | #define NUM_MMAPS 1 |
| 1811 | #else |
| 1812 | #define MMAP_SIZE (32 * 1024 * 1024ULL) |
| 1813 | #define NUM_MMAPS 128 |
| 1814 | #endif |
| 1815 | |
Namhyung Kim | 4ac30cf | 2015-01-29 17:06:43 +0900 | [diff] [blame] | 1816 | static int __perf_session__process_events(struct perf_session *session, |
| 1817 | u64 data_offset, u64 data_size, |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1818 | u64 file_size) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1819 | { |
Arnaldo Carvalho de Melo | fa713a4e | 2015-03-03 11:48:12 -0300 | [diff] [blame] | 1820 | struct ordered_events *oe = &session->ordered_events; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 1821 | struct perf_tool *tool = session->tool; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1822 | int fd = perf_data__fd(session->data); |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1823 | u64 head, page_offset, file_offset, file_pos, size; |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1824 | int err, mmap_prot, mmap_flags, map_idx = 0; |
Arnaldo Carvalho de Melo | 0c1fe6b | 2012-10-06 14:57:10 -0300 | [diff] [blame] | 1825 | size_t mmap_size; |
David Miller | 35d48dd | 2012-11-10 14:12:19 -0500 | [diff] [blame] | 1826 | char *buf, *mmaps[NUM_MMAPS]; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 1827 | union perf_event *event; |
Arnaldo Carvalho de Melo | 4d3001f | 2013-10-23 15:40:38 -0300 | [diff] [blame] | 1828 | struct ui_progress prog; |
Adrian Hunter | d5652d8 | 2014-07-23 22:19:58 +0300 | [diff] [blame] | 1829 | s64 skip; |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1830 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 1831 | perf_tool__fill_defaults(tool); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1832 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1833 | page_offset = page_size * (data_offset / page_size); |
| 1834 | file_offset = page_offset; |
| 1835 | head = data_offset - page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1836 | |
Mark Rutland | 381c02f | 2015-09-16 18:18:49 +0100 | [diff] [blame] | 1837 | if (data_size == 0) |
| 1838 | goto out; |
| 1839 | |
| 1840 | if (data_offset + data_size < file_size) |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1841 | file_size = data_offset + data_size; |
| 1842 | |
Jiri Olsa | 8233822 | 2017-09-08 14:05:10 +0200 | [diff] [blame] | 1843 | ui_progress__init_size(&prog, file_size, "Processing events..."); |
Thomas Gleixner | 55b44629 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1844 | |
David Miller | 35d48dd | 2012-11-10 14:12:19 -0500 | [diff] [blame] | 1845 | mmap_size = MMAP_SIZE; |
Adrian Hunter | 919d86d | 2014-07-14 13:02:51 +0300 | [diff] [blame] | 1846 | if (mmap_size > file_size) { |
Thomas Gleixner | 55b44629 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1847 | mmap_size = file_size; |
Adrian Hunter | 919d86d | 2014-07-14 13:02:51 +0300 | [diff] [blame] | 1848 | session->one_mmap = true; |
| 1849 | } |
Thomas Gleixner | 55b44629 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1850 | |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1851 | memset(mmaps, 0, sizeof(mmaps)); |
| 1852 | |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1853 | mmap_prot = PROT_READ; |
| 1854 | mmap_flags = MAP_SHARED; |
| 1855 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1856 | if (session->header.needs_swap) { |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 1857 | mmap_prot |= PROT_WRITE; |
| 1858 | mmap_flags = MAP_PRIVATE; |
| 1859 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1860 | remap: |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 1861 | buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, fd, |
Thomas Gleixner | 55b44629 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1862 | file_offset); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1863 | if (buf == MAP_FAILED) { |
| 1864 | pr_err("failed to mmap file\n"); |
| 1865 | err = -errno; |
| 1866 | goto out_err; |
| 1867 | } |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1868 | mmaps[map_idx] = buf; |
| 1869 | map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1); |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1870 | file_pos = file_offset + head; |
Adrian Hunter | 919d86d | 2014-07-14 13:02:51 +0300 | [diff] [blame] | 1871 | if (session->one_mmap) { |
| 1872 | session->one_mmap_addr = buf; |
| 1873 | session->one_mmap_offset = file_offset; |
| 1874 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1875 | |
| 1876 | more: |
Frederic Weisbecker | 998bedc | 2011-05-23 13:06:28 +0200 | [diff] [blame] | 1877 | event = fetch_mmaped_event(session, head, mmap_size, buf); |
| 1878 | if (!event) { |
Thomas Gleixner | fe17420 | 2010-11-30 17:49:49 +0000 | [diff] [blame] | 1879 | if (mmaps[map_idx]) { |
| 1880 | munmap(mmaps[map_idx], mmap_size); |
| 1881 | mmaps[map_idx] = NULL; |
| 1882 | } |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1883 | |
Thomas Gleixner | 0331ee0 | 2010-11-30 17:49:38 +0000 | [diff] [blame] | 1884 | page_offset = page_size * (head / page_size); |
| 1885 | file_offset += page_offset; |
| 1886 | head -= page_offset; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1887 | goto remap; |
| 1888 | } |
| 1889 | |
| 1890 | size = event->header.size; |
| 1891 | |
Adrian Hunter | 27389d7 | 2013-07-04 16:20:27 +0300 | [diff] [blame] | 1892 | if (size < sizeof(struct perf_event_header) || |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1893 | (skip = perf_session__process_event(session, event, file_pos)) < 0) { |
Jiri Olsa | 9389a46 | 2012-04-16 20:42:51 +0200 | [diff] [blame] | 1894 | pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n", |
| 1895 | file_offset + head, event->header.size, |
| 1896 | event->header.type); |
| 1897 | err = -EINVAL; |
| 1898 | goto out_err; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Adrian Hunter | 6f917c7 | 2014-07-23 22:19:57 +0300 | [diff] [blame] | 1901 | if (skip) |
| 1902 | size += skip; |
| 1903 | |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1904 | head += size; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1905 | file_pos += size; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1906 | |
Arnaldo Carvalho de Melo | 4d3001f | 2013-10-23 15:40:38 -0300 | [diff] [blame] | 1907 | ui_progress__update(&prog, size); |
Thomas Gleixner | 55b44629 | 2010-11-30 17:49:46 +0000 | [diff] [blame] | 1908 | |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 1909 | if (session_done()) |
Adrian Hunter | 8c16b64 | 2013-10-18 15:29:02 +0300 | [diff] [blame] | 1910 | goto out; |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 1911 | |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1912 | if (file_pos < file_size) |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1913 | goto more; |
Thomas Gleixner | d651328 | 2010-11-30 17:49:44 +0000 | [diff] [blame] | 1914 | |
Adrian Hunter | 8c16b64 | 2013-10-18 15:29:02 +0300 | [diff] [blame] | 1915 | out: |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 1916 | /* do the final flush for ordered samples */ |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1917 | err = ordered_events__flush(oe, OE_FLUSH__FINAL); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1918 | if (err) |
| 1919 | goto out_err; |
| 1920 | err = auxtrace__flush_events(session, tool); |
Adrian Hunter | a5499b3 | 2015-05-29 16:33:30 +0300 | [diff] [blame] | 1921 | if (err) |
| 1922 | goto out_err; |
| 1923 | err = perf_session__flush_thread_stacks(session); |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1924 | out_err: |
Namhyung Kim | a5580f3 | 2012-11-13 22:30:34 +0900 | [diff] [blame] | 1925 | ui_progress__finish(); |
Jiri Olsa | 075ca1e | 2018-01-07 17:03:54 +0100 | [diff] [blame] | 1926 | if (!tool->no_warn) |
| 1927 | perf_session__warn_about_errors(session); |
Wang Nan | b26dc73 | 2016-04-13 08:21:04 +0000 | [diff] [blame] | 1928 | /* |
| 1929 | * We may switching perf.data output, make ordered_events |
| 1930 | * reusable. |
| 1931 | */ |
| 1932 | ordered_events__reinit(&session->ordered_events); |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 1933 | auxtrace__free_events(session); |
Adrian Hunter | 919d86d | 2014-07-14 13:02:51 +0300 | [diff] [blame] | 1934 | session->one_mmap = false; |
Arnaldo Carvalho de Melo | 06aae590 | 2009-12-27 21:36:59 -0200 | [diff] [blame] | 1935 | return err; |
| 1936 | } |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1937 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1938 | int perf_session__process_events(struct perf_session *session) |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1939 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1940 | u64 size = perf_data__size(session->data); |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1941 | int err; |
| 1942 | |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 1943 | if (perf_session__register_idle_thread(session) < 0) |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1944 | return -ENOMEM; |
| 1945 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 1946 | if (!perf_data__is_pipe(session->data)) |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1947 | err = __perf_session__process_events(session, |
| 1948 | session->header.data_offset, |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1949 | session->header.data_size, size); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 1950 | else |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 1951 | err = __perf_session__process_pipe_events(session); |
Dave Martin | 88ca895 | 2010-07-27 11:46:12 -0300 | [diff] [blame] | 1952 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1953 | return err; |
| 1954 | } |
| 1955 | |
Arnaldo Carvalho de Melo | 7f3be65 | 2012-08-01 19:15:52 -0300 | [diff] [blame] | 1956 | bool perf_session__has_traces(struct perf_session *session, const char *msg) |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1957 | { |
David Ahern | 93ea01c29 | 2013-08-07 22:50:58 -0400 | [diff] [blame] | 1958 | struct perf_evsel *evsel; |
| 1959 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1960 | evlist__for_each_entry(session->evlist, evsel) { |
David Ahern | 93ea01c29 | 2013-08-07 22:50:58 -0400 | [diff] [blame] | 1961 | if (evsel->attr.type == PERF_TYPE_TRACEPOINT) |
| 1962 | return true; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1963 | } |
| 1964 | |
David Ahern | 93ea01c29 | 2013-08-07 22:50:58 -0400 | [diff] [blame] | 1965 | pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); |
| 1966 | return false; |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 1967 | } |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1968 | |
Arnaldo Carvalho de Melo | 3183f8c | 2018-04-26 16:52:34 -0300 | [diff] [blame] | 1969 | int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u64 addr) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1970 | { |
| 1971 | char *bracket; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1972 | struct ref_reloc_sym *ref; |
Arnaldo Carvalho de Melo | 3183f8c | 2018-04-26 16:52:34 -0300 | [diff] [blame] | 1973 | struct kmap *kmap; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1974 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1975 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
| 1976 | if (ref == NULL) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1977 | return -ENOMEM; |
| 1978 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1979 | ref->name = strdup(symbol_name); |
| 1980 | if (ref->name == NULL) { |
| 1981 | free(ref); |
| 1982 | return -ENOMEM; |
| 1983 | } |
| 1984 | |
| 1985 | bracket = strchr(ref->name, ']'); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1986 | if (bracket) |
| 1987 | *bracket = '\0'; |
| 1988 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1989 | ref->addr = addr; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1990 | |
Arnaldo Carvalho de Melo | 3183f8c | 2018-04-26 16:52:34 -0300 | [diff] [blame] | 1991 | kmap = map__kmap(map); |
| 1992 | if (kmap) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1993 | kmap->ref_reloc_sym = ref; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1994 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1995 | return 0; |
| 1996 | } |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1997 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 1998 | size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp) |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1999 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 2000 | return machines__fprintf_dsos(&session->machines, fp); |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 2001 | } |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 2002 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 2003 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp, |
Arnaldo Carvalho de Melo | 417c2ff | 2012-12-07 09:53:58 -0300 | [diff] [blame] | 2004 | bool (skip)(struct dso *dso, int parm), int parm) |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 2005 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 2006 | return machines__fprintf_dsos_buildid(&session->machines, fp, skip, parm); |
Arnaldo Carvalho de Melo | f869097 | 2010-05-19 13:41:23 -0300 | [diff] [blame] | 2007 | } |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 2008 | |
| 2009 | size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) |
| 2010 | { |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 2011 | size_t ret; |
| 2012 | const char *msg = ""; |
| 2013 | |
| 2014 | if (perf_header__has_feat(&session->header, HEADER_AUXTRACE)) |
| 2015 | msg = " (excludes AUX area (e.g. instruction trace) decoded / synthesized events)"; |
| 2016 | |
Adrian Hunter | fe692ac | 2015-06-23 10:52:49 +0300 | [diff] [blame] | 2017 | ret = fprintf(fp, "\nAggregated stats:%s\n", msg); |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 2018 | |
Arnaldo Carvalho de Melo | 75be989 | 2015-02-14 14:50:11 -0300 | [diff] [blame] | 2019 | ret += events_stats__fprintf(&session->evlist->stats, fp); |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 2020 | return ret; |
| 2021 | } |
David Ahern | c0230b2 | 2011-03-09 22:23:27 -0700 | [diff] [blame] | 2022 | |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 2023 | size_t perf_session__fprintf(struct perf_session *session, FILE *fp) |
| 2024 | { |
| 2025 | /* |
| 2026 | * FIXME: Here we have to actually print all the machines in this |
| 2027 | * session, not just the host... |
| 2028 | */ |
Arnaldo Carvalho de Melo | 876650e6 | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 2029 | return machine__fprintf(&session->machines.host, fp); |
Arnaldo Carvalho de Melo | b424eba | 2011-11-09 13:24:25 -0200 | [diff] [blame] | 2030 | } |
| 2031 | |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 2032 | struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, |
| 2033 | unsigned int type) |
| 2034 | { |
| 2035 | struct perf_evsel *pos; |
| 2036 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2037 | evlist__for_each_entry(session->evlist, pos) { |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 2038 | if (pos->attr.type == type) |
| 2039 | return pos; |
| 2040 | } |
| 2041 | return NULL; |
| 2042 | } |
| 2043 | |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2044 | int perf_session__cpu_bitmap(struct perf_session *session, |
| 2045 | const char *cpu_list, unsigned long *cpu_bitmap) |
| 2046 | { |
Stanislav Fomichev | 8bac41c | 2014-01-20 15:39:39 +0400 | [diff] [blame] | 2047 | int i, err = -1; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2048 | struct cpu_map *map; |
| 2049 | |
| 2050 | for (i = 0; i < PERF_TYPE_MAX; ++i) { |
| 2051 | struct perf_evsel *evsel; |
| 2052 | |
| 2053 | evsel = perf_session__find_first_evtype(session, i); |
| 2054 | if (!evsel) |
| 2055 | continue; |
| 2056 | |
| 2057 | if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) { |
| 2058 | pr_err("File does not contain CPU events. " |
Adrian Hunter | 3079546 | 2017-05-26 11:17:19 +0300 | [diff] [blame] | 2059 | "Remove -C option to proceed.\n"); |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2060 | return -1; |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | map = cpu_map__new(cpu_list); |
David Ahern | 47fbe53 | 2011-11-13 10:45:27 -0700 | [diff] [blame] | 2065 | if (map == NULL) { |
| 2066 | pr_err("Invalid cpu_list\n"); |
| 2067 | return -1; |
| 2068 | } |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2069 | |
| 2070 | for (i = 0; i < map->nr; i++) { |
| 2071 | int cpu = map->map[i]; |
| 2072 | |
| 2073 | if (cpu >= MAX_NR_CPUS) { |
| 2074 | pr_err("Requested CPU %d too large. " |
| 2075 | "Consider raising MAX_NR_CPUS\n", cpu); |
Stanislav Fomichev | 8bac41c | 2014-01-20 15:39:39 +0400 | [diff] [blame] | 2076 | goto out_delete_map; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | set_bit(cpu, cpu_bitmap); |
| 2080 | } |
| 2081 | |
Stanislav Fomichev | 8bac41c | 2014-01-20 15:39:39 +0400 | [diff] [blame] | 2082 | err = 0; |
| 2083 | |
| 2084 | out_delete_map: |
Jiri Olsa | f30a79b | 2015-06-23 00:36:04 +0200 | [diff] [blame] | 2085 | cpu_map__put(map); |
Stanislav Fomichev | 8bac41c | 2014-01-20 15:39:39 +0400 | [diff] [blame] | 2086 | return err; |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 2087 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2088 | |
| 2089 | void perf_session__fprintf_info(struct perf_session *session, FILE *fp, |
| 2090 | bool full) |
| 2091 | { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2092 | if (session == NULL || fp == NULL) |
| 2093 | return; |
| 2094 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2095 | fprintf(fp, "# ========\n"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2096 | perf_header__fprintf_info(session, fp, full); |
| 2097 | fprintf(fp, "# ========\n#\n"); |
| 2098 | } |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2099 | |
| 2100 | |
| 2101 | int __perf_session__set_tracepoints_handlers(struct perf_session *session, |
| 2102 | const struct perf_evsel_str_handler *assocs, |
| 2103 | size_t nr_assocs) |
| 2104 | { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2105 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2106 | size_t i; |
| 2107 | int err; |
| 2108 | |
| 2109 | for (i = 0; i < nr_assocs; i++) { |
Arnaldo Carvalho de Melo | ccf53ea | 2013-09-06 15:19:01 -0300 | [diff] [blame] | 2110 | /* |
| 2111 | * Adding a handler for an event not in the session, |
| 2112 | * just ignore it. |
| 2113 | */ |
| 2114 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, assocs[i].name); |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2115 | if (evsel == NULL) |
Arnaldo Carvalho de Melo | ccf53ea | 2013-09-06 15:19:01 -0300 | [diff] [blame] | 2116 | continue; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2117 | |
| 2118 | err = -EEXIST; |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2119 | if (evsel->handler != NULL) |
Arnaldo Carvalho de Melo | ccf53ea | 2013-09-06 15:19:01 -0300 | [diff] [blame] | 2120 | goto out; |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2121 | evsel->handler = assocs[i].handler; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | err = 0; |
| 2125 | out: |
| 2126 | return err; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 2127 | } |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 2128 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 2129 | int perf_event__process_id_index(struct perf_session *session, |
| 2130 | union perf_event *event) |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 2131 | { |
| 2132 | struct perf_evlist *evlist = session->evlist; |
| 2133 | struct id_index_event *ie = &event->id_index; |
| 2134 | size_t i, nr, max_nr; |
| 2135 | |
| 2136 | max_nr = (ie->header.size - sizeof(struct id_index_event)) / |
| 2137 | sizeof(struct id_index_entry); |
| 2138 | nr = ie->nr; |
| 2139 | if (nr > max_nr) |
| 2140 | return -EINVAL; |
| 2141 | |
| 2142 | if (dump_trace) |
| 2143 | fprintf(stdout, " nr: %zu\n", nr); |
| 2144 | |
| 2145 | for (i = 0; i < nr; i++) { |
| 2146 | struct id_index_entry *e = &ie->entries[i]; |
| 2147 | struct perf_sample_id *sid; |
| 2148 | |
| 2149 | if (dump_trace) { |
| 2150 | fprintf(stdout, " ... id: %"PRIu64, e->id); |
| 2151 | fprintf(stdout, " idx: %"PRIu64, e->idx); |
| 2152 | fprintf(stdout, " cpu: %"PRId64, e->cpu); |
| 2153 | fprintf(stdout, " tid: %"PRId64"\n", e->tid); |
| 2154 | } |
| 2155 | |
| 2156 | sid = perf_evlist__id2sid(evlist, e->id); |
| 2157 | if (!sid) |
| 2158 | return -ENOENT; |
| 2159 | sid->idx = e->idx; |
| 2160 | sid->cpu = e->cpu; |
| 2161 | sid->tid = e->tid; |
| 2162 | } |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | int perf_event__synthesize_id_index(struct perf_tool *tool, |
| 2167 | perf_event__handler_t process, |
| 2168 | struct perf_evlist *evlist, |
| 2169 | struct machine *machine) |
| 2170 | { |
| 2171 | union perf_event *ev; |
| 2172 | struct perf_evsel *evsel; |
| 2173 | size_t nr = 0, i = 0, sz, max_nr, n; |
| 2174 | int err; |
| 2175 | |
| 2176 | pr_debug2("Synthesizing id index\n"); |
| 2177 | |
| 2178 | max_nr = (UINT16_MAX - sizeof(struct id_index_event)) / |
| 2179 | sizeof(struct id_index_entry); |
| 2180 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2181 | evlist__for_each_entry(evlist, evsel) |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 2182 | nr += evsel->ids; |
| 2183 | |
| 2184 | n = nr > max_nr ? max_nr : nr; |
| 2185 | sz = sizeof(struct id_index_event) + n * sizeof(struct id_index_entry); |
| 2186 | ev = zalloc(sz); |
| 2187 | if (!ev) |
| 2188 | return -ENOMEM; |
| 2189 | |
| 2190 | ev->id_index.header.type = PERF_RECORD_ID_INDEX; |
| 2191 | ev->id_index.header.size = sz; |
| 2192 | ev->id_index.nr = n; |
| 2193 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2194 | evlist__for_each_entry(evlist, evsel) { |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 2195 | u32 j; |
| 2196 | |
| 2197 | for (j = 0; j < evsel->ids; j++) { |
| 2198 | struct id_index_entry *e; |
| 2199 | struct perf_sample_id *sid; |
| 2200 | |
| 2201 | if (i >= n) { |
| 2202 | err = process(tool, ev, NULL, machine); |
| 2203 | if (err) |
| 2204 | goto out_err; |
| 2205 | nr -= n; |
| 2206 | i = 0; |
| 2207 | } |
| 2208 | |
| 2209 | e = &ev->id_index.entries[i++]; |
| 2210 | |
| 2211 | e->id = evsel->id[j]; |
| 2212 | |
| 2213 | sid = perf_evlist__id2sid(evlist, e->id); |
| 2214 | if (!sid) { |
| 2215 | free(ev); |
| 2216 | return -ENOENT; |
| 2217 | } |
| 2218 | |
| 2219 | e->idx = sid->idx; |
| 2220 | e->cpu = sid->cpu; |
| 2221 | e->tid = sid->tid; |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | sz = sizeof(struct id_index_event) + nr * sizeof(struct id_index_entry); |
| 2226 | ev->id_index.header.size = sz; |
| 2227 | ev->id_index.nr = nr; |
| 2228 | |
| 2229 | err = process(tool, ev, NULL, machine); |
| 2230 | out_err: |
| 2231 | free(ev); |
| 2232 | |
| 2233 | return err; |
| 2234 | } |