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