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