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