Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 2 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 3 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 4 | #include "string2.h" |
Arnaldo Carvalho de Melo | 391e420 | 2017-04-19 18:51:14 -0300 | [diff] [blame] | 5 | #include <sys/param.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 6 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 7 | #include <byteswap.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 8 | #include <unistd.h> |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | 0353631 | 2017-06-16 12:18:27 -0300 | [diff] [blame] | 11 | #include <linux/compiler.h> |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 12 | #include <linux/list.h> |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Arnaldo Carvalho de Melo | fc6a172 | 2019-06-25 21:33:14 -0300 | [diff] [blame] | 15 | #include <linux/string.h> |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 16 | #include <linux/stringify.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 17 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | 7a8ef4c | 2017-04-19 20:57:47 -0300 | [diff] [blame] | 18 | #include <sys/stat.h> |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 19 | #include <sys/utsname.h> |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 20 | #include <linux/time64.h> |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 21 | #include <dirent.h> |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 22 | #include <bpf/libbpf.h> |
Jiri Olsa | 9c3516d | 2019-07-21 13:24:30 +0200 | [diff] [blame] | 23 | #include <perf/cpumap.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 24 | |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 25 | #include "dso.h" |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 26 | #include "evlist.h" |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 27 | #include "evsel.h" |
Arnaldo Carvalho de Melo | ca12527 | 2019-09-24 15:41:51 -0300 | [diff] [blame] | 28 | #include "util/evsel_fprintf.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 29 | #include "header.h" |
Arnaldo Carvalho de Melo | 98521b3 | 2017-04-25 15:45:35 -0300 | [diff] [blame] | 30 | #include "memswap.h" |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 31 | #include "trace-event.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 32 | #include "session.h" |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 33 | #include "symbol.h" |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 34 | #include "debug.h" |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 35 | #include "cpumap.h" |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 36 | #include "pmu.h" |
Jiri Olsa | 7dbf4dc | 2012-09-10 18:50:19 +0200 | [diff] [blame] | 37 | #include "vdso.h" |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 38 | #include "strbuf.h" |
Jiri Olsa | ebb296c | 2012-10-27 23:18:28 +0200 | [diff] [blame] | 39 | #include "build-id.h" |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 40 | #include "data.h" |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 41 | #include <api/fs/fs.h> |
| 42 | #include "asm/bug.h" |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 43 | #include "tool.h" |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 44 | #include "time-utils.h" |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 45 | #include "units.h" |
Jiri Olsa | 20f2be1 | 2019-08-06 15:25:25 +0200 | [diff] [blame] | 46 | #include "util/util.h" // perf_exe() |
Jiri Olsa | 5135d5e | 2019-02-19 10:58:13 +0100 | [diff] [blame] | 47 | #include "cputopo.h" |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 48 | #include "bpf-event.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 49 | |
Arnaldo Carvalho de Melo | 3052ba5 | 2019-06-25 17:27:31 -0300 | [diff] [blame] | 50 | #include <linux/ctype.h> |
Arnaldo Carvalho de Melo | fb71c86c | 2019-09-03 10:56:06 -0300 | [diff] [blame] | 51 | #include <internal/lib.h> |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 52 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 53 | /* |
| 54 | * magic2 = "PERFILE2" |
| 55 | * must be a numerical value to let the endianness |
| 56 | * determine the memory layout. That way we are able |
| 57 | * to detect endianness when reading the perf.data file |
| 58 | * back. |
| 59 | * |
| 60 | * we check for legacy (PERFFILE) format. |
| 61 | */ |
| 62 | static const char *__perf_magic1 = "PERFFILE"; |
| 63 | static const u64 __perf_magic2 = 0x32454c4946524550ULL; |
| 64 | static const u64 __perf_magic2_sw = 0x50455246494c4532ULL; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 65 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 66 | #define PERF_MAGIC __perf_magic2 |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 67 | |
Soramichi AKIYAMA | d25ed5d | 2017-01-17 00:22:37 +0900 | [diff] [blame] | 68 | const char perf_version_string[] = PERF_VERSION; |
| 69 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 70 | struct perf_file_attr { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 71 | struct perf_event_attr attr; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 72 | struct perf_file_section ids; |
| 73 | }; |
| 74 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 75 | void perf_header__set_feat(struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 76 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 77 | set_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 78 | } |
| 79 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 80 | void perf_header__clear_feat(struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | baa2f6c | 2010-11-26 19:39:15 -0200 | [diff] [blame] | 81 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 82 | clear_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | baa2f6c | 2010-11-26 19:39:15 -0200 | [diff] [blame] | 83 | } |
| 84 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 85 | bool perf_header__has_feat(const struct perf_header *header, int feat) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 86 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 87 | return test_bit(feat, header->adds_features); |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 88 | } |
| 89 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 90 | static int __do_write_fd(struct feat_fd *ff, const void *buf, size_t size) |
| 91 | { |
| 92 | ssize_t ret = writen(ff->fd, buf, size); |
| 93 | |
| 94 | if (ret != (ssize_t)size) |
| 95 | return ret < 0 ? (int)ret : -1; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int __do_write_buf(struct feat_fd *ff, const void *buf, size_t size) |
| 100 | { |
| 101 | /* struct perf_event_header::size is u16 */ |
| 102 | const size_t max_size = 0xffff - sizeof(struct perf_event_header); |
| 103 | size_t new_size = ff->size; |
| 104 | void *addr; |
| 105 | |
| 106 | if (size + ff->offset > max_size) |
| 107 | return -E2BIG; |
| 108 | |
| 109 | while (size > (new_size - ff->offset)) |
| 110 | new_size <<= 1; |
| 111 | new_size = min(max_size, new_size); |
| 112 | |
| 113 | if (ff->size < new_size) { |
| 114 | addr = realloc(ff->buf, new_size); |
| 115 | if (!addr) |
| 116 | return -ENOMEM; |
| 117 | ff->buf = addr; |
| 118 | ff->size = new_size; |
| 119 | } |
| 120 | |
| 121 | memcpy(ff->buf + ff->offset, buf, size); |
| 122 | ff->offset += size; |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
David Carrillo-Cisneros | 2ff5365 | 2017-07-17 21:25:36 -0700 | [diff] [blame] | 127 | /* Return: 0 if succeded, -ERR if failed. */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 128 | int do_write(struct feat_fd *ff, const void *buf, size_t size) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 129 | { |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 130 | if (!ff->buf) |
| 131 | return __do_write_fd(ff, buf, size); |
| 132 | return __do_write_buf(ff, buf, size); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 133 | } |
| 134 | |
David Carrillo-Cisneros | 2ff5365 | 2017-07-17 21:25:36 -0700 | [diff] [blame] | 135 | /* Return: 0 if succeded, -ERR if failed. */ |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 136 | static int do_write_bitmap(struct feat_fd *ff, unsigned long *set, u64 size) |
| 137 | { |
| 138 | u64 *p = (u64 *) set; |
| 139 | int i, ret; |
| 140 | |
| 141 | ret = do_write(ff, &size, sizeof(size)); |
| 142 | if (ret < 0) |
| 143 | return ret; |
| 144 | |
| 145 | for (i = 0; (u64) i < BITS_TO_U64(size); i++) { |
| 146 | ret = do_write(ff, p + i, sizeof(*p)); |
| 147 | if (ret < 0) |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* Return: 0 if succeded, -ERR if failed. */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 155 | int write_padded(struct feat_fd *ff, const void *bf, |
| 156 | size_t count, size_t count_aligned) |
Arnaldo Carvalho de Melo | f92cb24 | 2010-01-04 16:19:28 -0200 | [diff] [blame] | 157 | { |
| 158 | static const char zero_buf[NAME_ALIGN]; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 159 | int err = do_write(ff, bf, count); |
Arnaldo Carvalho de Melo | f92cb24 | 2010-01-04 16:19:28 -0200 | [diff] [blame] | 160 | |
| 161 | if (!err) |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 162 | err = do_write(ff, zero_buf, count_aligned - count); |
Arnaldo Carvalho de Melo | f92cb24 | 2010-01-04 16:19:28 -0200 | [diff] [blame] | 163 | |
| 164 | return err; |
| 165 | } |
| 166 | |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 167 | #define string_size(str) \ |
| 168 | (PERF_ALIGN((strlen(str) + 1), NAME_ALIGN) + sizeof(u32)) |
| 169 | |
David Carrillo-Cisneros | 2ff5365 | 2017-07-17 21:25:36 -0700 | [diff] [blame] | 170 | /* Return: 0 if succeded, -ERR if failed. */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 171 | static int do_write_string(struct feat_fd *ff, const char *str) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 172 | { |
| 173 | u32 len, olen; |
| 174 | int ret; |
| 175 | |
| 176 | olen = strlen(str) + 1; |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 177 | len = PERF_ALIGN(olen, NAME_ALIGN); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 178 | |
| 179 | /* write len, incl. \0 */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 180 | ret = do_write(ff, &len, sizeof(len)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 181 | if (ret < 0) |
| 182 | return ret; |
| 183 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 184 | return write_padded(ff, str, olen, len); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 185 | } |
| 186 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 187 | static int __do_read_fd(struct feat_fd *ff, void *addr, ssize_t size) |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 188 | { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 189 | ssize_t ret = readn(ff->fd, addr, size); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 190 | |
| 191 | if (ret != size) |
| 192 | return ret < 0 ? (int)ret : -1; |
| 193 | return 0; |
| 194 | } |
| 195 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 196 | static int __do_read_buf(struct feat_fd *ff, void *addr, ssize_t size) |
| 197 | { |
| 198 | if (size > (ssize_t)ff->size - ff->offset) |
| 199 | return -1; |
| 200 | |
| 201 | memcpy(addr, ff->buf + ff->offset, size); |
| 202 | ff->offset += size; |
| 203 | |
| 204 | return 0; |
| 205 | |
| 206 | } |
| 207 | |
| 208 | static int __do_read(struct feat_fd *ff, void *addr, ssize_t size) |
| 209 | { |
| 210 | if (!ff->buf) |
| 211 | return __do_read_fd(ff, addr, size); |
| 212 | return __do_read_buf(ff, addr, size); |
| 213 | } |
| 214 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 215 | static int do_read_u32(struct feat_fd *ff, u32 *addr) |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 216 | { |
| 217 | int ret; |
| 218 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 219 | ret = __do_read(ff, addr, sizeof(*addr)); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 220 | if (ret) |
| 221 | return ret; |
| 222 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 223 | if (ff->ph->needs_swap) |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 224 | *addr = bswap_32(*addr); |
| 225 | return 0; |
| 226 | } |
| 227 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 228 | static int do_read_u64(struct feat_fd *ff, u64 *addr) |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 229 | { |
| 230 | int ret; |
| 231 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 232 | ret = __do_read(ff, addr, sizeof(*addr)); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 233 | if (ret) |
| 234 | return ret; |
| 235 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 236 | if (ff->ph->needs_swap) |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 237 | *addr = bswap_64(*addr); |
| 238 | return 0; |
| 239 | } |
| 240 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 241 | static char *do_read_string(struct feat_fd *ff) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 242 | { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 243 | u32 len; |
| 244 | char *buf; |
| 245 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 246 | if (do_read_u32(ff, &len)) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 247 | return NULL; |
| 248 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 249 | buf = malloc(len); |
| 250 | if (!buf) |
| 251 | return NULL; |
| 252 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 253 | if (!__do_read(ff, buf, len)) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 254 | /* |
| 255 | * strings are padded by zeroes |
| 256 | * thus the actual strlen of buf |
| 257 | * may be less than len |
| 258 | */ |
| 259 | return buf; |
| 260 | } |
| 261 | |
| 262 | free(buf); |
| 263 | return NULL; |
| 264 | } |
| 265 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 266 | /* Return: 0 if succeded, -ERR if failed. */ |
| 267 | static int do_read_bitmap(struct feat_fd *ff, unsigned long **pset, u64 *psize) |
| 268 | { |
| 269 | unsigned long *set; |
| 270 | u64 size, *p; |
| 271 | int i, ret; |
| 272 | |
| 273 | ret = do_read_u64(ff, &size); |
| 274 | if (ret) |
| 275 | return ret; |
| 276 | |
| 277 | set = bitmap_alloc(size); |
| 278 | if (!set) |
| 279 | return -ENOMEM; |
| 280 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 281 | p = (u64 *) set; |
| 282 | |
| 283 | for (i = 0; (u64) i < BITS_TO_U64(size); i++) { |
| 284 | ret = do_read_u64(ff, p + i); |
| 285 | if (ret < 0) { |
| 286 | free(set); |
| 287 | return ret; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | *pset = set; |
| 292 | *psize = size; |
| 293 | return 0; |
| 294 | } |
| 295 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 296 | static int write_tracing_data(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 297 | struct evlist *evlist) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 298 | { |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 299 | if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) |
| 300 | return -1; |
| 301 | |
Jiri Olsa | ce9036a | 2019-07-21 13:24:23 +0200 | [diff] [blame] | 302 | return read_tracing_data(ff->fd, &evlist->core.entries); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 303 | } |
| 304 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 305 | static int write_build_id(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 306 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 307 | { |
| 308 | struct perf_session *session; |
| 309 | int err; |
| 310 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 311 | session = container_of(ff->ph, struct perf_session, header); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 312 | |
Robert Richter | e20960c | 2011-12-07 10:02:55 +0100 | [diff] [blame] | 313 | if (!perf_session__read_build_ids(session, true)) |
| 314 | return -1; |
| 315 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 316 | if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) |
| 317 | return -1; |
| 318 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 319 | err = perf_session__write_buildid_table(session, ff); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 320 | if (err < 0) { |
| 321 | pr_debug("failed to write buildid table\n"); |
| 322 | return err; |
| 323 | } |
Namhyung Kim | 73c5d22 | 2014-11-07 22:57:56 +0900 | [diff] [blame] | 324 | perf_session__cache_build_ids(session); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 329 | static int write_hostname(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 330 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 331 | { |
| 332 | struct utsname uts; |
| 333 | int ret; |
| 334 | |
| 335 | ret = uname(&uts); |
| 336 | if (ret < 0) |
| 337 | return -1; |
| 338 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 339 | return do_write_string(ff, uts.nodename); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 340 | } |
| 341 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 342 | static int write_osrelease(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 343 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 344 | { |
| 345 | struct utsname uts; |
| 346 | int ret; |
| 347 | |
| 348 | ret = uname(&uts); |
| 349 | if (ret < 0) |
| 350 | return -1; |
| 351 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 352 | return do_write_string(ff, uts.release); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 353 | } |
| 354 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 355 | static int write_arch(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 356 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 357 | { |
| 358 | struct utsname uts; |
| 359 | int ret; |
| 360 | |
| 361 | ret = uname(&uts); |
| 362 | if (ret < 0) |
| 363 | return -1; |
| 364 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 365 | return do_write_string(ff, uts.machine); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 366 | } |
| 367 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 368 | static int write_version(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 369 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 370 | { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 371 | return do_write_string(ff, perf_version_string); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 372 | } |
| 373 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 374 | static int __write_cpudesc(struct feat_fd *ff, const char *cpuinfo_proc) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 375 | { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 376 | FILE *file; |
| 377 | char *buf = NULL; |
| 378 | char *s, *p; |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 379 | const char *search = cpuinfo_proc; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 380 | size_t len = 0; |
| 381 | int ret = -1; |
| 382 | |
| 383 | if (!search) |
| 384 | return -1; |
| 385 | |
| 386 | file = fopen("/proc/cpuinfo", "r"); |
| 387 | if (!file) |
| 388 | return -1; |
| 389 | |
| 390 | while (getline(&buf, &len, file) > 0) { |
| 391 | ret = strncmp(buf, search, strlen(search)); |
| 392 | if (!ret) |
| 393 | break; |
| 394 | } |
| 395 | |
Wang Nan | ed30775 | 2014-10-16 11:08:29 +0800 | [diff] [blame] | 396 | if (ret) { |
| 397 | ret = -1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 398 | goto done; |
Wang Nan | ed30775 | 2014-10-16 11:08:29 +0800 | [diff] [blame] | 399 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 400 | |
| 401 | s = buf; |
| 402 | |
| 403 | p = strchr(buf, ':'); |
| 404 | if (p && *(p+1) == ' ' && *(p+2)) |
| 405 | s = p + 2; |
| 406 | p = strchr(s, '\n'); |
| 407 | if (p) |
| 408 | *p = '\0'; |
| 409 | |
| 410 | /* squash extra space characters (branding string) */ |
| 411 | p = s; |
| 412 | while (*p) { |
| 413 | if (isspace(*p)) { |
| 414 | char *r = p + 1; |
Arnaldo Carvalho de Melo | fc6a172 | 2019-06-25 21:33:14 -0300 | [diff] [blame] | 415 | char *q = skip_spaces(r); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 416 | *p = ' '; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 417 | if (q != (p+1)) |
| 418 | while ((*r++ = *q++)); |
| 419 | } |
| 420 | p++; |
| 421 | } |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 422 | ret = do_write_string(ff, s); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 423 | done: |
| 424 | free(buf); |
| 425 | fclose(file); |
| 426 | return ret; |
| 427 | } |
| 428 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 429 | static int write_cpudesc(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 430 | struct evlist *evlist __maybe_unused) |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 431 | { |
Arnaldo Carvalho de Melo | a774940 | 2019-08-29 14:40:28 -0300 | [diff] [blame] | 432 | #if defined(__powerpc__) || defined(__hppa__) || defined(__sparc__) |
| 433 | #define CPUINFO_PROC { "cpu", } |
| 434 | #elif defined(__s390__) |
| 435 | #define CPUINFO_PROC { "vendor_id", } |
| 436 | #elif defined(__sh__) |
| 437 | #define CPUINFO_PROC { "cpu type", } |
| 438 | #elif defined(__alpha__) || defined(__mips__) |
| 439 | #define CPUINFO_PROC { "cpu model", } |
| 440 | #elif defined(__arm__) |
| 441 | #define CPUINFO_PROC { "model name", "Processor", } |
| 442 | #elif defined(__arc__) |
| 443 | #define CPUINFO_PROC { "Processor", } |
| 444 | #elif defined(__xtensa__) |
| 445 | #define CPUINFO_PROC { "core ID", } |
| 446 | #else |
| 447 | #define CPUINFO_PROC { "model name", } |
| 448 | #endif |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 449 | const char *cpuinfo_procs[] = CPUINFO_PROC; |
Arnaldo Carvalho de Melo | a774940 | 2019-08-29 14:40:28 -0300 | [diff] [blame] | 450 | #undef CPUINFO_PROC |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 451 | unsigned int i; |
| 452 | |
| 453 | for (i = 0; i < ARRAY_SIZE(cpuinfo_procs); i++) { |
| 454 | int ret; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 455 | ret = __write_cpudesc(ff, cpuinfo_procs[i]); |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 456 | if (ret >= 0) |
| 457 | return ret; |
| 458 | } |
| 459 | return -1; |
| 460 | } |
| 461 | |
| 462 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 463 | static int write_nrcpus(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 464 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 465 | { |
| 466 | long nr; |
| 467 | u32 nrc, nra; |
| 468 | int ret; |
| 469 | |
Jan Stancek | da8a58b | 2017-02-17 12:10:26 +0100 | [diff] [blame] | 470 | nrc = cpu__max_present_cpu(); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 471 | |
| 472 | nr = sysconf(_SC_NPROCESSORS_ONLN); |
| 473 | if (nr < 0) |
| 474 | return -1; |
| 475 | |
| 476 | nra = (u32)(nr & UINT_MAX); |
| 477 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 478 | ret = do_write(ff, &nrc, sizeof(nrc)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 479 | if (ret < 0) |
| 480 | return ret; |
| 481 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 482 | return do_write(ff, &nra, sizeof(nra)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 483 | } |
| 484 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 485 | static int write_event_desc(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 486 | struct evlist *evlist) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 487 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 488 | struct evsel *evsel; |
Namhyung Kim | 74ba9e1 | 2012-09-05 14:02:47 +0900 | [diff] [blame] | 489 | u32 nre, nri, sz; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 490 | int ret; |
| 491 | |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 492 | nre = evlist->core.nr_entries; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * write number of events |
| 496 | */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 497 | ret = do_write(ff, &nre, sizeof(nre)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 498 | if (ret < 0) |
| 499 | return ret; |
| 500 | |
| 501 | /* |
| 502 | * size of perf_event_attr struct |
| 503 | */ |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 504 | sz = (u32)sizeof(evsel->core.attr); |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 505 | ret = do_write(ff, &sz, sizeof(sz)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 506 | if (ret < 0) |
| 507 | return ret; |
| 508 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 509 | evlist__for_each_entry(evlist, evsel) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 510 | ret = do_write(ff, &evsel->core.attr, sz); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 511 | if (ret < 0) |
| 512 | return ret; |
| 513 | /* |
| 514 | * write number of unique id per event |
| 515 | * there is one id per instance of an event |
| 516 | * |
| 517 | * copy into an nri to be independent of the |
| 518 | * type of ids, |
| 519 | */ |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 520 | nri = evsel->core.ids; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 521 | ret = do_write(ff, &nri, sizeof(nri)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 522 | if (ret < 0) |
| 523 | return ret; |
| 524 | |
| 525 | /* |
| 526 | * write event string as passed on cmdline |
| 527 | */ |
Arnaldo Carvalho de Melo | 8ab2e96 | 2020-04-29 16:07:09 -0300 | [diff] [blame] | 528 | ret = do_write_string(ff, evsel__name(evsel)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 529 | if (ret < 0) |
| 530 | return ret; |
| 531 | /* |
| 532 | * write unique ids for this event |
| 533 | */ |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 534 | ret = do_write(ff, evsel->core.id, evsel->core.ids * sizeof(u64)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 535 | if (ret < 0) |
| 536 | return ret; |
| 537 | } |
| 538 | return 0; |
| 539 | } |
| 540 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 541 | static int write_cmdline(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 542 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 543 | { |
Andi Kleen | 94816ad | 2019-02-24 07:37:19 -0800 | [diff] [blame] | 544 | char pbuf[MAXPATHLEN], *buf; |
| 545 | int i, ret, n; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 546 | |
Tommi Rantala | 55f77128 | 2017-03-22 15:06:24 +0200 | [diff] [blame] | 547 | /* actual path to perf binary */ |
Andi Kleen | 94816ad | 2019-02-24 07:37:19 -0800 | [diff] [blame] | 548 | buf = perf_exe(pbuf, MAXPATHLEN); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 549 | |
| 550 | /* account for binary path */ |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 551 | n = perf_env.nr_cmdline + 1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 552 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 553 | ret = do_write(ff, &n, sizeof(n)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 554 | if (ret < 0) |
| 555 | return ret; |
| 556 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 557 | ret = do_write_string(ff, buf); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 558 | if (ret < 0) |
| 559 | return ret; |
| 560 | |
Arnaldo Carvalho de Melo | b699869 | 2015-09-08 16:58:20 -0300 | [diff] [blame] | 561 | for (i = 0 ; i < perf_env.nr_cmdline; i++) { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 562 | ret = do_write_string(ff, perf_env.cmdline_argv[i]); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 563 | if (ret < 0) |
| 564 | return ret; |
| 565 | } |
| 566 | return 0; |
| 567 | } |
| 568 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 569 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 570 | static int write_cpu_topology(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 571 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 572 | { |
Jiri Olsa | 5135d5e | 2019-02-19 10:58:13 +0100 | [diff] [blame] | 573 | struct cpu_topology *tp; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 574 | u32 i; |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 575 | int ret, j; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 576 | |
Jiri Olsa | 5135d5e | 2019-02-19 10:58:13 +0100 | [diff] [blame] | 577 | tp = cpu_topology__new(); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 578 | if (!tp) |
| 579 | return -1; |
| 580 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 581 | ret = do_write(ff, &tp->core_sib, sizeof(tp->core_sib)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 582 | if (ret < 0) |
| 583 | goto done; |
| 584 | |
| 585 | for (i = 0; i < tp->core_sib; i++) { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 586 | ret = do_write_string(ff, tp->core_siblings[i]); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 587 | if (ret < 0) |
| 588 | goto done; |
| 589 | } |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 590 | ret = do_write(ff, &tp->thread_sib, sizeof(tp->thread_sib)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 591 | if (ret < 0) |
| 592 | goto done; |
| 593 | |
| 594 | for (i = 0; i < tp->thread_sib; i++) { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 595 | ret = do_write_string(ff, tp->thread_siblings[i]); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 596 | if (ret < 0) |
| 597 | break; |
| 598 | } |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 599 | |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 600 | ret = perf_env__read_cpu_topology_map(&perf_env); |
| 601 | if (ret < 0) |
| 602 | goto done; |
| 603 | |
| 604 | for (j = 0; j < perf_env.nr_cpus_avail; j++) { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 605 | ret = do_write(ff, &perf_env.cpu[j].core_id, |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 606 | sizeof(perf_env.cpu[j].core_id)); |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 607 | if (ret < 0) |
| 608 | return ret; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 609 | ret = do_write(ff, &perf_env.cpu[j].socket_id, |
Arnaldo Carvalho de Melo | aa36ddd | 2015-09-09 10:37:01 -0300 | [diff] [blame] | 610 | sizeof(perf_env.cpu[j].socket_id)); |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 611 | if (ret < 0) |
| 612 | return ret; |
| 613 | } |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 614 | |
| 615 | if (!tp->die_sib) |
| 616 | goto done; |
| 617 | |
| 618 | ret = do_write(ff, &tp->die_sib, sizeof(tp->die_sib)); |
| 619 | if (ret < 0) |
| 620 | goto done; |
| 621 | |
| 622 | for (i = 0; i < tp->die_sib; i++) { |
| 623 | ret = do_write_string(ff, tp->die_siblings[i]); |
| 624 | if (ret < 0) |
| 625 | goto done; |
| 626 | } |
| 627 | |
| 628 | for (j = 0; j < perf_env.nr_cpus_avail; j++) { |
| 629 | ret = do_write(ff, &perf_env.cpu[j].die_id, |
| 630 | sizeof(perf_env.cpu[j].die_id)); |
| 631 | if (ret < 0) |
| 632 | return ret; |
| 633 | } |
| 634 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 635 | done: |
Jiri Olsa | 5135d5e | 2019-02-19 10:58:13 +0100 | [diff] [blame] | 636 | cpu_topology__delete(tp); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 637 | return ret; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 642 | static int write_total_mem(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 643 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 644 | { |
| 645 | char *buf = NULL; |
| 646 | FILE *fp; |
| 647 | size_t len = 0; |
| 648 | int ret = -1, n; |
| 649 | uint64_t mem; |
| 650 | |
| 651 | fp = fopen("/proc/meminfo", "r"); |
| 652 | if (!fp) |
| 653 | return -1; |
| 654 | |
| 655 | while (getline(&buf, &len, fp) > 0) { |
| 656 | ret = strncmp(buf, "MemTotal:", 9); |
| 657 | if (!ret) |
| 658 | break; |
| 659 | } |
| 660 | if (!ret) { |
| 661 | n = sscanf(buf, "%*s %"PRIu64, &mem); |
| 662 | if (n == 1) |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 663 | ret = do_write(ff, &mem, sizeof(mem)); |
Wang Nan | ed30775 | 2014-10-16 11:08:29 +0800 | [diff] [blame] | 664 | } else |
| 665 | ret = -1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 666 | free(buf); |
| 667 | fclose(fp); |
| 668 | return ret; |
| 669 | } |
| 670 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 671 | static int write_numa_topology(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 672 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 673 | { |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 674 | struct numa_topology *tp; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 675 | int ret = -1; |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 676 | u32 i; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 677 | |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 678 | tp = numa_topology__new(); |
| 679 | if (!tp) |
| 680 | return -ENOMEM; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 681 | |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 682 | ret = do_write(ff, &tp->nr, sizeof(u32)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 683 | if (ret < 0) |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 684 | goto err; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 685 | |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 686 | for (i = 0; i < tp->nr; i++) { |
| 687 | struct numa_topology_node *n = &tp->nodes[i]; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 688 | |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 689 | ret = do_write(ff, &n->node, sizeof(u32)); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 690 | if (ret < 0) |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 691 | goto err; |
| 692 | |
| 693 | ret = do_write(ff, &n->mem_total, sizeof(u64)); |
| 694 | if (ret) |
| 695 | goto err; |
| 696 | |
| 697 | ret = do_write(ff, &n->mem_free, sizeof(u64)); |
| 698 | if (ret) |
| 699 | goto err; |
| 700 | |
| 701 | ret = do_write_string(ff, n->cpus); |
| 702 | if (ret < 0) |
| 703 | goto err; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 704 | } |
Jiri Olsa | 48e6c5a | 2019-02-19 10:58:14 +0100 | [diff] [blame] | 705 | |
| 706 | ret = 0; |
| 707 | |
| 708 | err: |
| 709 | numa_topology__delete(tp); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 710 | return ret; |
| 711 | } |
| 712 | |
| 713 | /* |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 714 | * File format: |
| 715 | * |
| 716 | * struct pmu_mappings { |
| 717 | * u32 pmu_num; |
| 718 | * struct pmu_map { |
| 719 | * u32 type; |
| 720 | * char name[]; |
| 721 | * }[pmu_num]; |
| 722 | * }; |
| 723 | */ |
| 724 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 725 | static int write_pmu_mappings(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 726 | struct evlist *evlist __maybe_unused) |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 727 | { |
| 728 | struct perf_pmu *pmu = NULL; |
David Carrillo-Cisneros | a02c395 | 2017-07-17 21:25:44 -0700 | [diff] [blame] | 729 | u32 pmu_num = 0; |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 730 | int ret; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 731 | |
David Carrillo-Cisneros | a02c395 | 2017-07-17 21:25:44 -0700 | [diff] [blame] | 732 | /* |
| 733 | * Do a first pass to count number of pmu to avoid lseek so this |
| 734 | * works in pipe mode as well. |
| 735 | */ |
| 736 | while ((pmu = perf_pmu__scan(pmu))) { |
| 737 | if (!pmu->name) |
| 738 | continue; |
| 739 | pmu_num++; |
| 740 | } |
| 741 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 742 | ret = do_write(ff, &pmu_num, sizeof(pmu_num)); |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 743 | if (ret < 0) |
| 744 | return ret; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 745 | |
| 746 | while ((pmu = perf_pmu__scan(pmu))) { |
| 747 | if (!pmu->name) |
| 748 | continue; |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 749 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 750 | ret = do_write(ff, &pmu->type, sizeof(pmu->type)); |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 751 | if (ret < 0) |
| 752 | return ret; |
| 753 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 754 | ret = do_write_string(ff, pmu->name); |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 755 | if (ret < 0) |
| 756 | return ret; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 757 | } |
| 758 | |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | /* |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 763 | * File format: |
| 764 | * |
| 765 | * struct group_descs { |
| 766 | * u32 nr_groups; |
| 767 | * struct group_desc { |
| 768 | * char name[]; |
| 769 | * u32 leader_idx; |
| 770 | * u32 nr_members; |
| 771 | * }[nr_groups]; |
| 772 | * }; |
| 773 | */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 774 | static int write_group_desc(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 775 | struct evlist *evlist) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 776 | { |
| 777 | u32 nr_groups = evlist->nr_groups; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 778 | struct evsel *evsel; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 779 | int ret; |
| 780 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 781 | ret = do_write(ff, &nr_groups, sizeof(nr_groups)); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 782 | if (ret < 0) |
| 783 | return ret; |
| 784 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 785 | evlist__for_each_entry(evlist, evsel) { |
Arnaldo Carvalho de Melo | c754c38 | 2020-04-30 10:51:16 -0300 | [diff] [blame^] | 786 | if (evsel__is_group_leader(evsel) && evsel->core.nr_members > 1) { |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 787 | const char *name = evsel->group_name ?: "{anon_group}"; |
| 788 | u32 leader_idx = evsel->idx; |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 789 | u32 nr_members = evsel->core.nr_members; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 790 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 791 | ret = do_write_string(ff, name); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 792 | if (ret < 0) |
| 793 | return ret; |
| 794 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 795 | ret = do_write(ff, &leader_idx, sizeof(leader_idx)); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 796 | if (ret < 0) |
| 797 | return ret; |
| 798 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 799 | ret = do_write(ff, &nr_members, sizeof(nr_members)); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 800 | if (ret < 0) |
| 801 | return ret; |
| 802 | } |
| 803 | } |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* |
Kan Liang | f4a0742 | 2018-11-21 08:49:39 -0800 | [diff] [blame] | 808 | * Return the CPU id as a raw string. |
| 809 | * |
| 810 | * Each architecture should provide a more precise id string that |
| 811 | * can be use to match the architecture's "mapfile". |
| 812 | */ |
| 813 | char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused) |
| 814 | { |
| 815 | return NULL; |
| 816 | } |
| 817 | |
| 818 | /* Return zero when the cpuid from the mapfile.csv matches the |
| 819 | * cpuid string generated on this platform. |
| 820 | * Otherwise return non-zero. |
| 821 | */ |
| 822 | int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) |
| 823 | { |
| 824 | regex_t re; |
| 825 | regmatch_t pmatch[1]; |
| 826 | int match; |
| 827 | |
| 828 | if (regcomp(&re, mapcpuid, REG_EXTENDED) != 0) { |
| 829 | /* Warn unable to generate match particular string. */ |
| 830 | pr_info("Invalid regular expression %s\n", mapcpuid); |
| 831 | return 1; |
| 832 | } |
| 833 | |
| 834 | match = !regexec(&re, cpuid, 1, pmatch, 0); |
| 835 | regfree(&re); |
| 836 | if (match) { |
| 837 | size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); |
| 838 | |
| 839 | /* Verify the entire string matched. */ |
| 840 | if (match_len == strlen(cpuid)) |
| 841 | return 0; |
| 842 | } |
| 843 | return 1; |
| 844 | } |
| 845 | |
| 846 | /* |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 847 | * default get_cpuid(): nothing gets recorded |
Jiada Wang | 7a759cd | 2017-04-09 20:02:37 -0700 | [diff] [blame] | 848 | * actual implementation must be in arch/$(SRCARCH)/util/header.c |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 849 | */ |
Rui Teng | 11d8f87 | 2016-07-28 10:05:57 +0800 | [diff] [blame] | 850 | int __weak get_cpuid(char *buffer __maybe_unused, size_t sz __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 851 | { |
Arnaldo Carvalho de Melo | 05267c7 | 2019-12-11 10:09:24 -0300 | [diff] [blame] | 852 | return ENOSYS; /* Not implemented */ |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 853 | } |
| 854 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 855 | static int write_cpuid(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 856 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 857 | { |
| 858 | char buffer[64]; |
| 859 | int ret; |
| 860 | |
| 861 | ret = get_cpuid(buffer, sizeof(buffer)); |
Jiri Olsa | a9aeb87 | 2019-02-13 13:32:43 +0100 | [diff] [blame] | 862 | if (ret) |
| 863 | return -1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 864 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 865 | return do_write_string(ff, buffer); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 866 | } |
| 867 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 868 | static int write_branch_stack(struct feat_fd *ff __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 869 | struct evlist *evlist __maybe_unused) |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 870 | { |
| 871 | return 0; |
| 872 | } |
| 873 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 874 | static int write_auxtrace(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 875 | struct evlist *evlist __maybe_unused) |
Adrian Hunter | 4025ea4 | 2015-04-09 18:53:41 +0300 | [diff] [blame] | 876 | { |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 877 | struct perf_session *session; |
| 878 | int err; |
| 879 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 880 | if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) |
| 881 | return -1; |
| 882 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 883 | session = container_of(ff->ph, struct perf_session, header); |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 884 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 885 | err = auxtrace_index__write(ff->fd, &session->auxtrace_index); |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 886 | if (err < 0) |
| 887 | pr_err("Failed to write auxtrace index\n"); |
| 888 | return err; |
Adrian Hunter | 4025ea4 | 2015-04-09 18:53:41 +0300 | [diff] [blame] | 889 | } |
| 890 | |
Alexey Budankov | cf79051 | 2018-10-09 17:36:24 +0300 | [diff] [blame] | 891 | static int write_clockid(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 892 | struct evlist *evlist __maybe_unused) |
Alexey Budankov | cf79051 | 2018-10-09 17:36:24 +0300 | [diff] [blame] | 893 | { |
| 894 | return do_write(ff, &ff->ph->env.clockid_res_ns, |
| 895 | sizeof(ff->ph->env.clockid_res_ns)); |
| 896 | } |
| 897 | |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 898 | static int write_dir_format(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 899 | struct evlist *evlist __maybe_unused) |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 900 | { |
| 901 | struct perf_session *session; |
| 902 | struct perf_data *data; |
| 903 | |
| 904 | session = container_of(ff->ph, struct perf_session, header); |
| 905 | data = session->data; |
| 906 | |
| 907 | if (WARN_ON(!perf_data__is_dir(data))) |
| 908 | return -1; |
| 909 | |
| 910 | return do_write(ff, &data->dir.version, sizeof(data->dir.version)); |
| 911 | } |
| 912 | |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 913 | #ifdef HAVE_LIBBPF_SUPPORT |
| 914 | static int write_bpf_prog_info(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 915 | struct evlist *evlist __maybe_unused) |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 916 | { |
| 917 | struct perf_env *env = &ff->ph->env; |
| 918 | struct rb_root *root; |
| 919 | struct rb_node *next; |
| 920 | int ret; |
| 921 | |
| 922 | down_read(&env->bpf_progs.lock); |
| 923 | |
| 924 | ret = do_write(ff, &env->bpf_progs.infos_cnt, |
| 925 | sizeof(env->bpf_progs.infos_cnt)); |
| 926 | if (ret < 0) |
| 927 | goto out; |
| 928 | |
| 929 | root = &env->bpf_progs.infos; |
| 930 | next = rb_first(root); |
| 931 | while (next) { |
| 932 | struct bpf_prog_info_node *node; |
| 933 | size_t len; |
| 934 | |
| 935 | node = rb_entry(next, struct bpf_prog_info_node, rb_node); |
| 936 | next = rb_next(&node->rb_node); |
| 937 | len = sizeof(struct bpf_prog_info_linear) + |
| 938 | node->info_linear->data_len; |
| 939 | |
| 940 | /* before writing to file, translate address to offset */ |
| 941 | bpf_program__bpil_addr_to_offs(node->info_linear); |
| 942 | ret = do_write(ff, node->info_linear, len); |
| 943 | /* |
| 944 | * translate back to address even when do_write() fails, |
| 945 | * so that this function never changes the data. |
| 946 | */ |
| 947 | bpf_program__bpil_offs_to_addr(node->info_linear); |
| 948 | if (ret < 0) |
| 949 | goto out; |
| 950 | } |
| 951 | out: |
| 952 | up_read(&env->bpf_progs.lock); |
| 953 | return ret; |
| 954 | } |
| 955 | #else // HAVE_LIBBPF_SUPPORT |
| 956 | static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 957 | struct evlist *evlist __maybe_unused) |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 958 | { |
| 959 | return 0; |
| 960 | } |
| 961 | #endif // HAVE_LIBBPF_SUPPORT |
| 962 | |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 963 | static int write_bpf_btf(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 964 | struct evlist *evlist __maybe_unused) |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 965 | { |
| 966 | struct perf_env *env = &ff->ph->env; |
| 967 | struct rb_root *root; |
| 968 | struct rb_node *next; |
| 969 | int ret; |
| 970 | |
| 971 | down_read(&env->bpf_progs.lock); |
| 972 | |
| 973 | ret = do_write(ff, &env->bpf_progs.btfs_cnt, |
| 974 | sizeof(env->bpf_progs.btfs_cnt)); |
| 975 | |
| 976 | if (ret < 0) |
| 977 | goto out; |
| 978 | |
| 979 | root = &env->bpf_progs.btfs; |
| 980 | next = rb_first(root); |
| 981 | while (next) { |
| 982 | struct btf_node *node; |
| 983 | |
| 984 | node = rb_entry(next, struct btf_node, rb_node); |
| 985 | next = rb_next(&node->rb_node); |
| 986 | ret = do_write(ff, &node->id, |
| 987 | sizeof(u32) * 2 + node->data_size); |
| 988 | if (ret < 0) |
| 989 | goto out; |
| 990 | } |
| 991 | out: |
| 992 | up_read(&env->bpf_progs.lock); |
| 993 | return ret; |
| 994 | } |
| 995 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 996 | static int cpu_cache_level__sort(const void *a, const void *b) |
| 997 | { |
| 998 | struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a; |
| 999 | struct cpu_cache_level *cache_b = (struct cpu_cache_level *)b; |
| 1000 | |
| 1001 | return cache_a->level - cache_b->level; |
| 1002 | } |
| 1003 | |
| 1004 | static bool cpu_cache_level__cmp(struct cpu_cache_level *a, struct cpu_cache_level *b) |
| 1005 | { |
| 1006 | if (a->level != b->level) |
| 1007 | return false; |
| 1008 | |
| 1009 | if (a->line_size != b->line_size) |
| 1010 | return false; |
| 1011 | |
| 1012 | if (a->sets != b->sets) |
| 1013 | return false; |
| 1014 | |
| 1015 | if (a->ways != b->ways) |
| 1016 | return false; |
| 1017 | |
| 1018 | if (strcmp(a->type, b->type)) |
| 1019 | return false; |
| 1020 | |
| 1021 | if (strcmp(a->size, b->size)) |
| 1022 | return false; |
| 1023 | |
| 1024 | if (strcmp(a->map, b->map)) |
| 1025 | return false; |
| 1026 | |
| 1027 | return true; |
| 1028 | } |
| 1029 | |
| 1030 | static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 level) |
| 1031 | { |
| 1032 | char path[PATH_MAX], file[PATH_MAX]; |
| 1033 | struct stat st; |
| 1034 | size_t len; |
| 1035 | |
| 1036 | scnprintf(path, PATH_MAX, "devices/system/cpu/cpu%d/cache/index%d/", cpu, level); |
| 1037 | scnprintf(file, PATH_MAX, "%s/%s", sysfs__mountpoint(), path); |
| 1038 | |
| 1039 | if (stat(file, &st)) |
| 1040 | return 1; |
| 1041 | |
| 1042 | scnprintf(file, PATH_MAX, "%s/level", path); |
| 1043 | if (sysfs__read_int(file, (int *) &cache->level)) |
| 1044 | return -1; |
| 1045 | |
| 1046 | scnprintf(file, PATH_MAX, "%s/coherency_line_size", path); |
| 1047 | if (sysfs__read_int(file, (int *) &cache->line_size)) |
| 1048 | return -1; |
| 1049 | |
| 1050 | scnprintf(file, PATH_MAX, "%s/number_of_sets", path); |
| 1051 | if (sysfs__read_int(file, (int *) &cache->sets)) |
| 1052 | return -1; |
| 1053 | |
| 1054 | scnprintf(file, PATH_MAX, "%s/ways_of_associativity", path); |
| 1055 | if (sysfs__read_int(file, (int *) &cache->ways)) |
| 1056 | return -1; |
| 1057 | |
| 1058 | scnprintf(file, PATH_MAX, "%s/type", path); |
| 1059 | if (sysfs__read_str(file, &cache->type, &len)) |
| 1060 | return -1; |
| 1061 | |
| 1062 | cache->type[len] = 0; |
Arnaldo Carvalho de Melo | 13c230a | 2019-06-26 12:13:13 -0300 | [diff] [blame] | 1063 | cache->type = strim(cache->type); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1064 | |
| 1065 | scnprintf(file, PATH_MAX, "%s/size", path); |
| 1066 | if (sysfs__read_str(file, &cache->size, &len)) { |
Arnaldo Carvalho de Melo | d8f9da2 | 2019-07-04 12:06:20 -0300 | [diff] [blame] | 1067 | zfree(&cache->type); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1068 | return -1; |
| 1069 | } |
| 1070 | |
| 1071 | cache->size[len] = 0; |
Arnaldo Carvalho de Melo | 13c230a | 2019-06-26 12:13:13 -0300 | [diff] [blame] | 1072 | cache->size = strim(cache->size); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1073 | |
| 1074 | scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path); |
| 1075 | if (sysfs__read_str(file, &cache->map, &len)) { |
Jiri Olsa | 0216234 | 2019-09-12 12:52:35 +0200 | [diff] [blame] | 1076 | zfree(&cache->size); |
Arnaldo Carvalho de Melo | d8f9da2 | 2019-07-04 12:06:20 -0300 | [diff] [blame] | 1077 | zfree(&cache->type); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1078 | return -1; |
| 1079 | } |
| 1080 | |
| 1081 | cache->map[len] = 0; |
Arnaldo Carvalho de Melo | 13c230a | 2019-06-26 12:13:13 -0300 | [diff] [blame] | 1082 | cache->map = strim(cache->map); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | static void cpu_cache_level__fprintf(FILE *out, struct cpu_cache_level *c) |
| 1087 | { |
| 1088 | fprintf(out, "L%d %-15s %8s [%s]\n", c->level, c->type, c->size, c->map); |
| 1089 | } |
| 1090 | |
Michael Petlan | 2870782 | 2019-12-08 17:20:56 +0100 | [diff] [blame] | 1091 | #define MAX_CACHE_LVL 4 |
| 1092 | |
| 1093 | static int build_caches(struct cpu_cache_level caches[], u32 *cntp) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1094 | { |
| 1095 | u32 i, cnt = 0; |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1096 | u32 nr, cpu; |
| 1097 | u16 level; |
| 1098 | |
Michael Petlan | 2870782 | 2019-12-08 17:20:56 +0100 | [diff] [blame] | 1099 | nr = cpu__max_cpu(); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1100 | |
| 1101 | for (cpu = 0; cpu < nr; cpu++) { |
Michael Petlan | 2870782 | 2019-12-08 17:20:56 +0100 | [diff] [blame] | 1102 | for (level = 0; level < MAX_CACHE_LVL; level++) { |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1103 | struct cpu_cache_level c; |
| 1104 | int err; |
| 1105 | |
| 1106 | err = cpu_cache_level__read(&c, cpu, level); |
| 1107 | if (err < 0) |
| 1108 | return err; |
| 1109 | |
| 1110 | if (err == 1) |
| 1111 | break; |
| 1112 | |
| 1113 | for (i = 0; i < cnt; i++) { |
| 1114 | if (cpu_cache_level__cmp(&c, &caches[i])) |
| 1115 | break; |
| 1116 | } |
| 1117 | |
| 1118 | if (i == cnt) |
| 1119 | caches[cnt++] = c; |
| 1120 | else |
| 1121 | cpu_cache_level__free(&c); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1122 | } |
| 1123 | } |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1124 | *cntp = cnt; |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1128 | static int write_cache(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1129 | struct evlist *evlist __maybe_unused) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1130 | { |
Kyle Meyer | dc84187 | 2019-08-27 16:43:51 -0500 | [diff] [blame] | 1131 | u32 max_caches = cpu__max_cpu() * MAX_CACHE_LVL; |
| 1132 | struct cpu_cache_level caches[max_caches]; |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1133 | u32 cnt = 0, i, version = 1; |
| 1134 | int ret; |
| 1135 | |
Michael Petlan | 2870782 | 2019-12-08 17:20:56 +0100 | [diff] [blame] | 1136 | ret = build_caches(caches, &cnt); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1137 | if (ret) |
| 1138 | goto out; |
| 1139 | |
| 1140 | qsort(&caches, cnt, sizeof(struct cpu_cache_level), cpu_cache_level__sort); |
| 1141 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1142 | ret = do_write(ff, &version, sizeof(u32)); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1143 | if (ret < 0) |
| 1144 | goto out; |
| 1145 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1146 | ret = do_write(ff, &cnt, sizeof(u32)); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1147 | if (ret < 0) |
| 1148 | goto out; |
| 1149 | |
| 1150 | for (i = 0; i < cnt; i++) { |
| 1151 | struct cpu_cache_level *c = &caches[i]; |
| 1152 | |
| 1153 | #define _W(v) \ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1154 | ret = do_write(ff, &c->v, sizeof(u32)); \ |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1155 | if (ret < 0) \ |
| 1156 | goto out; |
| 1157 | |
| 1158 | _W(level) |
| 1159 | _W(line_size) |
| 1160 | _W(sets) |
| 1161 | _W(ways) |
| 1162 | #undef _W |
| 1163 | |
| 1164 | #define _W(v) \ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1165 | ret = do_write_string(ff, (const char *) c->v); \ |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1166 | if (ret < 0) \ |
| 1167 | goto out; |
| 1168 | |
| 1169 | _W(type) |
| 1170 | _W(size) |
| 1171 | _W(map) |
| 1172 | #undef _W |
| 1173 | } |
| 1174 | |
| 1175 | out: |
| 1176 | for (i = 0; i < cnt; i++) |
| 1177 | cpu_cache_level__free(&caches[i]); |
| 1178 | return ret; |
| 1179 | } |
| 1180 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 1181 | static int write_stat(struct feat_fd *ff __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1182 | struct evlist *evlist __maybe_unused) |
Jiri Olsa | ffa517a | 2015-10-25 15:51:43 +0100 | [diff] [blame] | 1183 | { |
| 1184 | return 0; |
| 1185 | } |
| 1186 | |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 1187 | static int write_sample_time(struct feat_fd *ff, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1188 | struct evlist *evlist) |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 1189 | { |
| 1190 | int ret; |
| 1191 | |
| 1192 | ret = do_write(ff, &evlist->first_sample_time, |
| 1193 | sizeof(evlist->first_sample_time)); |
| 1194 | if (ret < 0) |
| 1195 | return ret; |
| 1196 | |
| 1197 | return do_write(ff, &evlist->last_sample_time, |
| 1198 | sizeof(evlist->last_sample_time)); |
| 1199 | } |
| 1200 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1201 | |
| 1202 | static int memory_node__read(struct memory_node *n, unsigned long idx) |
| 1203 | { |
| 1204 | unsigned int phys, size = 0; |
| 1205 | char path[PATH_MAX]; |
| 1206 | struct dirent *ent; |
| 1207 | DIR *dir; |
| 1208 | |
| 1209 | #define for_each_memory(mem, dir) \ |
| 1210 | while ((ent = readdir(dir))) \ |
| 1211 | if (strcmp(ent->d_name, ".") && \ |
| 1212 | strcmp(ent->d_name, "..") && \ |
| 1213 | sscanf(ent->d_name, "memory%u", &mem) == 1) |
| 1214 | |
| 1215 | scnprintf(path, PATH_MAX, |
| 1216 | "%s/devices/system/node/node%lu", |
| 1217 | sysfs__mountpoint(), idx); |
| 1218 | |
| 1219 | dir = opendir(path); |
| 1220 | if (!dir) { |
| 1221 | pr_warning("failed: cant' open memory sysfs data\n"); |
| 1222 | return -1; |
| 1223 | } |
| 1224 | |
| 1225 | for_each_memory(phys, dir) { |
| 1226 | size = max(phys, size); |
| 1227 | } |
| 1228 | |
| 1229 | size++; |
| 1230 | |
| 1231 | n->set = bitmap_alloc(size); |
| 1232 | if (!n->set) { |
| 1233 | closedir(dir); |
| 1234 | return -ENOMEM; |
| 1235 | } |
| 1236 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1237 | n->node = idx; |
| 1238 | n->size = size; |
| 1239 | |
| 1240 | rewinddir(dir); |
| 1241 | |
| 1242 | for_each_memory(phys, dir) { |
| 1243 | set_bit(phys, n->set); |
| 1244 | } |
| 1245 | |
| 1246 | closedir(dir); |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | static int memory_node__sort(const void *a, const void *b) |
| 1251 | { |
| 1252 | const struct memory_node *na = a; |
| 1253 | const struct memory_node *nb = b; |
| 1254 | |
| 1255 | return na->node - nb->node; |
| 1256 | } |
| 1257 | |
| 1258 | static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp) |
| 1259 | { |
| 1260 | char path[PATH_MAX]; |
| 1261 | struct dirent *ent; |
| 1262 | DIR *dir; |
| 1263 | u64 cnt = 0; |
| 1264 | int ret = 0; |
| 1265 | |
| 1266 | scnprintf(path, PATH_MAX, "%s/devices/system/node/", |
| 1267 | sysfs__mountpoint()); |
| 1268 | |
| 1269 | dir = opendir(path); |
| 1270 | if (!dir) { |
Thomas Richter | 4f75f1cb | 2018-04-12 15:32:46 +0200 | [diff] [blame] | 1271 | pr_debug2("%s: could't read %s, does this arch have topology information?\n", |
| 1272 | __func__, path); |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1273 | return -1; |
| 1274 | } |
| 1275 | |
| 1276 | while (!ret && (ent = readdir(dir))) { |
| 1277 | unsigned int idx; |
| 1278 | int r; |
| 1279 | |
| 1280 | if (!strcmp(ent->d_name, ".") || |
| 1281 | !strcmp(ent->d_name, "..")) |
| 1282 | continue; |
| 1283 | |
| 1284 | r = sscanf(ent->d_name, "node%u", &idx); |
| 1285 | if (r != 1) |
| 1286 | continue; |
| 1287 | |
| 1288 | if (WARN_ONCE(cnt >= size, |
Yunfeng Ye | 6080728 | 2019-10-15 16:30:08 +0800 | [diff] [blame] | 1289 | "failed to write MEM_TOPOLOGY, way too many nodes\n")) { |
| 1290 | closedir(dir); |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1291 | return -1; |
Yunfeng Ye | 6080728 | 2019-10-15 16:30:08 +0800 | [diff] [blame] | 1292 | } |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1293 | |
| 1294 | ret = memory_node__read(&nodes[cnt++], idx); |
| 1295 | } |
| 1296 | |
| 1297 | *cntp = cnt; |
| 1298 | closedir(dir); |
| 1299 | |
| 1300 | if (!ret) |
| 1301 | qsort(nodes, cnt, sizeof(nodes[0]), memory_node__sort); |
| 1302 | |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | #define MAX_MEMORY_NODES 2000 |
| 1307 | |
| 1308 | /* |
| 1309 | * The MEM_TOPOLOGY holds physical memory map for every |
| 1310 | * node in system. The format of data is as follows: |
| 1311 | * |
| 1312 | * 0 - version | for future changes |
| 1313 | * 8 - block_size_bytes | /sys/devices/system/memory/block_size_bytes |
| 1314 | * 16 - count | number of nodes |
| 1315 | * |
| 1316 | * For each node we store map of physical indexes for |
| 1317 | * each node: |
| 1318 | * |
| 1319 | * 32 - node id | node index |
| 1320 | * 40 - size | size of bitmap |
| 1321 | * 48 - bitmap | bitmap of memory indexes that belongs to node |
| 1322 | */ |
| 1323 | static int write_mem_topology(struct feat_fd *ff __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1324 | struct evlist *evlist __maybe_unused) |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1325 | { |
| 1326 | static struct memory_node nodes[MAX_MEMORY_NODES]; |
| 1327 | u64 bsize, version = 1, i, nr; |
| 1328 | int ret; |
| 1329 | |
| 1330 | ret = sysfs__read_xll("devices/system/memory/block_size_bytes", |
| 1331 | (unsigned long long *) &bsize); |
| 1332 | if (ret) |
| 1333 | return ret; |
| 1334 | |
| 1335 | ret = build_mem_topology(&nodes[0], MAX_MEMORY_NODES, &nr); |
| 1336 | if (ret) |
| 1337 | return ret; |
| 1338 | |
| 1339 | ret = do_write(ff, &version, sizeof(version)); |
| 1340 | if (ret < 0) |
| 1341 | goto out; |
| 1342 | |
| 1343 | ret = do_write(ff, &bsize, sizeof(bsize)); |
| 1344 | if (ret < 0) |
| 1345 | goto out; |
| 1346 | |
| 1347 | ret = do_write(ff, &nr, sizeof(nr)); |
| 1348 | if (ret < 0) |
| 1349 | goto out; |
| 1350 | |
| 1351 | for (i = 0; i < nr; i++) { |
| 1352 | struct memory_node *n = &nodes[i]; |
| 1353 | |
| 1354 | #define _W(v) \ |
| 1355 | ret = do_write(ff, &n->v, sizeof(n->v)); \ |
| 1356 | if (ret < 0) \ |
| 1357 | goto out; |
| 1358 | |
| 1359 | _W(node) |
| 1360 | _W(size) |
| 1361 | |
| 1362 | #undef _W |
| 1363 | |
| 1364 | ret = do_write_bitmap(ff, n->set, n->size); |
| 1365 | if (ret < 0) |
| 1366 | goto out; |
| 1367 | } |
| 1368 | |
| 1369 | out: |
| 1370 | return ret; |
| 1371 | } |
| 1372 | |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 1373 | static int write_compressed(struct feat_fd *ff __maybe_unused, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1374 | struct evlist *evlist __maybe_unused) |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 1375 | { |
| 1376 | int ret; |
| 1377 | |
| 1378 | ret = do_write(ff, &(ff->ph->env.comp_ver), sizeof(ff->ph->env.comp_ver)); |
| 1379 | if (ret) |
| 1380 | return ret; |
| 1381 | |
| 1382 | ret = do_write(ff, &(ff->ph->env.comp_type), sizeof(ff->ph->env.comp_type)); |
| 1383 | if (ret) |
| 1384 | return ret; |
| 1385 | |
| 1386 | ret = do_write(ff, &(ff->ph->env.comp_level), sizeof(ff->ph->env.comp_level)); |
| 1387 | if (ret) |
| 1388 | return ret; |
| 1389 | |
| 1390 | ret = do_write(ff, &(ff->ph->env.comp_ratio), sizeof(ff->ph->env.comp_ratio)); |
| 1391 | if (ret) |
| 1392 | return ret; |
| 1393 | |
| 1394 | return do_write(ff, &(ff->ph->env.comp_mmap_len), sizeof(ff->ph->env.comp_mmap_len)); |
| 1395 | } |
| 1396 | |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 1397 | static int write_cpu_pmu_caps(struct feat_fd *ff, |
| 1398 | struct evlist *evlist __maybe_unused) |
| 1399 | { |
| 1400 | struct perf_pmu *cpu_pmu = perf_pmu__find("cpu"); |
| 1401 | struct perf_pmu_caps *caps = NULL; |
| 1402 | int nr_caps; |
| 1403 | int ret; |
| 1404 | |
| 1405 | if (!cpu_pmu) |
| 1406 | return -ENOENT; |
| 1407 | |
| 1408 | nr_caps = perf_pmu__caps_parse(cpu_pmu); |
| 1409 | if (nr_caps < 0) |
| 1410 | return nr_caps; |
| 1411 | |
| 1412 | ret = do_write(ff, &nr_caps, sizeof(nr_caps)); |
| 1413 | if (ret < 0) |
| 1414 | return ret; |
| 1415 | |
| 1416 | list_for_each_entry(caps, &cpu_pmu->caps, list) { |
| 1417 | ret = do_write_string(ff, caps->name); |
| 1418 | if (ret < 0) |
| 1419 | return ret; |
| 1420 | |
| 1421 | ret = do_write_string(ff, caps->value); |
| 1422 | if (ret < 0) |
| 1423 | return ret; |
| 1424 | } |
| 1425 | |
| 1426 | return ret; |
| 1427 | } |
| 1428 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1429 | static void print_hostname(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1430 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1431 | fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1432 | } |
| 1433 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1434 | static void print_osrelease(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1435 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1436 | fprintf(fp, "# os release : %s\n", ff->ph->env.os_release); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1437 | } |
| 1438 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1439 | static void print_arch(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1440 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1441 | fprintf(fp, "# arch : %s\n", ff->ph->env.arch); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1444 | static void print_cpudesc(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1445 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1446 | fprintf(fp, "# cpudesc : %s\n", ff->ph->env.cpu_desc); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1447 | } |
| 1448 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1449 | static void print_nrcpus(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1450 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1451 | fprintf(fp, "# nrcpus online : %u\n", ff->ph->env.nr_cpus_online); |
| 1452 | fprintf(fp, "# nrcpus avail : %u\n", ff->ph->env.nr_cpus_avail); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1453 | } |
| 1454 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1455 | static void print_version(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1456 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1457 | fprintf(fp, "# perf version : %s\n", ff->ph->env.version); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1458 | } |
| 1459 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1460 | static void print_cmdline(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1461 | { |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1462 | int nr, i; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1463 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1464 | nr = ff->ph->env.nr_cmdline; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1465 | |
| 1466 | fprintf(fp, "# cmdline : "); |
| 1467 | |
Alexey Budankov | f92da71 | 2018-06-04 09:50:56 +0300 | [diff] [blame] | 1468 | for (i = 0; i < nr; i++) { |
| 1469 | char *argv_i = strdup(ff->ph->env.cmdline_argv[i]); |
| 1470 | if (!argv_i) { |
| 1471 | fprintf(fp, "%s ", ff->ph->env.cmdline_argv[i]); |
| 1472 | } else { |
| 1473 | char *mem = argv_i; |
| 1474 | do { |
| 1475 | char *quote = strchr(argv_i, '\''); |
| 1476 | if (!quote) |
| 1477 | break; |
| 1478 | *quote++ = '\0'; |
| 1479 | fprintf(fp, "%s\\\'", argv_i); |
| 1480 | argv_i = quote; |
| 1481 | } while (1); |
| 1482 | fprintf(fp, "%s ", argv_i); |
| 1483 | free(mem); |
| 1484 | } |
| 1485 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1486 | fputc('\n', fp); |
| 1487 | } |
| 1488 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1489 | static void print_cpu_topology(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1490 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1491 | struct perf_header *ph = ff->ph; |
| 1492 | int cpu_nr = ph->env.nr_cpus_avail; |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1493 | int nr, i; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1494 | char *str; |
| 1495 | |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1496 | nr = ph->env.nr_sibling_cores; |
| 1497 | str = ph->env.sibling_cores; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1498 | |
| 1499 | for (i = 0; i < nr; i++) { |
Kan Liang | e05a899 | 2019-06-04 15:50:43 -0700 | [diff] [blame] | 1500 | fprintf(fp, "# sibling sockets : %s\n", str); |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1501 | str += strlen(str) + 1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1502 | } |
| 1503 | |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 1504 | if (ph->env.nr_sibling_dies) { |
| 1505 | nr = ph->env.nr_sibling_dies; |
| 1506 | str = ph->env.sibling_dies; |
| 1507 | |
| 1508 | for (i = 0; i < nr; i++) { |
| 1509 | fprintf(fp, "# sibling dies : %s\n", str); |
| 1510 | str += strlen(str) + 1; |
| 1511 | } |
| 1512 | } |
| 1513 | |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1514 | nr = ph->env.nr_sibling_threads; |
| 1515 | str = ph->env.sibling_threads; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1516 | |
| 1517 | for (i = 0; i < nr; i++) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1518 | fprintf(fp, "# sibling threads : %s\n", str); |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1519 | str += strlen(str) + 1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1520 | } |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 1521 | |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 1522 | if (ph->env.nr_sibling_dies) { |
| 1523 | if (ph->env.cpu != NULL) { |
| 1524 | for (i = 0; i < cpu_nr; i++) |
| 1525 | fprintf(fp, "# CPU %d: Core ID %d, " |
| 1526 | "Die ID %d, Socket ID %d\n", |
| 1527 | i, ph->env.cpu[i].core_id, |
| 1528 | ph->env.cpu[i].die_id, |
| 1529 | ph->env.cpu[i].socket_id); |
| 1530 | } else |
| 1531 | fprintf(fp, "# Core ID, Die ID and Socket ID " |
| 1532 | "information is not available\n"); |
| 1533 | } else { |
| 1534 | if (ph->env.cpu != NULL) { |
| 1535 | for (i = 0; i < cpu_nr; i++) |
| 1536 | fprintf(fp, "# CPU %d: Core ID %d, " |
| 1537 | "Socket ID %d\n", |
| 1538 | i, ph->env.cpu[i].core_id, |
| 1539 | ph->env.cpu[i].socket_id); |
| 1540 | } else |
| 1541 | fprintf(fp, "# Core ID and Socket ID " |
| 1542 | "information is not available\n"); |
| 1543 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
Alexey Budankov | cf79051 | 2018-10-09 17:36:24 +0300 | [diff] [blame] | 1546 | static void print_clockid(struct feat_fd *ff, FILE *fp) |
| 1547 | { |
| 1548 | fprintf(fp, "# clockid frequency: %"PRIu64" MHz\n", |
| 1549 | ff->ph->env.clockid_res_ns * 1000); |
| 1550 | } |
| 1551 | |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 1552 | static void print_dir_format(struct feat_fd *ff, FILE *fp) |
| 1553 | { |
| 1554 | struct perf_session *session; |
| 1555 | struct perf_data *data; |
| 1556 | |
| 1557 | session = container_of(ff->ph, struct perf_session, header); |
| 1558 | data = session->data; |
| 1559 | |
| 1560 | fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version); |
| 1561 | } |
| 1562 | |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 1563 | static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp) |
| 1564 | { |
| 1565 | struct perf_env *env = &ff->ph->env; |
| 1566 | struct rb_root *root; |
| 1567 | struct rb_node *next; |
| 1568 | |
| 1569 | down_read(&env->bpf_progs.lock); |
| 1570 | |
| 1571 | root = &env->bpf_progs.infos; |
| 1572 | next = rb_first(root); |
| 1573 | |
| 1574 | while (next) { |
| 1575 | struct bpf_prog_info_node *node; |
| 1576 | |
| 1577 | node = rb_entry(next, struct bpf_prog_info_node, rb_node); |
| 1578 | next = rb_next(&node->rb_node); |
Song Liu | f8dfeae | 2019-03-19 09:54:54 -0700 | [diff] [blame] | 1579 | |
| 1580 | bpf_event__print_bpf_prog_info(&node->info_linear->info, |
| 1581 | env, fp); |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | up_read(&env->bpf_progs.lock); |
| 1585 | } |
| 1586 | |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 1587 | static void print_bpf_btf(struct feat_fd *ff, FILE *fp) |
| 1588 | { |
| 1589 | struct perf_env *env = &ff->ph->env; |
| 1590 | struct rb_root *root; |
| 1591 | struct rb_node *next; |
| 1592 | |
| 1593 | down_read(&env->bpf_progs.lock); |
| 1594 | |
| 1595 | root = &env->bpf_progs.btfs; |
| 1596 | next = rb_first(root); |
| 1597 | |
| 1598 | while (next) { |
| 1599 | struct btf_node *node; |
| 1600 | |
| 1601 | node = rb_entry(next, struct btf_node, rb_node); |
| 1602 | next = rb_next(&node->rb_node); |
| 1603 | fprintf(fp, "# btf info of id %u\n", node->id); |
| 1604 | } |
| 1605 | |
| 1606 | up_read(&env->bpf_progs.lock); |
| 1607 | } |
| 1608 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1609 | static void free_event_desc(struct evsel *events) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1610 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1611 | struct evsel *evsel; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1612 | |
| 1613 | if (!events) |
| 1614 | return; |
| 1615 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1616 | for (evsel = events; evsel->core.attr.size; evsel++) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 1617 | zfree(&evsel->name); |
Jiri Olsa | deaf321 | 2019-09-02 22:12:26 +0200 | [diff] [blame] | 1618 | zfree(&evsel->core.id); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | free(events); |
| 1622 | } |
| 1623 | |
Kan Liang | 277ce1e | 2020-02-28 08:30:02 -0800 | [diff] [blame] | 1624 | static bool perf_attr_check(struct perf_event_attr *attr) |
| 1625 | { |
| 1626 | if (attr->__reserved_1 || attr->__reserved_2 || attr->__reserved_3) { |
| 1627 | pr_warning("Reserved bits are set unexpectedly. " |
| 1628 | "Please update perf tool.\n"); |
| 1629 | return false; |
| 1630 | } |
| 1631 | |
| 1632 | if (attr->sample_type & ~(PERF_SAMPLE_MAX-1)) { |
| 1633 | pr_warning("Unknown sample type (0x%llx) is detected. " |
| 1634 | "Please update perf tool.\n", |
| 1635 | attr->sample_type); |
| 1636 | return false; |
| 1637 | } |
| 1638 | |
| 1639 | if (attr->read_format & ~(PERF_FORMAT_MAX-1)) { |
| 1640 | pr_warning("Unknown read format (0x%llx) is detected. " |
| 1641 | "Please update perf tool.\n", |
| 1642 | attr->read_format); |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | if ((attr->sample_type & PERF_SAMPLE_BRANCH_STACK) && |
| 1647 | (attr->branch_sample_type & ~(PERF_SAMPLE_BRANCH_MAX-1))) { |
| 1648 | pr_warning("Unknown branch sample type (0x%llx) is detected. " |
| 1649 | "Please update perf tool.\n", |
| 1650 | attr->branch_sample_type); |
| 1651 | |
| 1652 | return false; |
| 1653 | } |
| 1654 | |
| 1655 | return true; |
| 1656 | } |
| 1657 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1658 | static struct evsel *read_event_desc(struct feat_fd *ff) |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1659 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1660 | struct evsel *evsel, *events = NULL; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1661 | u64 *id; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1662 | void *buf = NULL; |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1663 | u32 nre, sz, nr, i, j; |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1664 | size_t msz; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1665 | |
| 1666 | /* number of events */ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1667 | if (do_read_u32(ff, &nre)) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1668 | goto error; |
| 1669 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1670 | if (do_read_u32(ff, &sz)) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1671 | goto error; |
| 1672 | |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1673 | /* buffer to hold on file attr struct */ |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1674 | buf = malloc(sz); |
| 1675 | if (!buf) |
| 1676 | goto error; |
| 1677 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1678 | /* the last event terminates with evsel->core.attr.size == 0: */ |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1679 | events = calloc(nre + 1, sizeof(*events)); |
| 1680 | if (!events) |
| 1681 | goto error; |
| 1682 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1683 | msz = sizeof(evsel->core.attr); |
Jiri Olsa | 9fafd98 | 2012-03-20 19:15:39 +0100 | [diff] [blame] | 1684 | if (sz < msz) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1685 | msz = sz; |
| 1686 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1687 | for (i = 0, evsel = events; i < nre; evsel++, i++) { |
| 1688 | evsel->idx = i; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1689 | |
Stephane Eranian | 62db906 | 2012-02-09 23:21:07 +0100 | [diff] [blame] | 1690 | /* |
| 1691 | * must read entire on-file attr struct to |
| 1692 | * sync up with layout. |
| 1693 | */ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1694 | if (__do_read(ff, buf, sz)) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1695 | goto error; |
| 1696 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1697 | if (ff->ph->needs_swap) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1698 | perf_event__attr_swap(buf); |
| 1699 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1700 | memcpy(&evsel->core.attr, buf, msz); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1701 | |
Kan Liang | 277ce1e | 2020-02-28 08:30:02 -0800 | [diff] [blame] | 1702 | if (!perf_attr_check(&evsel->core.attr)) |
| 1703 | goto error; |
| 1704 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1705 | if (do_read_u32(ff, &nr)) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1706 | goto error; |
| 1707 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1708 | if (ff->ph->needs_swap) |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1709 | evsel->needs_swap = true; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1710 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1711 | evsel->name = do_read_string(ff); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 1712 | if (!evsel->name) |
| 1713 | goto error; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1714 | |
| 1715 | if (!nr) |
| 1716 | continue; |
| 1717 | |
| 1718 | id = calloc(nr, sizeof(*id)); |
| 1719 | if (!id) |
| 1720 | goto error; |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 1721 | evsel->core.ids = nr; |
Jiri Olsa | deaf321 | 2019-09-02 22:12:26 +0200 | [diff] [blame] | 1722 | evsel->core.id = id; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1723 | |
| 1724 | for (j = 0 ; j < nr; j++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 1725 | if (do_read_u64(ff, id)) |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1726 | goto error; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1727 | id++; |
| 1728 | } |
| 1729 | } |
| 1730 | out: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1731 | free(buf); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1732 | return events; |
| 1733 | error: |
Markus Elfring | 4cc9761 | 2015-06-25 17:12:32 +0200 | [diff] [blame] | 1734 | free_event_desc(events); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1735 | events = NULL; |
| 1736 | goto out; |
| 1737 | } |
| 1738 | |
Peter Zijlstra | 2c5e8c5 | 2015-04-07 11:09:54 +0200 | [diff] [blame] | 1739 | static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val, |
Arnaldo Carvalho de Melo | 0353631 | 2017-06-16 12:18:27 -0300 | [diff] [blame] | 1740 | void *priv __maybe_unused) |
Peter Zijlstra | 2c5e8c5 | 2015-04-07 11:09:54 +0200 | [diff] [blame] | 1741 | { |
| 1742 | return fprintf(fp, ", %s = %s", name, val); |
| 1743 | } |
| 1744 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1745 | static void print_event_desc(struct feat_fd *ff, FILE *fp) |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1746 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1747 | struct evsel *evsel, *events; |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1748 | u32 j; |
| 1749 | u64 *id; |
| 1750 | |
David Carrillo-Cisneros | f9ebdcc | 2017-07-17 21:25:49 -0700 | [diff] [blame] | 1751 | if (ff->events) |
| 1752 | events = ff->events; |
| 1753 | else |
| 1754 | events = read_event_desc(ff); |
| 1755 | |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1756 | if (!events) { |
| 1757 | fprintf(fp, "# event desc: not available or unable to read\n"); |
| 1758 | return; |
| 1759 | } |
| 1760 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1761 | for (evsel = events; evsel->core.attr.size; evsel++) { |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1762 | fprintf(fp, "# event : name = %s, ", evsel->name); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1763 | |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 1764 | if (evsel->core.ids) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1765 | fprintf(fp, ", id = {"); |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 1766 | for (j = 0, id = evsel->core.id; j < evsel->core.ids; j++, id++) { |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1767 | if (j) |
| 1768 | fputc(',', fp); |
| 1769 | fprintf(fp, " %"PRIu64, *id); |
| 1770 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1771 | fprintf(fp, " }"); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1772 | } |
Peter Zijlstra | 814c8c3 | 2015-03-31 00:19:31 +0200 | [diff] [blame] | 1773 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1774 | perf_event_attr__fprintf(fp, &evsel->core.attr, __desc_attr__fprintf, NULL); |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1775 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1776 | fputc('\n', fp); |
| 1777 | } |
Robert Richter | 4e1b9c6 | 2012-08-16 21:10:22 +0200 | [diff] [blame] | 1778 | |
| 1779 | free_event_desc(events); |
David Carrillo-Cisneros | f9ebdcc | 2017-07-17 21:25:49 -0700 | [diff] [blame] | 1780 | ff->events = NULL; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1783 | static void print_total_mem(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1784 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1785 | fprintf(fp, "# total memory : %llu kB\n", ff->ph->env.total_mem); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1786 | } |
| 1787 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1788 | static void print_numa_topology(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1789 | { |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 1790 | int i; |
| 1791 | struct numa_node *n; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1792 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1793 | for (i = 0; i < ff->ph->env.nr_numa_nodes; i++) { |
| 1794 | n = &ff->ph->env.numa_nodes[i]; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1795 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1796 | fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB," |
| 1797 | " free = %"PRIu64" kB\n", |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 1798 | n->node, n->mem_total, n->mem_free); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1799 | |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 1800 | fprintf(fp, "# node%u cpu list : ", n->node); |
| 1801 | cpu_map__fprintf(n->map, fp); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1802 | } |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1803 | } |
| 1804 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1805 | static void print_cpuid(struct feat_fd *ff, FILE *fp) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1806 | { |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1807 | fprintf(fp, "# cpuid : %s\n", ff->ph->env.cpuid); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 1808 | } |
| 1809 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1810 | static void print_branch_stack(struct feat_fd *ff __maybe_unused, FILE *fp) |
Stephane Eranian | 330aa67 | 2012-03-08 23:47:46 +0100 | [diff] [blame] | 1811 | { |
| 1812 | fprintf(fp, "# contains samples with branch stack\n"); |
| 1813 | } |
| 1814 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1815 | static void print_auxtrace(struct feat_fd *ff __maybe_unused, FILE *fp) |
Adrian Hunter | 4025ea4 | 2015-04-09 18:53:41 +0300 | [diff] [blame] | 1816 | { |
| 1817 | fprintf(fp, "# contains AUX area data (e.g. instruction trace)\n"); |
| 1818 | } |
| 1819 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1820 | static void print_stat(struct feat_fd *ff __maybe_unused, FILE *fp) |
Jiri Olsa | ffa517a | 2015-10-25 15:51:43 +0100 | [diff] [blame] | 1821 | { |
| 1822 | fprintf(fp, "# contains stat data\n"); |
| 1823 | } |
| 1824 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1825 | static void print_cache(struct feat_fd *ff, FILE *fp __maybe_unused) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1826 | { |
| 1827 | int i; |
| 1828 | |
| 1829 | fprintf(fp, "# CPU cache info:\n"); |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1830 | for (i = 0; i < ff->ph->env.caches_cnt; i++) { |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1831 | fprintf(fp, "# "); |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1832 | cpu_cache_level__fprintf(fp, &ff->ph->env.caches[i]); |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 1833 | } |
| 1834 | } |
| 1835 | |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 1836 | static void print_compressed(struct feat_fd *ff, FILE *fp) |
| 1837 | { |
| 1838 | fprintf(fp, "# compressed : %s, level = %d, ratio = %d\n", |
| 1839 | ff->ph->env.comp_type == PERF_COMP_ZSTD ? "Zstd" : "Unknown", |
| 1840 | ff->ph->env.comp_level, ff->ph->env.comp_ratio); |
| 1841 | } |
| 1842 | |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 1843 | static void print_cpu_pmu_caps(struct feat_fd *ff, FILE *fp) |
| 1844 | { |
| 1845 | const char *delimiter = "# cpu pmu capabilities: "; |
| 1846 | u32 nr_caps = ff->ph->env.nr_cpu_pmu_caps; |
| 1847 | char *str; |
| 1848 | |
| 1849 | if (!nr_caps) { |
| 1850 | fprintf(fp, "# cpu pmu capabilities: not available\n"); |
| 1851 | return; |
| 1852 | } |
| 1853 | |
| 1854 | str = ff->ph->env.cpu_pmu_caps; |
| 1855 | while (nr_caps--) { |
| 1856 | fprintf(fp, "%s%s", delimiter, str); |
| 1857 | delimiter = ", "; |
| 1858 | str += strlen(str) + 1; |
| 1859 | } |
| 1860 | |
| 1861 | fprintf(fp, "\n"); |
| 1862 | } |
| 1863 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1864 | static void print_pmu_mappings(struct feat_fd *ff, FILE *fp) |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 1865 | { |
| 1866 | const char *delimiter = "# pmu mappings: "; |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1867 | char *str, *tmp; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 1868 | u32 pmu_num; |
| 1869 | u32 type; |
| 1870 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1871 | pmu_num = ff->ph->env.nr_pmu_mappings; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 1872 | if (!pmu_num) { |
| 1873 | fprintf(fp, "# pmu mappings: not available\n"); |
| 1874 | return; |
| 1875 | } |
| 1876 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1877 | str = ff->ph->env.pmu_mappings; |
Namhyung Kim | be4a2de | 2012-09-05 14:02:49 +0900 | [diff] [blame] | 1878 | |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1879 | while (pmu_num) { |
| 1880 | type = strtoul(str, &tmp, 0); |
| 1881 | if (*tmp != ':') |
| 1882 | goto error; |
| 1883 | |
| 1884 | str = tmp + 1; |
| 1885 | fprintf(fp, "%s%s = %" PRIu32, delimiter, str, type); |
| 1886 | |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 1887 | delimiter = ", "; |
Namhyung Kim | 7e94cfc | 2012-09-24 17:15:00 +0900 | [diff] [blame] | 1888 | str += strlen(str) + 1; |
| 1889 | pmu_num--; |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | fprintf(fp, "\n"); |
| 1893 | |
| 1894 | if (!pmu_num) |
| 1895 | return; |
| 1896 | error: |
| 1897 | fprintf(fp, "# pmu mappings: unable to read\n"); |
| 1898 | } |
| 1899 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1900 | static void print_group_desc(struct feat_fd *ff, FILE *fp) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1901 | { |
| 1902 | struct perf_session *session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1903 | struct evsel *evsel; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1904 | u32 nr = 0; |
| 1905 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 1906 | session = container_of(ff->ph, struct perf_session, header); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1907 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1908 | evlist__for_each_entry(session->evlist, evsel) { |
Arnaldo Carvalho de Melo | c754c38 | 2020-04-30 10:51:16 -0300 | [diff] [blame^] | 1909 | if (evsel__is_group_leader(evsel) && evsel->core.nr_members > 1) { |
Arnaldo Carvalho de Melo | 8ab2e96 | 2020-04-29 16:07:09 -0300 | [diff] [blame] | 1910 | fprintf(fp, "# group: %s{%s", evsel->group_name ?: "", evsel__name(evsel)); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1911 | |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 1912 | nr = evsel->core.nr_members - 1; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1913 | } else if (nr) { |
Arnaldo Carvalho de Melo | 8ab2e96 | 2020-04-29 16:07:09 -0300 | [diff] [blame] | 1914 | fprintf(fp, ",%s", evsel__name(evsel)); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 1915 | |
| 1916 | if (--nr == 0) |
| 1917 | fprintf(fp, "}\n"); |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 1922 | static void print_sample_time(struct feat_fd *ff, FILE *fp) |
| 1923 | { |
| 1924 | struct perf_session *session; |
| 1925 | char time_buf[32]; |
| 1926 | double d; |
| 1927 | |
| 1928 | session = container_of(ff->ph, struct perf_session, header); |
| 1929 | |
| 1930 | timestamp__scnprintf_usec(session->evlist->first_sample_time, |
| 1931 | time_buf, sizeof(time_buf)); |
| 1932 | fprintf(fp, "# time of first sample : %s\n", time_buf); |
| 1933 | |
| 1934 | timestamp__scnprintf_usec(session->evlist->last_sample_time, |
| 1935 | time_buf, sizeof(time_buf)); |
| 1936 | fprintf(fp, "# time of last sample : %s\n", time_buf); |
| 1937 | |
| 1938 | d = (double)(session->evlist->last_sample_time - |
| 1939 | session->evlist->first_sample_time) / NSEC_PER_MSEC; |
| 1940 | |
| 1941 | fprintf(fp, "# sample duration : %10.3f ms\n", d); |
| 1942 | } |
| 1943 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 1944 | static void memory_node__fprintf(struct memory_node *n, |
| 1945 | unsigned long long bsize, FILE *fp) |
| 1946 | { |
| 1947 | char buf_map[100], buf_size[50]; |
| 1948 | unsigned long long size; |
| 1949 | |
| 1950 | size = bsize * bitmap_weight(n->set, n->size); |
| 1951 | unit_number__scnprintf(buf_size, 50, size); |
| 1952 | |
| 1953 | bitmap_scnprintf(n->set, n->size, buf_map, 100); |
| 1954 | fprintf(fp, "# %3" PRIu64 " [%s]: %s\n", n->node, buf_size, buf_map); |
| 1955 | } |
| 1956 | |
| 1957 | static void print_mem_topology(struct feat_fd *ff, FILE *fp) |
| 1958 | { |
| 1959 | struct memory_node *nodes; |
| 1960 | int i, nr; |
| 1961 | |
| 1962 | nodes = ff->ph->env.memory_nodes; |
| 1963 | nr = ff->ph->env.nr_memory_nodes; |
| 1964 | |
| 1965 | fprintf(fp, "# memory nodes (nr %d, block size 0x%llx):\n", |
| 1966 | nr, ff->ph->env.memory_bsize); |
| 1967 | |
| 1968 | for (i = 0; i < nr; i++) { |
| 1969 | memory_node__fprintf(&nodes[i], ff->ph->env.memory_bsize, fp); |
| 1970 | } |
| 1971 | } |
| 1972 | |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 1973 | static int __event_process_build_id(struct perf_record_header_build_id *bev, |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1974 | char *filename, |
| 1975 | struct perf_session *session) |
| 1976 | { |
| 1977 | int err = -1; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1978 | struct machine *machine; |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 1979 | u16 cpumode; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1980 | struct dso *dso; |
| 1981 | enum dso_kernel_type dso_type; |
| 1982 | |
| 1983 | machine = perf_session__findnew_machine(session, bev->pid); |
| 1984 | if (!machine) |
| 1985 | goto out; |
| 1986 | |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 1987 | cpumode = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1988 | |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 1989 | switch (cpumode) { |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1990 | case PERF_RECORD_MISC_KERNEL: |
| 1991 | dso_type = DSO_TYPE_KERNEL; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1992 | break; |
| 1993 | case PERF_RECORD_MISC_GUEST_KERNEL: |
| 1994 | dso_type = DSO_TYPE_GUEST_KERNEL; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1995 | break; |
| 1996 | case PERF_RECORD_MISC_USER: |
| 1997 | case PERF_RECORD_MISC_GUEST_USER: |
| 1998 | dso_type = DSO_TYPE_USER; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 1999 | break; |
| 2000 | default: |
| 2001 | goto out; |
| 2002 | } |
| 2003 | |
Arnaldo Carvalho de Melo | aa7cc2a | 2015-05-29 11:31:12 -0300 | [diff] [blame] | 2004 | dso = machine__findnew_dso(machine, filename); |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2005 | if (dso != NULL) { |
Masami Hiramatsu | b5d8bbe | 2016-05-11 22:51:59 +0900 | [diff] [blame] | 2006 | char sbuild_id[SBUILD_ID_SIZE]; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2007 | |
| 2008 | dso__set_build_id(dso, &bev->build_id); |
| 2009 | |
Namhyung Kim | 1deec1b | 2017-05-31 21:01:03 +0900 | [diff] [blame] | 2010 | if (dso_type != DSO_TYPE_USER) { |
| 2011 | struct kmod_path m = { .name = NULL, }; |
| 2012 | |
| 2013 | if (!kmod_path__parse_name(&m, filename) && m.kmod) |
Namhyung Kim | 6b335e8 | 2017-05-31 21:01:04 +0900 | [diff] [blame] | 2014 | dso__set_module_info(dso, &m, machine); |
Namhyung Kim | 1deec1b | 2017-05-31 21:01:03 +0900 | [diff] [blame] | 2015 | else |
| 2016 | dso->kernel = dso_type; |
| 2017 | |
| 2018 | free(m.name); |
| 2019 | } |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2020 | |
| 2021 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), |
| 2022 | sbuild_id); |
| 2023 | pr_debug("build id event received for %s: %s\n", |
| 2024 | dso->long_name, sbuild_id); |
Arnaldo Carvalho de Melo | d3a7c48 | 2015-06-02 11:53:26 -0300 | [diff] [blame] | 2025 | dso__put(dso); |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | err = 0; |
| 2029 | out: |
| 2030 | return err; |
| 2031 | } |
| 2032 | |
| 2033 | static int perf_header__read_build_ids_abi_quirk(struct perf_header *header, |
| 2034 | int input, u64 offset, u64 size) |
| 2035 | { |
| 2036 | struct perf_session *session = container_of(header, struct perf_session, header); |
| 2037 | struct { |
| 2038 | struct perf_event_header header; |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 2039 | u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))]; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2040 | char filename[0]; |
| 2041 | } old_bev; |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 2042 | struct perf_record_header_build_id bev; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2043 | char filename[PATH_MAX]; |
| 2044 | u64 limit = offset + size; |
| 2045 | |
| 2046 | while (offset < limit) { |
| 2047 | ssize_t len; |
| 2048 | |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 2049 | if (readn(input, &old_bev, sizeof(old_bev)) != sizeof(old_bev)) |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2050 | return -1; |
| 2051 | |
| 2052 | if (header->needs_swap) |
| 2053 | perf_event_header__bswap(&old_bev.header); |
| 2054 | |
| 2055 | len = old_bev.header.size - sizeof(old_bev); |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 2056 | if (readn(input, filename, len) != len) |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2057 | return -1; |
| 2058 | |
| 2059 | bev.header = old_bev.header; |
| 2060 | |
| 2061 | /* |
| 2062 | * As the pid is the missing value, we need to fill |
| 2063 | * it properly. The header.misc value give us nice hint. |
| 2064 | */ |
| 2065 | bev.pid = HOST_KERNEL_ID; |
| 2066 | if (bev.header.misc == PERF_RECORD_MISC_GUEST_USER || |
| 2067 | bev.header.misc == PERF_RECORD_MISC_GUEST_KERNEL) |
| 2068 | bev.pid = DEFAULT_GUEST_KERNEL_ID; |
| 2069 | |
| 2070 | memcpy(bev.build_id, old_bev.build_id, sizeof(bev.build_id)); |
| 2071 | __event_process_build_id(&bev, filename, session); |
| 2072 | |
| 2073 | offset += bev.header.size; |
| 2074 | } |
| 2075 | |
| 2076 | return 0; |
| 2077 | } |
| 2078 | |
| 2079 | static int perf_header__read_build_ids(struct perf_header *header, |
| 2080 | int input, u64 offset, u64 size) |
| 2081 | { |
| 2082 | struct perf_session *session = container_of(header, struct perf_session, header); |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 2083 | struct perf_record_header_build_id bev; |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2084 | char filename[PATH_MAX]; |
| 2085 | u64 limit = offset + size, orig_offset = offset; |
| 2086 | int err = -1; |
| 2087 | |
| 2088 | while (offset < limit) { |
| 2089 | ssize_t len; |
| 2090 | |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 2091 | if (readn(input, &bev, sizeof(bev)) != sizeof(bev)) |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2092 | goto out; |
| 2093 | |
| 2094 | if (header->needs_swap) |
| 2095 | perf_event_header__bswap(&bev.header); |
| 2096 | |
| 2097 | len = bev.header.size - sizeof(bev); |
Namhyung Kim | 5323f60 | 2012-12-17 15:38:54 +0900 | [diff] [blame] | 2098 | if (readn(input, filename, len) != len) |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2099 | goto out; |
| 2100 | /* |
| 2101 | * The a1645ce1 changeset: |
| 2102 | * |
| 2103 | * "perf: 'perf kvm' tool for monitoring guest performance from host" |
| 2104 | * |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 2105 | * Added a field to struct perf_record_header_build_id that broke the file |
Robert Richter | 08d95bd | 2012-02-10 15:41:55 +0100 | [diff] [blame] | 2106 | * format. |
| 2107 | * |
| 2108 | * Since the kernel build-id is the first entry, process the |
| 2109 | * table using the old format if the well known |
| 2110 | * '[kernel.kallsyms]' string for the kernel build-id has the |
| 2111 | * first 4 characters chopped off (where the pid_t sits). |
| 2112 | */ |
| 2113 | if (memcmp(filename, "nel.kallsyms]", 13) == 0) { |
| 2114 | if (lseek(input, orig_offset, SEEK_SET) == (off_t)-1) |
| 2115 | return -1; |
| 2116 | return perf_header__read_build_ids_abi_quirk(header, input, offset, size); |
| 2117 | } |
| 2118 | |
| 2119 | __event_process_build_id(&bev, filename, session); |
| 2120 | |
| 2121 | offset += bev.header.size; |
| 2122 | } |
| 2123 | err = 0; |
| 2124 | out: |
| 2125 | return err; |
| 2126 | } |
| 2127 | |
David Carrillo-Cisneros | dfaa158 | 2017-07-17 21:25:35 -0700 | [diff] [blame] | 2128 | /* Macro for features that simply need to read and store a string. */ |
| 2129 | #define FEAT_PROCESS_STR_FUN(__feat, __feat_env) \ |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2130 | static int process_##__feat(struct feat_fd *ff, void *data __maybe_unused) \ |
David Carrillo-Cisneros | dfaa158 | 2017-07-17 21:25:35 -0700 | [diff] [blame] | 2131 | {\ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2132 | ff->ph->env.__feat_env = do_read_string(ff); \ |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2133 | return ff->ph->env.__feat_env ? 0 : -ENOMEM; \ |
David Carrillo-Cisneros | dfaa158 | 2017-07-17 21:25:35 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | FEAT_PROCESS_STR_FUN(hostname, hostname); |
| 2137 | FEAT_PROCESS_STR_FUN(osrelease, os_release); |
| 2138 | FEAT_PROCESS_STR_FUN(version, version); |
| 2139 | FEAT_PROCESS_STR_FUN(arch, arch); |
| 2140 | FEAT_PROCESS_STR_FUN(cpudesc, cpu_desc); |
| 2141 | FEAT_PROCESS_STR_FUN(cpuid, cpuid); |
| 2142 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2143 | static int process_tracing_data(struct feat_fd *ff, void *data) |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 2144 | { |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2145 | ssize_t ret = trace_report(ff->fd, data, false); |
| 2146 | |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 2147 | return ret < 0 ? -1 : 0; |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 2148 | } |
| 2149 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2150 | static int process_build_id(struct feat_fd *ff, void *data __maybe_unused) |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 2151 | { |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2152 | if (perf_header__read_build_ids(ff->ph, ff->fd, ff->offset, ff->size)) |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 2153 | pr_debug("Failed to read buildids, continuing...\n"); |
| 2154 | return 0; |
| 2155 | } |
| 2156 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2157 | static int process_nrcpus(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2158 | { |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 2159 | int ret; |
| 2160 | u32 nr_cpus_avail, nr_cpus_online; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2161 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2162 | ret = do_read_u32(ff, &nr_cpus_avail); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 2163 | if (ret) |
| 2164 | return ret; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2165 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2166 | ret = do_read_u32(ff, &nr_cpus_online); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 2167 | if (ret) |
| 2168 | return ret; |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2169 | ff->ph->env.nr_cpus_avail = (int)nr_cpus_avail; |
| 2170 | ff->ph->env.nr_cpus_online = (int)nr_cpus_online; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2171 | return 0; |
| 2172 | } |
| 2173 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2174 | static int process_total_mem(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2175 | { |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 2176 | u64 total_mem; |
| 2177 | int ret; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2178 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2179 | ret = do_read_u64(ff, &total_mem); |
David Carrillo-Cisneros | 6200e494 | 2017-07-17 21:25:34 -0700 | [diff] [blame] | 2180 | if (ret) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2181 | return -1; |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2182 | ff->ph->env.total_mem = (unsigned long long)total_mem; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2183 | return 0; |
| 2184 | } |
| 2185 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2186 | static struct evsel * |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2187 | perf_evlist__find_by_index(struct evlist *evlist, int idx) |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2188 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2189 | struct evsel *evsel; |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2190 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2191 | evlist__for_each_entry(evlist, evsel) { |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2192 | if (evsel->idx == idx) |
| 2193 | return evsel; |
| 2194 | } |
| 2195 | |
| 2196 | return NULL; |
| 2197 | } |
| 2198 | |
| 2199 | static void |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2200 | perf_evlist__set_event_name(struct evlist *evlist, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2201 | struct evsel *event) |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2202 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2203 | struct evsel *evsel; |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2204 | |
| 2205 | if (!event->name) |
| 2206 | return; |
| 2207 | |
| 2208 | evsel = perf_evlist__find_by_index(evlist, event->idx); |
| 2209 | if (!evsel) |
| 2210 | return; |
| 2211 | |
| 2212 | if (evsel->name) |
| 2213 | return; |
| 2214 | |
| 2215 | evsel->name = strdup(event->name); |
| 2216 | } |
| 2217 | |
| 2218 | static int |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2219 | process_event_desc(struct feat_fd *ff, void *data __maybe_unused) |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2220 | { |
Namhyung Kim | 3d7eb86 | 2012-09-24 17:15:01 +0900 | [diff] [blame] | 2221 | struct perf_session *session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2222 | struct evsel *evsel, *events = read_event_desc(ff); |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2223 | |
| 2224 | if (!events) |
| 2225 | return 0; |
| 2226 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2227 | session = container_of(ff->ph, struct perf_session, header); |
David Carrillo-Cisneros | f9ebdcc | 2017-07-17 21:25:49 -0700 | [diff] [blame] | 2228 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2229 | if (session->data->is_pipe) { |
David Carrillo-Cisneros | f9ebdcc | 2017-07-17 21:25:49 -0700 | [diff] [blame] | 2230 | /* Save events for reading later by print_event_desc, |
| 2231 | * since they can't be read again in pipe mode. */ |
| 2232 | ff->events = events; |
| 2233 | } |
| 2234 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2235 | for (evsel = events; evsel->core.attr.size; evsel++) |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2236 | perf_evlist__set_event_name(session->evlist, evsel); |
| 2237 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 2238 | if (!session->data->is_pipe) |
David Carrillo-Cisneros | f9ebdcc | 2017-07-17 21:25:49 -0700 | [diff] [blame] | 2239 | free_event_desc(events); |
Robert Richter | 7c2f7af | 2012-08-16 21:10:23 +0200 | [diff] [blame] | 2240 | |
| 2241 | return 0; |
| 2242 | } |
| 2243 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2244 | static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2245 | { |
Jiri Olsa | 768dd3f | 2015-07-21 14:31:31 +0200 | [diff] [blame] | 2246 | char *str, *cmdline = NULL, **argv = NULL; |
| 2247 | u32 nr, i, len = 0; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2248 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2249 | if (do_read_u32(ff, &nr)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2250 | return -1; |
| 2251 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2252 | ff->ph->env.nr_cmdline = nr; |
Jiri Olsa | 768dd3f | 2015-07-21 14:31:31 +0200 | [diff] [blame] | 2253 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2254 | cmdline = zalloc(ff->size + nr + 1); |
Jiri Olsa | 768dd3f | 2015-07-21 14:31:31 +0200 | [diff] [blame] | 2255 | if (!cmdline) |
| 2256 | return -1; |
| 2257 | |
| 2258 | argv = zalloc(sizeof(char *) * (nr + 1)); |
| 2259 | if (!argv) |
| 2260 | goto error; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2261 | |
| 2262 | for (i = 0; i < nr; i++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2263 | str = do_read_string(ff); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2264 | if (!str) |
| 2265 | goto error; |
| 2266 | |
Jiri Olsa | 768dd3f | 2015-07-21 14:31:31 +0200 | [diff] [blame] | 2267 | argv[i] = cmdline + len; |
| 2268 | memcpy(argv[i], str, strlen(str) + 1); |
| 2269 | len += strlen(str) + 1; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2270 | free(str); |
| 2271 | } |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2272 | ff->ph->env.cmdline = cmdline; |
| 2273 | ff->ph->env.cmdline_argv = (const char **) argv; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2274 | return 0; |
| 2275 | |
| 2276 | error: |
Jiri Olsa | 768dd3f | 2015-07-21 14:31:31 +0200 | [diff] [blame] | 2277 | free(argv); |
| 2278 | free(cmdline); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2279 | return -1; |
| 2280 | } |
| 2281 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2282 | static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2283 | { |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2284 | u32 nr, i; |
| 2285 | char *str; |
| 2286 | struct strbuf sb; |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2287 | int cpu_nr = ff->ph->env.nr_cpus_avail; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2288 | u64 size = 0; |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2289 | struct perf_header *ph = ff->ph; |
Thomas Richter | 0176622 | 2018-06-11 09:31:52 +0200 | [diff] [blame] | 2290 | bool do_core_id_test = true; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2291 | |
| 2292 | ph->env.cpu = calloc(cpu_nr, sizeof(*ph->env.cpu)); |
| 2293 | if (!ph->env.cpu) |
| 2294 | return -1; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2295 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2296 | if (do_read_u32(ff, &nr)) |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2297 | goto free_cpu; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2298 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2299 | ph->env.nr_sibling_cores = nr; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2300 | size += sizeof(u32); |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2301 | if (strbuf_init(&sb, 128) < 0) |
| 2302 | goto free_cpu; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2303 | |
| 2304 | for (i = 0; i < nr; i++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2305 | str = do_read_string(ff); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2306 | if (!str) |
| 2307 | goto error; |
| 2308 | |
| 2309 | /* include a NULL character at the end */ |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2310 | if (strbuf_add(&sb, str, strlen(str) + 1) < 0) |
| 2311 | goto error; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2312 | size += string_size(str); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2313 | free(str); |
| 2314 | } |
| 2315 | ph->env.sibling_cores = strbuf_detach(&sb, NULL); |
| 2316 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2317 | if (do_read_u32(ff, &nr)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2318 | return -1; |
| 2319 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2320 | ph->env.nr_sibling_threads = nr; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2321 | size += sizeof(u32); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2322 | |
| 2323 | for (i = 0; i < nr; i++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2324 | str = do_read_string(ff); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2325 | if (!str) |
| 2326 | goto error; |
| 2327 | |
| 2328 | /* include a NULL character at the end */ |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2329 | if (strbuf_add(&sb, str, strlen(str) + 1) < 0) |
| 2330 | goto error; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2331 | size += string_size(str); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2332 | free(str); |
| 2333 | } |
| 2334 | ph->env.sibling_threads = strbuf_detach(&sb, NULL); |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2335 | |
| 2336 | /* |
| 2337 | * The header may be from old perf, |
| 2338 | * which doesn't include core id and socket id information. |
| 2339 | */ |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2340 | if (ff->size <= size) { |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2341 | zfree(&ph->env.cpu); |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
Thomas Richter | 0176622 | 2018-06-11 09:31:52 +0200 | [diff] [blame] | 2345 | /* On s390 the socket_id number is not related to the numbers of cpus. |
| 2346 | * The socket_id number might be higher than the numbers of cpus. |
| 2347 | * This depends on the configuration. |
Tan Xiaojun | 0a4d8fb | 2019-08-02 11:48:57 +0800 | [diff] [blame] | 2348 | * AArch64 is the same. |
Thomas Richter | 0176622 | 2018-06-11 09:31:52 +0200 | [diff] [blame] | 2349 | */ |
Tan Xiaojun | 0a4d8fb | 2019-08-02 11:48:57 +0800 | [diff] [blame] | 2350 | if (ph->env.arch && (!strncmp(ph->env.arch, "s390", 4) |
| 2351 | || !strncmp(ph->env.arch, "aarch64", 7))) |
Thomas Richter | 0176622 | 2018-06-11 09:31:52 +0200 | [diff] [blame] | 2352 | do_core_id_test = false; |
| 2353 | |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2354 | for (i = 0; i < (u32)cpu_nr; i++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2355 | if (do_read_u32(ff, &nr)) |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2356 | goto free_cpu; |
| 2357 | |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2358 | ph->env.cpu[i].core_id = nr; |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 2359 | size += sizeof(u32); |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2360 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2361 | if (do_read_u32(ff, &nr)) |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2362 | goto free_cpu; |
| 2363 | |
Thomas Richter | 0176622 | 2018-06-11 09:31:52 +0200 | [diff] [blame] | 2364 | if (do_core_id_test && nr != (u32)-1 && nr > (u32)cpu_nr) { |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2365 | pr_debug("socket_id number is too big." |
| 2366 | "You may need to upgrade the perf tool.\n"); |
| 2367 | goto free_cpu; |
| 2368 | } |
| 2369 | |
| 2370 | ph->env.cpu[i].socket_id = nr; |
Kan Liang | acae8b3 | 2019-06-04 15:50:41 -0700 | [diff] [blame] | 2371 | size += sizeof(u32); |
| 2372 | } |
| 2373 | |
| 2374 | /* |
| 2375 | * The header may be from old perf, |
| 2376 | * which doesn't include die information. |
| 2377 | */ |
| 2378 | if (ff->size <= size) |
| 2379 | return 0; |
| 2380 | |
| 2381 | if (do_read_u32(ff, &nr)) |
| 2382 | return -1; |
| 2383 | |
| 2384 | ph->env.nr_sibling_dies = nr; |
| 2385 | size += sizeof(u32); |
| 2386 | |
| 2387 | for (i = 0; i < nr; i++) { |
| 2388 | str = do_read_string(ff); |
| 2389 | if (!str) |
| 2390 | goto error; |
| 2391 | |
| 2392 | /* include a NULL character at the end */ |
| 2393 | if (strbuf_add(&sb, str, strlen(str) + 1) < 0) |
| 2394 | goto error; |
| 2395 | size += string_size(str); |
| 2396 | free(str); |
| 2397 | } |
| 2398 | ph->env.sibling_dies = strbuf_detach(&sb, NULL); |
| 2399 | |
| 2400 | for (i = 0; i < (u32)cpu_nr; i++) { |
| 2401 | if (do_read_u32(ff, &nr)) |
| 2402 | goto free_cpu; |
| 2403 | |
| 2404 | ph->env.cpu[i].die_id = nr; |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2405 | } |
| 2406 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2407 | return 0; |
| 2408 | |
| 2409 | error: |
| 2410 | strbuf_release(&sb); |
Kan Liang | 2bb00d2 | 2015-09-01 09:58:12 -0400 | [diff] [blame] | 2411 | free_cpu: |
| 2412 | zfree(&ph->env.cpu); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2413 | return -1; |
| 2414 | } |
| 2415 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2416 | static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2417 | { |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2418 | struct numa_node *nodes, *n; |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2419 | u32 nr, i; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2420 | char *str; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2421 | |
| 2422 | /* nr nodes */ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2423 | if (do_read_u32(ff, &nr)) |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2424 | return -1; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2425 | |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2426 | nodes = zalloc(sizeof(*nodes) * nr); |
| 2427 | if (!nodes) |
| 2428 | return -ENOMEM; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2429 | |
| 2430 | for (i = 0; i < nr; i++) { |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2431 | n = &nodes[i]; |
| 2432 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2433 | /* node number */ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2434 | if (do_read_u32(ff, &n->node)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2435 | goto error; |
| 2436 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2437 | if (do_read_u64(ff, &n->mem_total)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2438 | goto error; |
| 2439 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2440 | if (do_read_u64(ff, &n->mem_free)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2441 | goto error; |
| 2442 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2443 | str = do_read_string(ff); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2444 | if (!str) |
| 2445 | goto error; |
| 2446 | |
Jiri Olsa | 9c3516d | 2019-07-21 13:24:30 +0200 | [diff] [blame] | 2447 | n->map = perf_cpu_map__new(str); |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2448 | if (!n->map) |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2449 | goto error; |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2450 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2451 | free(str); |
| 2452 | } |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2453 | ff->ph->env.nr_numa_nodes = nr; |
| 2454 | ff->ph->env.numa_nodes = nodes; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2455 | return 0; |
| 2456 | |
| 2457 | error: |
Jiri Olsa | c60da22 | 2016-07-04 14:16:20 +0200 | [diff] [blame] | 2458 | free(nodes); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2459 | return -1; |
| 2460 | } |
| 2461 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2462 | static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2463 | { |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2464 | char *name; |
| 2465 | u32 pmu_num; |
| 2466 | u32 type; |
| 2467 | struct strbuf sb; |
| 2468 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2469 | if (do_read_u32(ff, &pmu_num)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2470 | return -1; |
| 2471 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2472 | if (!pmu_num) { |
| 2473 | pr_debug("pmu mappings not available\n"); |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2477 | ff->ph->env.nr_pmu_mappings = pmu_num; |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2478 | if (strbuf_init(&sb, 128) < 0) |
| 2479 | return -1; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2480 | |
| 2481 | while (pmu_num) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2482 | if (do_read_u32(ff, &type)) |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2483 | goto error; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2484 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2485 | name = do_read_string(ff); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2486 | if (!name) |
| 2487 | goto error; |
| 2488 | |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2489 | if (strbuf_addf(&sb, "%u:%s", type, name) < 0) |
| 2490 | goto error; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2491 | /* include a NULL character at the end */ |
Masami Hiramatsu | 642aada | 2016-05-10 14:47:35 +0900 | [diff] [blame] | 2492 | if (strbuf_add(&sb, "", 1) < 0) |
| 2493 | goto error; |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2494 | |
Kan Liang | e0838e0 | 2015-09-10 11:03:05 -0300 | [diff] [blame] | 2495 | if (!strcmp(name, "msr")) |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2496 | ff->ph->env.msr_pmu_type = type; |
Kan Liang | e0838e0 | 2015-09-10 11:03:05 -0300 | [diff] [blame] | 2497 | |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2498 | free(name); |
| 2499 | pmu_num--; |
| 2500 | } |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2501 | ff->ph->env.pmu_mappings = strbuf_detach(&sb, NULL); |
Namhyung Kim | a1ae565 | 2012-09-24 17:14:59 +0900 | [diff] [blame] | 2502 | return 0; |
| 2503 | |
| 2504 | error: |
| 2505 | strbuf_release(&sb); |
| 2506 | return -1; |
| 2507 | } |
| 2508 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2509 | static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2510 | { |
| 2511 | size_t ret = -1; |
| 2512 | u32 i, nr, nr_groups; |
| 2513 | struct perf_session *session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2514 | struct evsel *evsel, *leader = NULL; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2515 | struct group_desc { |
| 2516 | char *name; |
| 2517 | u32 leader_idx; |
| 2518 | u32 nr_members; |
| 2519 | } *desc; |
| 2520 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2521 | if (do_read_u32(ff, &nr_groups)) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2522 | return -1; |
| 2523 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2524 | ff->ph->env.nr_groups = nr_groups; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2525 | if (!nr_groups) { |
| 2526 | pr_debug("group desc not available\n"); |
| 2527 | return 0; |
| 2528 | } |
| 2529 | |
| 2530 | desc = calloc(nr_groups, sizeof(*desc)); |
| 2531 | if (!desc) |
| 2532 | return -1; |
| 2533 | |
| 2534 | for (i = 0; i < nr_groups; i++) { |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2535 | desc[i].name = do_read_string(ff); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2536 | if (!desc[i].name) |
| 2537 | goto out_free; |
| 2538 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2539 | if (do_read_u32(ff, &desc[i].leader_idx)) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2540 | goto out_free; |
| 2541 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2542 | if (do_read_u32(ff, &desc[i].nr_members)) |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2543 | goto out_free; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | /* |
| 2547 | * Rebuild group relationship based on the group_desc |
| 2548 | */ |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2549 | session = container_of(ff->ph, struct perf_session, header); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2550 | session->evlist->nr_groups = nr_groups; |
| 2551 | |
| 2552 | i = nr = 0; |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2553 | evlist__for_each_entry(session->evlist, evsel) { |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2554 | if (evsel->idx == (int) desc[i].leader_idx) { |
| 2555 | evsel->leader = evsel; |
| 2556 | /* {anon_group} is a dummy name */ |
Namhyung Kim | 210e812 | 2013-11-18 11:20:43 +0900 | [diff] [blame] | 2557 | if (strcmp(desc[i].name, "{anon_group}")) { |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2558 | evsel->group_name = desc[i].name; |
Namhyung Kim | 210e812 | 2013-11-18 11:20:43 +0900 | [diff] [blame] | 2559 | desc[i].name = NULL; |
| 2560 | } |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 2561 | evsel->core.nr_members = desc[i].nr_members; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2562 | |
| 2563 | if (i >= nr_groups || nr > 0) { |
| 2564 | pr_debug("invalid group desc\n"); |
| 2565 | goto out_free; |
| 2566 | } |
| 2567 | |
| 2568 | leader = evsel; |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 2569 | nr = evsel->core.nr_members - 1; |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2570 | i++; |
| 2571 | } else if (nr) { |
| 2572 | /* This is a group member */ |
| 2573 | evsel->leader = leader; |
| 2574 | |
| 2575 | nr--; |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | if (i != nr_groups || nr != 0) { |
| 2580 | pr_debug("invalid group desc\n"); |
| 2581 | goto out_free; |
| 2582 | } |
| 2583 | |
| 2584 | ret = 0; |
| 2585 | out_free: |
Namhyung Kim | 50a2740 | 2013-11-18 11:20:44 +0900 | [diff] [blame] | 2586 | for (i = 0; i < nr_groups; i++) |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 2587 | zfree(&desc[i].name); |
Namhyung Kim | a8bb559 | 2013-01-22 18:09:31 +0900 | [diff] [blame] | 2588 | free(desc); |
| 2589 | |
| 2590 | return ret; |
| 2591 | } |
| 2592 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2593 | static int process_auxtrace(struct feat_fd *ff, void *data __maybe_unused) |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 2594 | { |
| 2595 | struct perf_session *session; |
| 2596 | int err; |
| 2597 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2598 | session = container_of(ff->ph, struct perf_session, header); |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 2599 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2600 | err = auxtrace_index__process(ff->fd, ff->size, session, |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2601 | ff->ph->needs_swap); |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 2602 | if (err < 0) |
| 2603 | pr_err("Failed to process auxtrace index\n"); |
| 2604 | return err; |
| 2605 | } |
| 2606 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 2607 | static int process_cache(struct feat_fd *ff, void *data __maybe_unused) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2608 | { |
| 2609 | struct cpu_cache_level *caches; |
| 2610 | u32 cnt, i, version; |
| 2611 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2612 | if (do_read_u32(ff, &version)) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2613 | return -1; |
| 2614 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2615 | if (version != 1) |
| 2616 | return -1; |
| 2617 | |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2618 | if (do_read_u32(ff, &cnt)) |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2619 | return -1; |
| 2620 | |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2621 | caches = zalloc(sizeof(*caches) * cnt); |
| 2622 | if (!caches) |
| 2623 | return -1; |
| 2624 | |
| 2625 | for (i = 0; i < cnt; i++) { |
| 2626 | struct cpu_cache_level c; |
| 2627 | |
| 2628 | #define _R(v) \ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2629 | if (do_read_u32(ff, &c.v))\ |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2630 | goto out_free_caches; \ |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2631 | |
| 2632 | _R(level) |
| 2633 | _R(line_size) |
| 2634 | _R(sets) |
| 2635 | _R(ways) |
| 2636 | #undef _R |
| 2637 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2638 | #define _R(v) \ |
David Carrillo-Cisneros | 48e5fce | 2017-07-17 21:25:43 -0700 | [diff] [blame] | 2639 | c.v = do_read_string(ff); \ |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2640 | if (!c.v) \ |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2641 | goto out_free_caches; |
| 2642 | |
| 2643 | _R(type) |
| 2644 | _R(size) |
| 2645 | _R(map) |
| 2646 | #undef _R |
| 2647 | |
| 2648 | caches[i] = c; |
| 2649 | } |
| 2650 | |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 2651 | ff->ph->env.caches = caches; |
| 2652 | ff->ph->env.caches_cnt = cnt; |
Jiri Olsa | 720e98b | 2016-02-16 16:01:43 +0100 | [diff] [blame] | 2653 | return 0; |
| 2654 | out_free_caches: |
| 2655 | free(caches); |
| 2656 | return -1; |
| 2657 | } |
| 2658 | |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 2659 | static int process_sample_time(struct feat_fd *ff, void *data __maybe_unused) |
| 2660 | { |
| 2661 | struct perf_session *session; |
| 2662 | u64 first_sample_time, last_sample_time; |
| 2663 | int ret; |
| 2664 | |
| 2665 | session = container_of(ff->ph, struct perf_session, header); |
| 2666 | |
| 2667 | ret = do_read_u64(ff, &first_sample_time); |
| 2668 | if (ret) |
| 2669 | return -1; |
| 2670 | |
| 2671 | ret = do_read_u64(ff, &last_sample_time); |
| 2672 | if (ret) |
| 2673 | return -1; |
| 2674 | |
| 2675 | session->evlist->first_sample_time = first_sample_time; |
| 2676 | session->evlist->last_sample_time = last_sample_time; |
| 2677 | return 0; |
| 2678 | } |
| 2679 | |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 2680 | static int process_mem_topology(struct feat_fd *ff, |
| 2681 | void *data __maybe_unused) |
| 2682 | { |
| 2683 | struct memory_node *nodes; |
| 2684 | u64 version, i, nr, bsize; |
| 2685 | int ret = -1; |
| 2686 | |
| 2687 | if (do_read_u64(ff, &version)) |
| 2688 | return -1; |
| 2689 | |
| 2690 | if (version != 1) |
| 2691 | return -1; |
| 2692 | |
| 2693 | if (do_read_u64(ff, &bsize)) |
| 2694 | return -1; |
| 2695 | |
| 2696 | if (do_read_u64(ff, &nr)) |
| 2697 | return -1; |
| 2698 | |
| 2699 | nodes = zalloc(sizeof(*nodes) * nr); |
| 2700 | if (!nodes) |
| 2701 | return -1; |
| 2702 | |
| 2703 | for (i = 0; i < nr; i++) { |
| 2704 | struct memory_node n; |
| 2705 | |
| 2706 | #define _R(v) \ |
| 2707 | if (do_read_u64(ff, &n.v)) \ |
| 2708 | goto out; \ |
| 2709 | |
| 2710 | _R(node) |
| 2711 | _R(size) |
| 2712 | |
| 2713 | #undef _R |
| 2714 | |
| 2715 | if (do_read_bitmap(ff, &n.set, &n.size)) |
| 2716 | goto out; |
| 2717 | |
| 2718 | nodes[i] = n; |
| 2719 | } |
| 2720 | |
| 2721 | ff->ph->env.memory_bsize = bsize; |
| 2722 | ff->ph->env.memory_nodes = nodes; |
| 2723 | ff->ph->env.nr_memory_nodes = nr; |
| 2724 | ret = 0; |
| 2725 | |
| 2726 | out: |
| 2727 | if (ret) |
| 2728 | free(nodes); |
| 2729 | return ret; |
| 2730 | } |
| 2731 | |
Alexey Budankov | cf79051 | 2018-10-09 17:36:24 +0300 | [diff] [blame] | 2732 | static int process_clockid(struct feat_fd *ff, |
| 2733 | void *data __maybe_unused) |
| 2734 | { |
| 2735 | if (do_read_u64(ff, &ff->ph->env.clockid_res_ns)) |
| 2736 | return -1; |
| 2737 | |
| 2738 | return 0; |
| 2739 | } |
| 2740 | |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 2741 | static int process_dir_format(struct feat_fd *ff, |
| 2742 | void *_data __maybe_unused) |
| 2743 | { |
| 2744 | struct perf_session *session; |
| 2745 | struct perf_data *data; |
| 2746 | |
| 2747 | session = container_of(ff->ph, struct perf_session, header); |
| 2748 | data = session->data; |
| 2749 | |
| 2750 | if (WARN_ON(!perf_data__is_dir(data))) |
| 2751 | return -1; |
| 2752 | |
| 2753 | return do_read_u64(ff, &data->dir.version); |
| 2754 | } |
| 2755 | |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 2756 | #ifdef HAVE_LIBBPF_SUPPORT |
| 2757 | static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_unused) |
| 2758 | { |
| 2759 | struct bpf_prog_info_linear *info_linear; |
| 2760 | struct bpf_prog_info_node *info_node; |
| 2761 | struct perf_env *env = &ff->ph->env; |
| 2762 | u32 count, i; |
| 2763 | int err = -1; |
| 2764 | |
| 2765 | if (ff->ph->needs_swap) { |
| 2766 | pr_warning("interpreting bpf_prog_info from systems with endianity is not yet supported\n"); |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | if (do_read_u32(ff, &count)) |
| 2771 | return -1; |
| 2772 | |
| 2773 | down_write(&env->bpf_progs.lock); |
| 2774 | |
| 2775 | for (i = 0; i < count; ++i) { |
| 2776 | u32 info_len, data_len; |
| 2777 | |
| 2778 | info_linear = NULL; |
| 2779 | info_node = NULL; |
| 2780 | if (do_read_u32(ff, &info_len)) |
| 2781 | goto out; |
| 2782 | if (do_read_u32(ff, &data_len)) |
| 2783 | goto out; |
| 2784 | |
| 2785 | if (info_len > sizeof(struct bpf_prog_info)) { |
| 2786 | pr_warning("detected invalid bpf_prog_info\n"); |
| 2787 | goto out; |
| 2788 | } |
| 2789 | |
| 2790 | info_linear = malloc(sizeof(struct bpf_prog_info_linear) + |
| 2791 | data_len); |
| 2792 | if (!info_linear) |
| 2793 | goto out; |
| 2794 | info_linear->info_len = sizeof(struct bpf_prog_info); |
| 2795 | info_linear->data_len = data_len; |
| 2796 | if (do_read_u64(ff, (u64 *)(&info_linear->arrays))) |
| 2797 | goto out; |
| 2798 | if (__do_read(ff, &info_linear->info, info_len)) |
| 2799 | goto out; |
| 2800 | if (info_len < sizeof(struct bpf_prog_info)) |
| 2801 | memset(((void *)(&info_linear->info)) + info_len, 0, |
| 2802 | sizeof(struct bpf_prog_info) - info_len); |
| 2803 | |
| 2804 | if (__do_read(ff, info_linear->data, data_len)) |
| 2805 | goto out; |
| 2806 | |
| 2807 | info_node = malloc(sizeof(struct bpf_prog_info_node)); |
| 2808 | if (!info_node) |
| 2809 | goto out; |
| 2810 | |
| 2811 | /* after reading from file, translate offset to address */ |
| 2812 | bpf_program__bpil_offs_to_addr(info_linear); |
| 2813 | info_node->info_linear = info_linear; |
| 2814 | perf_env__insert_bpf_prog_info(env, info_node); |
| 2815 | } |
| 2816 | |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2817 | up_write(&env->bpf_progs.lock); |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 2818 | return 0; |
| 2819 | out: |
| 2820 | free(info_linear); |
| 2821 | free(info_node); |
| 2822 | up_write(&env->bpf_progs.lock); |
| 2823 | return err; |
| 2824 | } |
| 2825 | #else // HAVE_LIBBPF_SUPPORT |
| 2826 | static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *data __maybe_unused) |
| 2827 | { |
| 2828 | return 0; |
| 2829 | } |
| 2830 | #endif // HAVE_LIBBPF_SUPPORT |
| 2831 | |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2832 | static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused) |
| 2833 | { |
| 2834 | struct perf_env *env = &ff->ph->env; |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2835 | struct btf_node *node = NULL; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2836 | u32 count, i; |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2837 | int err = -1; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2838 | |
| 2839 | if (ff->ph->needs_swap) { |
| 2840 | pr_warning("interpreting btf from systems with endianity is not yet supported\n"); |
| 2841 | return 0; |
| 2842 | } |
| 2843 | |
| 2844 | if (do_read_u32(ff, &count)) |
| 2845 | return -1; |
| 2846 | |
| 2847 | down_write(&env->bpf_progs.lock); |
| 2848 | |
| 2849 | for (i = 0; i < count; ++i) { |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2850 | u32 id, data_size; |
| 2851 | |
| 2852 | if (do_read_u32(ff, &id)) |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2853 | goto out; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2854 | if (do_read_u32(ff, &data_size)) |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2855 | goto out; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2856 | |
| 2857 | node = malloc(sizeof(struct btf_node) + data_size); |
| 2858 | if (!node) |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2859 | goto out; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2860 | |
| 2861 | node->id = id; |
| 2862 | node->data_size = data_size; |
| 2863 | |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2864 | if (__do_read(ff, node->data, data_size)) |
| 2865 | goto out; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2866 | |
| 2867 | perf_env__insert_btf(env, node); |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2868 | node = NULL; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2871 | err = 0; |
| 2872 | out: |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2873 | up_write(&env->bpf_progs.lock); |
Gustavo A. R. Silva | 14c9b31 | 2019-04-08 12:33:55 -0500 | [diff] [blame] | 2874 | free(node); |
| 2875 | return err; |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 2878 | static int process_compressed(struct feat_fd *ff, |
| 2879 | void *data __maybe_unused) |
| 2880 | { |
| 2881 | if (do_read_u32(ff, &(ff->ph->env.comp_ver))) |
| 2882 | return -1; |
| 2883 | |
| 2884 | if (do_read_u32(ff, &(ff->ph->env.comp_type))) |
| 2885 | return -1; |
| 2886 | |
| 2887 | if (do_read_u32(ff, &(ff->ph->env.comp_level))) |
| 2888 | return -1; |
| 2889 | |
| 2890 | if (do_read_u32(ff, &(ff->ph->env.comp_ratio))) |
| 2891 | return -1; |
| 2892 | |
| 2893 | if (do_read_u32(ff, &(ff->ph->env.comp_mmap_len))) |
| 2894 | return -1; |
| 2895 | |
| 2896 | return 0; |
| 2897 | } |
| 2898 | |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 2899 | static int process_cpu_pmu_caps(struct feat_fd *ff, |
| 2900 | void *data __maybe_unused) |
| 2901 | { |
| 2902 | char *name, *value; |
| 2903 | struct strbuf sb; |
| 2904 | u32 nr_caps; |
| 2905 | |
| 2906 | if (do_read_u32(ff, &nr_caps)) |
| 2907 | return -1; |
| 2908 | |
| 2909 | if (!nr_caps) { |
| 2910 | pr_debug("cpu pmu capabilities not available\n"); |
| 2911 | return 0; |
| 2912 | } |
| 2913 | |
| 2914 | ff->ph->env.nr_cpu_pmu_caps = nr_caps; |
| 2915 | |
| 2916 | if (strbuf_init(&sb, 128) < 0) |
| 2917 | return -1; |
| 2918 | |
| 2919 | while (nr_caps--) { |
| 2920 | name = do_read_string(ff); |
| 2921 | if (!name) |
| 2922 | goto error; |
| 2923 | |
| 2924 | value = do_read_string(ff); |
| 2925 | if (!value) |
| 2926 | goto free_name; |
| 2927 | |
| 2928 | if (strbuf_addf(&sb, "%s=%s", name, value) < 0) |
| 2929 | goto free_value; |
| 2930 | |
| 2931 | /* include a NULL character at the end */ |
| 2932 | if (strbuf_add(&sb, "", 1) < 0) |
| 2933 | goto free_value; |
| 2934 | |
| 2935 | if (!strcmp(name, "branches")) |
| 2936 | ff->ph->env.max_branches = atoi(value); |
| 2937 | |
| 2938 | free(value); |
| 2939 | free(name); |
| 2940 | } |
| 2941 | ff->ph->env.cpu_pmu_caps = strbuf_detach(&sb, NULL); |
| 2942 | return 0; |
| 2943 | |
| 2944 | free_value: |
| 2945 | free(value); |
| 2946 | free_name: |
| 2947 | free(name); |
| 2948 | error: |
| 2949 | strbuf_release(&sb); |
| 2950 | return -1; |
| 2951 | } |
| 2952 | |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 2953 | #define FEAT_OPR(n, func, __full_only) \ |
| 2954 | [HEADER_##n] = { \ |
| 2955 | .name = __stringify(n), \ |
| 2956 | .write = write_##func, \ |
| 2957 | .print = print_##func, \ |
| 2958 | .full_only = __full_only, \ |
| 2959 | .process = process_##func, \ |
| 2960 | .synthesize = true \ |
| 2961 | } |
| 2962 | |
| 2963 | #define FEAT_OPN(n, func, __full_only) \ |
| 2964 | [HEADER_##n] = { \ |
| 2965 | .name = __stringify(n), \ |
| 2966 | .write = write_##func, \ |
| 2967 | .print = print_##func, \ |
| 2968 | .full_only = __full_only, \ |
| 2969 | .process = process_##func \ |
| 2970 | } |
Robert Richter | 8cdfa78 | 2011-12-07 10:02:56 +0100 | [diff] [blame] | 2971 | |
| 2972 | /* feature_ops not implemented: */ |
Stephane Eranian | 2eeaaa0 | 2012-05-15 13:28:13 +0200 | [diff] [blame] | 2973 | #define print_tracing_data NULL |
| 2974 | #define print_build_id NULL |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 2975 | |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 2976 | #define process_branch_stack NULL |
| 2977 | #define process_stat NULL |
| 2978 | |
Arnaldo Carvalho de Melo | 055c67e | 2019-09-18 16:08:52 -0300 | [diff] [blame] | 2979 | // Only used in util/synthetic-events.c |
| 2980 | const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE]; |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 2981 | |
Arnaldo Carvalho de Melo | 055c67e | 2019-09-18 16:08:52 -0300 | [diff] [blame] | 2982 | const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE] = { |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 2983 | FEAT_OPN(TRACING_DATA, tracing_data, false), |
| 2984 | FEAT_OPN(BUILD_ID, build_id, false), |
| 2985 | FEAT_OPR(HOSTNAME, hostname, false), |
| 2986 | FEAT_OPR(OSRELEASE, osrelease, false), |
| 2987 | FEAT_OPR(VERSION, version, false), |
| 2988 | FEAT_OPR(ARCH, arch, false), |
| 2989 | FEAT_OPR(NRCPUS, nrcpus, false), |
| 2990 | FEAT_OPR(CPUDESC, cpudesc, false), |
| 2991 | FEAT_OPR(CPUID, cpuid, false), |
| 2992 | FEAT_OPR(TOTAL_MEM, total_mem, false), |
| 2993 | FEAT_OPR(EVENT_DESC, event_desc, false), |
| 2994 | FEAT_OPR(CMDLINE, cmdline, false), |
| 2995 | FEAT_OPR(CPU_TOPOLOGY, cpu_topology, true), |
| 2996 | FEAT_OPR(NUMA_TOPOLOGY, numa_topology, true), |
| 2997 | FEAT_OPN(BRANCH_STACK, branch_stack, false), |
| 2998 | FEAT_OPR(PMU_MAPPINGS, pmu_mappings, false), |
Jiri Olsa | e8fedff | 2018-07-12 15:52:02 +0200 | [diff] [blame] | 2999 | FEAT_OPR(GROUP_DESC, group_desc, false), |
David Carrillo-Cisneros | a4d8c98 | 2017-07-17 21:25:46 -0700 | [diff] [blame] | 3000 | FEAT_OPN(AUXTRACE, auxtrace, false), |
| 3001 | FEAT_OPN(STAT, stat, false), |
| 3002 | FEAT_OPN(CACHE, cache, true), |
Jin Yao | 6011518 | 2017-12-08 21:13:41 +0800 | [diff] [blame] | 3003 | FEAT_OPR(SAMPLE_TIME, sample_time, false), |
Jiri Olsa | e2091ce | 2018-03-07 16:50:08 +0100 | [diff] [blame] | 3004 | FEAT_OPR(MEM_TOPOLOGY, mem_topology, true), |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 3005 | FEAT_OPR(CLOCKID, clockid, false), |
Song Liu | 606f972 | 2019-03-11 22:30:43 -0700 | [diff] [blame] | 3006 | FEAT_OPN(DIR_FORMAT, dir_format, false), |
Song Liu | a70a11231 | 2019-03-11 22:30:45 -0700 | [diff] [blame] | 3007 | FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false), |
| 3008 | FEAT_OPR(BPF_BTF, bpf_btf, false), |
Alexey Budankov | 42e1fd8 | 2019-03-18 20:41:33 +0300 | [diff] [blame] | 3009 | FEAT_OPR(COMPRESSED, compressed, false), |
Kan Liang | 6f91ea2 | 2020-03-19 13:25:02 -0700 | [diff] [blame] | 3010 | FEAT_OPR(CPU_PMU_CAPS, cpu_pmu_caps, false), |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3011 | }; |
| 3012 | |
| 3013 | struct header_print_data { |
| 3014 | FILE *fp; |
| 3015 | bool full; /* extended list of headers */ |
| 3016 | }; |
| 3017 | |
| 3018 | static int perf_file_section__fprintf_info(struct perf_file_section *section, |
| 3019 | struct perf_header *ph, |
| 3020 | int feat, int fd, void *data) |
| 3021 | { |
| 3022 | struct header_print_data *hd = data; |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 3023 | struct feat_fd ff; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3024 | |
| 3025 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { |
| 3026 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " |
| 3027 | "%d, continuing...\n", section->offset, feat); |
| 3028 | return 0; |
| 3029 | } |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3030 | if (feat >= HEADER_LAST_FEATURE) { |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3031 | pr_warning("unknown feature %d\n", feat); |
Robert Richter | f7a8a13 | 2011-12-07 10:02:51 +0100 | [diff] [blame] | 3032 | return 0; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3033 | } |
| 3034 | if (!feat_ops[feat].print) |
| 3035 | return 0; |
| 3036 | |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 3037 | ff = (struct feat_fd) { |
| 3038 | .fd = fd, |
| 3039 | .ph = ph, |
| 3040 | }; |
| 3041 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3042 | if (!feat_ops[feat].full_only || hd->full) |
David Carrillo-Cisneros | cfc6542 | 2017-07-17 21:25:40 -0700 | [diff] [blame] | 3043 | feat_ops[feat].print(&ff, hd->fp); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3044 | else |
| 3045 | fprintf(hd->fp, "# %s info available, use -I to display\n", |
| 3046 | feat_ops[feat].name); |
| 3047 | |
| 3048 | return 0; |
| 3049 | } |
| 3050 | |
| 3051 | int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full) |
| 3052 | { |
| 3053 | struct header_print_data hd; |
| 3054 | struct perf_header *header = &session->header; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3055 | int fd = perf_data__fd(session->data); |
Jiri Olsa | f45f561 | 2016-10-10 09:03:07 +0200 | [diff] [blame] | 3056 | struct stat st; |
Arnaldo Carvalho de Melo | 0afcf29 | 2018-12-11 16:11:54 -0300 | [diff] [blame] | 3057 | time_t stctime; |
Jiri Olsa | aabae16 | 2016-10-10 09:35:50 +0200 | [diff] [blame] | 3058 | int ret, bit; |
Jiri Olsa | f45f561 | 2016-10-10 09:03:07 +0200 | [diff] [blame] | 3059 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3060 | hd.fp = fp; |
| 3061 | hd.full = full; |
| 3062 | |
Jiri Olsa | f45f561 | 2016-10-10 09:03:07 +0200 | [diff] [blame] | 3063 | ret = fstat(fd, &st); |
| 3064 | if (ret == -1) |
| 3065 | return -1; |
| 3066 | |
Michael Petlan | 8af19d6 | 2020-01-14 11:42:36 +0100 | [diff] [blame] | 3067 | stctime = st.st_mtime; |
Arnaldo Carvalho de Melo | 0afcf29 | 2018-12-11 16:11:54 -0300 | [diff] [blame] | 3068 | fprintf(fp, "# captured on : %s", ctime(&stctime)); |
Jiri Olsa | e971a5a | 2018-03-07 16:50:03 +0100 | [diff] [blame] | 3069 | |
| 3070 | fprintf(fp, "# header version : %u\n", header->version); |
| 3071 | fprintf(fp, "# data offset : %" PRIu64 "\n", header->data_offset); |
| 3072 | fprintf(fp, "# data size : %" PRIu64 "\n", header->data_size); |
| 3073 | fprintf(fp, "# feat offset : %" PRIu64 "\n", header->feat_offset); |
Jiri Olsa | f45f561 | 2016-10-10 09:03:07 +0200 | [diff] [blame] | 3074 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3075 | perf_header__process_sections(header, fd, &hd, |
| 3076 | perf_file_section__fprintf_info); |
Jiri Olsa | aabae16 | 2016-10-10 09:35:50 +0200 | [diff] [blame] | 3077 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3078 | if (session->data->is_pipe) |
David Carrillo-Cisneros | c9d1c93 | 2017-04-10 13:14:32 -0700 | [diff] [blame] | 3079 | return 0; |
| 3080 | |
Jiri Olsa | aabae16 | 2016-10-10 09:35:50 +0200 | [diff] [blame] | 3081 | fprintf(fp, "# missing features: "); |
| 3082 | for_each_clear_bit(bit, header->adds_features, HEADER_LAST_FEATURE) { |
| 3083 | if (bit) |
| 3084 | fprintf(fp, "%s ", feat_ops[bit].name); |
| 3085 | } |
| 3086 | |
| 3087 | fprintf(fp, "\n"); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3088 | return 0; |
| 3089 | } |
| 3090 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3091 | static int do_write_feat(struct feat_fd *ff, int type, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3092 | struct perf_file_section **p, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3093 | struct evlist *evlist) |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3094 | { |
| 3095 | int err; |
| 3096 | int ret = 0; |
| 3097 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3098 | if (perf_header__has_feat(ff->ph, type)) { |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3099 | if (!feat_ops[type].write) |
| 3100 | return -1; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3101 | |
David Carrillo-Cisneros | 0b3d341 | 2017-07-17 21:25:45 -0700 | [diff] [blame] | 3102 | if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) |
| 3103 | return -1; |
| 3104 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3105 | (*p)->offset = lseek(ff->fd, 0, SEEK_CUR); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3106 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3107 | err = feat_ops[type].write(ff, evlist); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3108 | if (err < 0) { |
Jiri Olsa | 0c2aff4 | 2016-10-10 09:38:02 +0200 | [diff] [blame] | 3109 | pr_debug("failed to write feature %s\n", feat_ops[type].name); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3110 | |
| 3111 | /* undo anything written */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3112 | lseek(ff->fd, (*p)->offset, SEEK_SET); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3113 | |
| 3114 | return -1; |
| 3115 | } |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3116 | (*p)->size = lseek(ff->fd, 0, SEEK_CUR) - (*p)->offset; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3117 | (*p)++; |
| 3118 | } |
| 3119 | return ret; |
| 3120 | } |
| 3121 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3122 | static int perf_header__adds_write(struct perf_header *header, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3123 | struct evlist *evlist, int fd) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3124 | { |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3125 | int nr_sections; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3126 | struct feat_fd ff; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3127 | struct perf_file_section *feat_sec, *p; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3128 | int sec_size; |
| 3129 | u64 sec_start; |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3130 | int feat; |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3131 | int err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3132 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3133 | ff = (struct feat_fd){ |
| 3134 | .fd = fd, |
| 3135 | .ph = header, |
| 3136 | }; |
| 3137 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3138 | nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3139 | if (!nr_sections) |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3140 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3141 | |
Paul Gortmaker | 91b9880 | 2013-01-30 20:05:49 -0500 | [diff] [blame] | 3142 | feat_sec = p = calloc(nr_sections, sizeof(*feat_sec)); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3143 | if (feat_sec == NULL) |
| 3144 | return -ENOMEM; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3145 | |
| 3146 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 3147 | |
Jiri Olsa | 8d541e9 | 2013-07-17 19:49:44 +0200 | [diff] [blame] | 3148 | sec_start = header->feat_offset; |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 3149 | lseek(fd, sec_start + sec_size, SEEK_SET); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3150 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3151 | for_each_set_bit(feat, header->adds_features, HEADER_FEAT_BITS) { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3152 | if (do_write_feat(&ff, feat, &p, evlist)) |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3153 | perf_header__clear_feat(header, feat); |
| 3154 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3155 | |
Xiao Guangrong | f887f30 | 2010-02-04 16:46:42 +0800 | [diff] [blame] | 3156 | lseek(fd, sec_start, SEEK_SET); |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3157 | /* |
| 3158 | * may write more than needed due to dropped feature, but |
Ingo Molnar | adba163 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 3159 | * this is okay, reader will skip the missing entries |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3160 | */ |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3161 | err = do_write(&ff, feat_sec, sec_size); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3162 | if (err < 0) |
| 3163 | pr_debug("failed to write feature section\n"); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3164 | free(feat_sec); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3165 | return err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3166 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3167 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3168 | int perf_header__write_pipe(int fd) |
| 3169 | { |
| 3170 | struct perf_pipe_file_header f_header; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3171 | struct feat_fd ff; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3172 | int err; |
| 3173 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3174 | ff = (struct feat_fd){ .fd = fd }; |
| 3175 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3176 | f_header = (struct perf_pipe_file_header){ |
| 3177 | .magic = PERF_MAGIC, |
| 3178 | .size = sizeof(f_header), |
| 3179 | }; |
| 3180 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3181 | err = do_write(&ff, &f_header, sizeof(f_header)); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3182 | if (err < 0) { |
| 3183 | pr_debug("failed to write perf pipe header\n"); |
| 3184 | return err; |
| 3185 | } |
| 3186 | |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3190 | int perf_session__write_header(struct perf_session *session, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3191 | struct evlist *evlist, |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3192 | int fd, bool at_exit) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3193 | { |
| 3194 | struct perf_file_header f_header; |
| 3195 | struct perf_file_attr f_attr; |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3196 | struct perf_header *header = &session->header; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3197 | struct evsel *evsel; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3198 | struct feat_fd ff; |
Jiri Olsa | 944d62b | 2013-07-17 19:49:43 +0200 | [diff] [blame] | 3199 | u64 attr_offset; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3200 | int err; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3201 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3202 | ff = (struct feat_fd){ .fd = fd}; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3203 | lseek(fd, sizeof(f_header), SEEK_SET); |
| 3204 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3205 | evlist__for_each_entry(session->evlist, evsel) { |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 3206 | evsel->id_offset = lseek(fd, 0, SEEK_CUR); |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 3207 | err = do_write(&ff, evsel->core.id, evsel->core.ids * sizeof(u64)); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3208 | if (err < 0) { |
| 3209 | pr_debug("failed to write perf header\n"); |
| 3210 | return err; |
| 3211 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3212 | } |
| 3213 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3214 | attr_offset = lseek(ff.fd, 0, SEEK_CUR); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3215 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3216 | evlist__for_each_entry(evlist, evsel) { |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3217 | f_attr = (struct perf_file_attr){ |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3218 | .attr = evsel->core.attr, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3219 | .ids = { |
Robert Richter | 6606f87 | 2012-08-16 21:10:19 +0200 | [diff] [blame] | 3220 | .offset = evsel->id_offset, |
Jiri Olsa | e7eb900 | 2019-09-02 22:15:47 +0200 | [diff] [blame] | 3221 | .size = evsel->core.ids * sizeof(u64), |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3222 | } |
| 3223 | }; |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3224 | err = do_write(&ff, &f_attr, sizeof(f_attr)); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3225 | if (err < 0) { |
| 3226 | pr_debug("failed to write perf header attribute\n"); |
| 3227 | return err; |
| 3228 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3229 | } |
| 3230 | |
Adrian Hunter | d645c44 | 2013-12-11 14:36:28 +0200 | [diff] [blame] | 3231 | if (!header->data_offset) |
| 3232 | header->data_offset = lseek(fd, 0, SEEK_CUR); |
Jiri Olsa | 8d541e9 | 2013-07-17 19:49:44 +0200 | [diff] [blame] | 3233 | header->feat_offset = header->data_offset + header->data_size; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3234 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3235 | if (at_exit) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3236 | err = perf_header__adds_write(header, evlist, fd); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3237 | if (err < 0) |
| 3238 | return err; |
| 3239 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3240 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3241 | f_header = (struct perf_file_header){ |
| 3242 | .magic = PERF_MAGIC, |
| 3243 | .size = sizeof(f_header), |
| 3244 | .attr_size = sizeof(f_attr), |
| 3245 | .attrs = { |
Jiri Olsa | 944d62b | 2013-07-17 19:49:43 +0200 | [diff] [blame] | 3246 | .offset = attr_offset, |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 3247 | .size = evlist->core.nr_entries * sizeof(f_attr), |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3248 | }, |
| 3249 | .data = { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3250 | .offset = header->data_offset, |
| 3251 | .size = header->data_size, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3252 | }, |
Jiri Olsa | 44b3c57 | 2013-07-11 17:28:31 +0200 | [diff] [blame] | 3253 | /* event_types is ignored, store zeros */ |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3254 | }; |
| 3255 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3256 | memcpy(&f_header.adds_features, &header->adds_features, sizeof(header->adds_features)); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3257 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3258 | lseek(fd, 0, SEEK_SET); |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3259 | err = do_write(&ff, &f_header, sizeof(f_header)); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3260 | if (err < 0) { |
| 3261 | pr_debug("failed to write perf header\n"); |
| 3262 | return err; |
| 3263 | } |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3264 | lseek(fd, header->data_offset + header->data_size, SEEK_SET); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3265 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 3266 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3267 | } |
| 3268 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3269 | static int perf_header__getbuffer64(struct perf_header *header, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3270 | int fd, void *buf, size_t size) |
| 3271 | { |
Arnaldo Carvalho de Melo | 1e7972c | 2011-01-03 16:50:55 -0200 | [diff] [blame] | 3272 | if (readn(fd, buf, size) <= 0) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3273 | return -1; |
| 3274 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3275 | if (header->needs_swap) |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3276 | mem_bswap_64(buf, size); |
| 3277 | |
| 3278 | return 0; |
| 3279 | } |
| 3280 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3281 | int perf_header__process_sections(struct perf_header *header, int fd, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3282 | void *data, |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3283 | int (*process)(struct perf_file_section *section, |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3284 | struct perf_header *ph, |
| 3285 | int feat, int fd, void *data)) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3286 | { |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3287 | struct perf_file_section *feat_sec, *sec; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3288 | int nr_sections; |
| 3289 | int sec_size; |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3290 | int feat; |
| 3291 | int err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3292 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3293 | nr_sections = bitmap_weight(header->adds_features, HEADER_FEAT_BITS); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3294 | if (!nr_sections) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3295 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3296 | |
Paul Gortmaker | 91b9880 | 2013-01-30 20:05:49 -0500 | [diff] [blame] | 3297 | feat_sec = sec = calloc(nr_sections, sizeof(*feat_sec)); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3298 | if (!feat_sec) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3299 | return -1; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3300 | |
| 3301 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 3302 | |
Jiri Olsa | 8d541e9 | 2013-07-17 19:49:44 +0200 | [diff] [blame] | 3303 | lseek(fd, header->feat_offset, SEEK_SET); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3304 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3305 | err = perf_header__getbuffer64(header, fd, feat_sec, sec_size); |
| 3306 | if (err < 0) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3307 | goto out_free; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3308 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3309 | for_each_set_bit(feat, header->adds_features, HEADER_LAST_FEATURE) { |
| 3310 | err = process(sec++, header, feat, fd, data); |
| 3311 | if (err < 0) |
| 3312 | goto out_free; |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 3313 | } |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3314 | err = 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3315 | out_free: |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 3316 | free(feat_sec); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3317 | return err; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3318 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 3319 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3320 | static const int attr_file_abi_sizes[] = { |
| 3321 | [0] = PERF_ATTR_SIZE_VER0, |
| 3322 | [1] = PERF_ATTR_SIZE_VER1, |
Jiri Olsa | 239cc47 | 2012-08-07 15:20:42 +0200 | [diff] [blame] | 3323 | [2] = PERF_ATTR_SIZE_VER2, |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 3324 | [3] = PERF_ATTR_SIZE_VER3, |
Stephane Eranian | 6a21c0b | 2014-09-24 13:48:39 +0200 | [diff] [blame] | 3325 | [4] = PERF_ATTR_SIZE_VER4, |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3326 | 0, |
| 3327 | }; |
| 3328 | |
| 3329 | /* |
| 3330 | * In the legacy file format, the magic number is not used to encode endianness. |
| 3331 | * hdr_sz was used to encode endianness. But given that hdr_sz can vary based |
| 3332 | * on ABI revisions, we need to try all combinations for all endianness to |
| 3333 | * detect the endianness. |
| 3334 | */ |
| 3335 | static int try_all_file_abis(uint64_t hdr_sz, struct perf_header *ph) |
| 3336 | { |
| 3337 | uint64_t ref_size, attr_size; |
| 3338 | int i; |
| 3339 | |
| 3340 | for (i = 0 ; attr_file_abi_sizes[i]; i++) { |
| 3341 | ref_size = attr_file_abi_sizes[i] |
| 3342 | + sizeof(struct perf_file_section); |
| 3343 | if (hdr_sz != ref_size) { |
| 3344 | attr_size = bswap_64(hdr_sz); |
| 3345 | if (attr_size != ref_size) |
| 3346 | continue; |
| 3347 | |
| 3348 | ph->needs_swap = true; |
| 3349 | } |
| 3350 | pr_debug("ABI%d perf.data file detected, need_swap=%d\n", |
| 3351 | i, |
| 3352 | ph->needs_swap); |
| 3353 | return 0; |
| 3354 | } |
| 3355 | /* could not determine endianness */ |
| 3356 | return -1; |
| 3357 | } |
| 3358 | |
| 3359 | #define PERF_PIPE_HDR_VER0 16 |
| 3360 | |
| 3361 | static const size_t attr_pipe_abi_sizes[] = { |
| 3362 | [0] = PERF_PIPE_HDR_VER0, |
| 3363 | 0, |
| 3364 | }; |
| 3365 | |
| 3366 | /* |
| 3367 | * In the legacy pipe format, there is an implicit assumption that endiannesss |
| 3368 | * between host recording the samples, and host parsing the samples is the |
| 3369 | * same. This is not always the case given that the pipe output may always be |
| 3370 | * redirected into a file and analyzed on a different machine with possibly a |
| 3371 | * different endianness and perf_event ABI revsions in the perf tool itself. |
| 3372 | */ |
| 3373 | static int try_all_pipe_abis(uint64_t hdr_sz, struct perf_header *ph) |
| 3374 | { |
| 3375 | u64 attr_size; |
| 3376 | int i; |
| 3377 | |
| 3378 | for (i = 0 ; attr_pipe_abi_sizes[i]; i++) { |
| 3379 | if (hdr_sz != attr_pipe_abi_sizes[i]) { |
| 3380 | attr_size = bswap_64(hdr_sz); |
| 3381 | if (attr_size != hdr_sz) |
| 3382 | continue; |
| 3383 | |
| 3384 | ph->needs_swap = true; |
| 3385 | } |
| 3386 | pr_debug("Pipe ABI%d perf.data file detected\n", i); |
| 3387 | return 0; |
| 3388 | } |
| 3389 | return -1; |
| 3390 | } |
| 3391 | |
Feng Tang | e84ba4e | 2012-10-30 11:56:07 +0800 | [diff] [blame] | 3392 | bool is_perf_magic(u64 magic) |
| 3393 | { |
| 3394 | if (!memcmp(&magic, __perf_magic1, sizeof(magic)) |
| 3395 | || magic == __perf_magic2 |
| 3396 | || magic == __perf_magic2_sw) |
| 3397 | return true; |
| 3398 | |
| 3399 | return false; |
| 3400 | } |
| 3401 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3402 | static int check_magic_endian(u64 magic, uint64_t hdr_sz, |
| 3403 | bool is_pipe, struct perf_header *ph) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3404 | { |
| 3405 | int ret; |
| 3406 | |
| 3407 | /* check for legacy format */ |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3408 | ret = memcmp(&magic, __perf_magic1, sizeof(magic)); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3409 | if (ret == 0) { |
Jiri Olsa | 2a08c3e | 2013-07-17 19:49:47 +0200 | [diff] [blame] | 3410 | ph->version = PERF_HEADER_VERSION_1; |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3411 | pr_debug("legacy perf.data format\n"); |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3412 | if (is_pipe) |
| 3413 | return try_all_pipe_abis(hdr_sz, ph); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3414 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3415 | return try_all_file_abis(hdr_sz, ph); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3416 | } |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3417 | /* |
| 3418 | * the new magic number serves two purposes: |
| 3419 | * - unique number to identify actual perf.data files |
| 3420 | * - encode endianness of file |
| 3421 | */ |
Namhyung Kim | f791397 | 2015-01-29 17:06:45 +0900 | [diff] [blame] | 3422 | ph->version = PERF_HEADER_VERSION_2; |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3423 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3424 | /* check magic number with one endianness */ |
| 3425 | if (magic == __perf_magic2) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3426 | return 0; |
| 3427 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3428 | /* check magic number with opposite endianness */ |
| 3429 | if (magic != __perf_magic2_sw) |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3430 | return -1; |
| 3431 | |
| 3432 | ph->needs_swap = true; |
| 3433 | |
| 3434 | return 0; |
| 3435 | } |
| 3436 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3437 | int perf_file_header__read(struct perf_file_header *header, |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3438 | struct perf_header *ph, int fd) |
| 3439 | { |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 3440 | ssize_t ret; |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3441 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3442 | lseek(fd, 0, SEEK_SET); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3443 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3444 | ret = readn(fd, header, sizeof(*header)); |
| 3445 | if (ret <= 0) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3446 | return -1; |
| 3447 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3448 | if (check_magic_endian(header->magic, |
| 3449 | header->attr_size, false, ph) < 0) { |
| 3450 | pr_debug("magic/endian check failed\n"); |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3451 | return -1; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3452 | } |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3453 | |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3454 | if (ph->needs_swap) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3455 | mem_bswap_64(header, offsetof(struct perf_file_header, |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3456 | adds_features)); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3457 | } |
| 3458 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3459 | if (header->size != sizeof(*header)) { |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3460 | /* Support the previous format */ |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3461 | if (header->size == offsetof(typeof(*header), adds_features)) |
| 3462 | bitmap_zero(header->adds_features, HEADER_FEAT_BITS); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3463 | else |
| 3464 | return -1; |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 3465 | } else if (ph->needs_swap) { |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 3466 | /* |
| 3467 | * feature bitmap is declared as an array of unsigned longs -- |
| 3468 | * not good since its size can differ between the host that |
| 3469 | * generated the data file and the host analyzing the file. |
| 3470 | * |
| 3471 | * We need to handle endianness, but we don't know the size of |
| 3472 | * the unsigned long where the file was generated. Take a best |
| 3473 | * guess at determining it: try 64-bit swap first (ie., file |
| 3474 | * created on a 64-bit host), and check if the hostname feature |
| 3475 | * bit is set (this feature bit is forced on as of fbe96f2). |
| 3476 | * If the bit is not, undo the 64-bit swap and try a 32-bit |
| 3477 | * swap. If the hostname bit is still not set (e.g., older data |
| 3478 | * file), punt and fallback to the original behavior -- |
| 3479 | * clearing all feature bits and setting buildid. |
| 3480 | */ |
David Ahern | 80c0120 | 2012-06-08 11:47:51 -0300 | [diff] [blame] | 3481 | mem_bswap_64(&header->adds_features, |
| 3482 | BITS_TO_U64(HEADER_FEAT_BITS)); |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 3483 | |
| 3484 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
David Ahern | 80c0120 | 2012-06-08 11:47:51 -0300 | [diff] [blame] | 3485 | /* unswap as u64 */ |
| 3486 | mem_bswap_64(&header->adds_features, |
| 3487 | BITS_TO_U64(HEADER_FEAT_BITS)); |
| 3488 | |
| 3489 | /* unswap as u32 */ |
| 3490 | mem_bswap_32(&header->adds_features, |
| 3491 | BITS_TO_U32(HEADER_FEAT_BITS)); |
David Ahern | d327fa4 | 2011-10-18 17:34:01 -0600 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | if (!test_bit(HEADER_HOSTNAME, header->adds_features)) { |
| 3495 | bitmap_zero(header->adds_features, HEADER_FEAT_BITS); |
| 3496 | set_bit(HEADER_BUILD_ID, header->adds_features); |
| 3497 | } |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3498 | } |
| 3499 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3500 | memcpy(&ph->adds_features, &header->adds_features, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3501 | sizeof(ph->adds_features)); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3502 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3503 | ph->data_offset = header->data.offset; |
| 3504 | ph->data_size = header->data.size; |
Jiri Olsa | 8d541e9 | 2013-07-17 19:49:44 +0200 | [diff] [blame] | 3505 | ph->feat_offset = header->data.offset + header->data.size; |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3506 | return 0; |
| 3507 | } |
| 3508 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3509 | static int perf_file_section__process(struct perf_file_section *section, |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3510 | struct perf_header *ph, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 3511 | int feat, int fd, void *data) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3512 | { |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 3513 | struct feat_fd fdd = { |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 3514 | .fd = fd, |
| 3515 | .ph = ph, |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 3516 | .size = section->size, |
| 3517 | .offset = section->offset, |
David Carrillo-Cisneros | 1a22275 | 2017-07-17 21:25:41 -0700 | [diff] [blame] | 3518 | }; |
| 3519 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3520 | if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 3521 | pr_debug("Failed to lseek to %" PRIu64 " offset for feature " |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3522 | "%d, continuing...\n", section->offset, feat); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3523 | return 0; |
| 3524 | } |
| 3525 | |
Robert Richter | b1e5a9b | 2011-12-07 10:02:57 +0100 | [diff] [blame] | 3526 | if (feat >= HEADER_LAST_FEATURE) { |
| 3527 | pr_debug("unknown feature %d, continuing...\n", feat); |
| 3528 | return 0; |
| 3529 | } |
| 3530 | |
Robert Richter | f1c67db | 2012-02-10 15:41:56 +0100 | [diff] [blame] | 3531 | if (!feat_ops[feat].process) |
| 3532 | return 0; |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3533 | |
David Carrillo-Cisneros | 6255245 | 2017-07-17 21:25:42 -0700 | [diff] [blame] | 3534 | return feat_ops[feat].process(&fdd, data); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 3535 | } |
| 3536 | |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3537 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *header, |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 3538 | struct perf_header *ph, int fd, |
| 3539 | bool repipe) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3540 | { |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3541 | struct feat_fd ff = { |
| 3542 | .fd = STDOUT_FILENO, |
| 3543 | .ph = ph, |
| 3544 | }; |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 3545 | ssize_t ret; |
Stephane Eranian | 73323f5 | 2012-02-02 13:54:44 +0100 | [diff] [blame] | 3546 | |
| 3547 | ret = readn(fd, header, sizeof(*header)); |
| 3548 | if (ret <= 0) |
| 3549 | return -1; |
| 3550 | |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3551 | if (check_magic_endian(header->magic, header->size, true, ph) < 0) { |
| 3552 | pr_debug("endian/magic failed\n"); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3553 | return -1; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | if (ph->needs_swap) |
| 3557 | header->size = bswap_64(header->size); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3558 | |
David Carrillo-Cisneros | ccebbeb | 2017-07-17 21:25:39 -0700 | [diff] [blame] | 3559 | if (repipe && do_write(&ff, header, sizeof(*header)) < 0) |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 3560 | return -1; |
| 3561 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3562 | return 0; |
| 3563 | } |
| 3564 | |
Jiri Olsa | d433956 | 2013-07-17 19:49:41 +0200 | [diff] [blame] | 3565 | static int perf_header__read_pipe(struct perf_session *session) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3566 | { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3567 | struct perf_header *header = &session->header; |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3568 | struct perf_pipe_file_header f_header; |
| 3569 | |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 3570 | if (perf_file_header__read_pipe(&f_header, header, |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3571 | perf_data__fd(session->data), |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 3572 | session->repipe) < 0) { |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3573 | pr_debug("incompatible file format\n"); |
| 3574 | return -EINVAL; |
| 3575 | } |
| 3576 | |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3577 | return 0; |
| 3578 | } |
| 3579 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3580 | static int read_attr(int fd, struct perf_header *ph, |
| 3581 | struct perf_file_attr *f_attr) |
| 3582 | { |
| 3583 | struct perf_event_attr *attr = &f_attr->attr; |
| 3584 | size_t sz, left; |
| 3585 | size_t our_sz = sizeof(f_attr->attr); |
Jiri Olsa | 727ebd5 | 2013-11-28 11:30:14 +0100 | [diff] [blame] | 3586 | ssize_t ret; |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3587 | |
| 3588 | memset(f_attr, 0, sizeof(*f_attr)); |
| 3589 | |
| 3590 | /* read minimal guaranteed structure */ |
| 3591 | ret = readn(fd, attr, PERF_ATTR_SIZE_VER0); |
| 3592 | if (ret <= 0) { |
| 3593 | pr_debug("cannot read %d bytes of header attr\n", |
| 3594 | PERF_ATTR_SIZE_VER0); |
| 3595 | return -1; |
| 3596 | } |
| 3597 | |
| 3598 | /* on file perf_event_attr size */ |
| 3599 | sz = attr->size; |
Stephane Eranian | 114382a | 2012-02-09 23:21:08 +0100 | [diff] [blame] | 3600 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3601 | if (ph->needs_swap) |
| 3602 | sz = bswap_32(sz); |
| 3603 | |
| 3604 | if (sz == 0) { |
| 3605 | /* assume ABI0 */ |
| 3606 | sz = PERF_ATTR_SIZE_VER0; |
| 3607 | } else if (sz > our_sz) { |
| 3608 | pr_debug("file uses a more recent and unsupported ABI" |
| 3609 | " (%zu bytes extra)\n", sz - our_sz); |
| 3610 | return -1; |
| 3611 | } |
| 3612 | /* what we have not yet read and that we know about */ |
| 3613 | left = sz - PERF_ATTR_SIZE_VER0; |
| 3614 | if (left) { |
| 3615 | void *ptr = attr; |
| 3616 | ptr += PERF_ATTR_SIZE_VER0; |
| 3617 | |
| 3618 | ret = readn(fd, ptr, left); |
| 3619 | } |
| 3620 | /* read perf_file_section, ids are read in caller */ |
| 3621 | ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids)); |
| 3622 | |
| 3623 | return ret <= 0 ? -1 : 0; |
| 3624 | } |
| 3625 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3626 | static int perf_evsel__prepare_tracepoint_event(struct evsel *evsel, |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3627 | struct tep_handle *pevent) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3628 | { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 3629 | struct tep_event *event; |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3630 | char bf[128]; |
| 3631 | |
Namhyung Kim | 831394b | 2012-09-06 11:10:46 +0900 | [diff] [blame] | 3632 | /* already prepared */ |
| 3633 | if (evsel->tp_format) |
| 3634 | return 0; |
| 3635 | |
Namhyung Kim | 3dce2ce | 2013-03-21 16:18:48 +0900 | [diff] [blame] | 3636 | if (pevent == NULL) { |
| 3637 | pr_debug("broken or missing trace data\n"); |
| 3638 | return -1; |
| 3639 | } |
| 3640 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3641 | event = tep_find_event(pevent, evsel->core.attr.config); |
Namhyung Kim | a7619ae | 2013-04-18 21:24:16 +0900 | [diff] [blame] | 3642 | if (event == NULL) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3643 | pr_debug("cannot find event format for %d\n", (int)evsel->core.attr.config); |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3644 | return -1; |
Namhyung Kim | a7619ae | 2013-04-18 21:24:16 +0900 | [diff] [blame] | 3645 | } |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3646 | |
Namhyung Kim | 831394b | 2012-09-06 11:10:46 +0900 | [diff] [blame] | 3647 | if (!evsel->name) { |
| 3648 | snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name); |
| 3649 | evsel->name = strdup(bf); |
| 3650 | if (evsel->name == NULL) |
| 3651 | return -1; |
| 3652 | } |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3653 | |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 3654 | evsel->tp_format = event; |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3655 | return 0; |
| 3656 | } |
| 3657 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3658 | static int perf_evlist__prepare_tracepoint_events(struct evlist *evlist, |
Tzvetomir Stoyanov (VMware) | 096177a | 2018-08-08 14:02:46 -0400 | [diff] [blame] | 3659 | struct tep_handle *pevent) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3660 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3661 | struct evsel *pos; |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3662 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3663 | evlist__for_each_entry(evlist, pos) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3664 | if (pos->core.attr.type == PERF_TYPE_TRACEPOINT && |
Namhyung Kim | 831394b | 2012-09-06 11:10:46 +0900 | [diff] [blame] | 3665 | perf_evsel__prepare_tracepoint_event(pos, pevent)) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3666 | return -1; |
| 3667 | } |
| 3668 | |
| 3669 | return 0; |
| 3670 | } |
| 3671 | |
Jiri Olsa | d433956 | 2013-07-17 19:49:41 +0200 | [diff] [blame] | 3672 | int perf_session__read_header(struct perf_session *session) |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3673 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3674 | struct perf_data *data = session->data; |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3675 | struct perf_header *header = &session->header; |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3676 | struct perf_file_header f_header; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3677 | struct perf_file_attr f_attr; |
| 3678 | u64 f_id; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3679 | int nr_attrs, nr_ids, i, j; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3680 | int fd = perf_data__fd(data); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3681 | |
Jiri Olsa | 0f98b11 | 2019-07-21 13:23:55 +0200 | [diff] [blame] | 3682 | session->evlist = evlist__new(); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3683 | if (session->evlist == NULL) |
| 3684 | return -ENOMEM; |
| 3685 | |
Kan Liang | 2c07144 | 2015-08-28 05:48:05 -0400 | [diff] [blame] | 3686 | session->evlist->env = &header->env; |
Arnaldo Carvalho de Melo | 4cde998 | 2015-09-09 12:25:00 -0300 | [diff] [blame] | 3687 | session->machines.host.env = &header->env; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3688 | if (perf_data__is_pipe(data)) |
Jiri Olsa | d433956 | 2013-07-17 19:49:41 +0200 | [diff] [blame] | 3689 | return perf_header__read_pipe(session); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 3690 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3691 | if (perf_file_header__read(&f_header, header, fd) < 0) |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 3692 | return -EINVAL; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3693 | |
Namhyung Kim | b314e5c | 2013-09-30 17:19:48 +0900 | [diff] [blame] | 3694 | /* |
| 3695 | * Sanity check that perf.data was written cleanly; data size is |
| 3696 | * initialized to 0 and updated only if the on_exit function is run. |
| 3697 | * If data size is still 0 then the file contains only partial |
| 3698 | * information. Just warn user and process it as much as it can. |
| 3699 | */ |
| 3700 | if (f_header.data.size == 0) { |
| 3701 | pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n" |
| 3702 | "Was the 'perf record' command properly terminated?\n", |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 3703 | data->file.path); |
Namhyung Kim | b314e5c | 2013-09-30 17:19:48 +0900 | [diff] [blame] | 3704 | } |
| 3705 | |
Vince Weaver | 7622236 | 2019-07-23 11:06:01 -0400 | [diff] [blame] | 3706 | if (f_header.attr_size == 0) { |
| 3707 | pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n" |
| 3708 | "Was the 'perf record' command properly terminated?\n", |
| 3709 | data->file.path); |
| 3710 | return -EINVAL; |
| 3711 | } |
| 3712 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3713 | nr_attrs = f_header.attrs.size / f_header.attr_size; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3714 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
| 3715 | |
| 3716 | for (i = 0; i < nr_attrs; i++) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3717 | struct evsel *evsel; |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 3718 | off_t tmp; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3719 | |
Stephane Eranian | 69996df | 2012-02-09 23:21:06 +0100 | [diff] [blame] | 3720 | if (read_attr(fd, header, &f_attr) < 0) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3721 | goto out_errno; |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 3722 | |
David Ahern | 1060ab8 | 2015-04-09 16:15:46 -0400 | [diff] [blame] | 3723 | if (header->needs_swap) { |
| 3724 | f_attr.ids.size = bswap_64(f_attr.ids.size); |
| 3725 | f_attr.ids.offset = bswap_64(f_attr.ids.offset); |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 3726 | perf_event__attr_swap(&f_attr.attr); |
David Ahern | 1060ab8 | 2015-04-09 16:15:46 -0400 | [diff] [blame] | 3727 | } |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 3728 | |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 3729 | tmp = lseek(fd, 0, SEEK_CUR); |
Jiri Olsa | 365c3ae | 2019-07-21 13:23:58 +0200 | [diff] [blame] | 3730 | evsel = evsel__new(&f_attr.attr); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3731 | |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3732 | if (evsel == NULL) |
| 3733 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 3734 | |
| 3735 | evsel->needs_swap = header->needs_swap; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3736 | /* |
| 3737 | * Do it before so that if perf_evsel__alloc_id fails, this |
Jiri Olsa | c12995a | 2019-07-21 13:23:56 +0200 | [diff] [blame] | 3738 | * entry gets purged too at evlist__delete(). |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3739 | */ |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 3740 | evlist__add(session->evlist, evsel); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3741 | |
| 3742 | nr_ids = f_attr.ids.size / sizeof(u64); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3743 | /* |
| 3744 | * We don't have the cpu and thread maps on the header, so |
| 3745 | * for allocating the perf_sample_id table we fake 1 cpu and |
| 3746 | * hattr->ids threads. |
| 3747 | */ |
Jiri Olsa | 70c2036 | 2019-09-03 10:34:29 +0200 | [diff] [blame] | 3748 | if (perf_evsel__alloc_id(&evsel->core, 1, nr_ids)) |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3749 | goto out_delete_evlist; |
| 3750 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3751 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
| 3752 | |
| 3753 | for (j = 0; j < nr_ids; j++) { |
Arnaldo Carvalho de Melo | 1c0b04d | 2011-03-09 08:13:19 -0300 | [diff] [blame] | 3754 | if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id))) |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3755 | goto out_errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3756 | |
Jiri Olsa | b0031c2 | 2019-09-03 11:01:04 +0200 | [diff] [blame] | 3757 | perf_evlist__id_add(&session->evlist->core, &evsel->core, 0, j, f_id); |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 3758 | } |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 3759 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3760 | lseek(fd, tmp, SEEK_SET); |
| 3761 | } |
| 3762 | |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 3763 | perf_header__process_sections(header, fd, &session->tevent, |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 3764 | perf_file_section__process); |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 3765 | |
Namhyung Kim | 831394b | 2012-09-06 11:10:46 +0900 | [diff] [blame] | 3766 | if (perf_evlist__prepare_tracepoint_events(session->evlist, |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 3767 | session->tevent.pevent)) |
Arnaldo Carvalho de Melo | cb9dd49 | 2012-06-11 19:03:32 -0300 | [diff] [blame] | 3768 | goto out_delete_evlist; |
| 3769 | |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 3770 | return 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame] | 3771 | out_errno: |
| 3772 | return -errno; |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3773 | |
| 3774 | out_delete_evlist: |
Jiri Olsa | c12995a | 2019-07-21 13:23:56 +0200 | [diff] [blame] | 3775 | evlist__delete(session->evlist); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3776 | session->evlist = NULL; |
| 3777 | return -ENOMEM; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 3778 | } |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 3779 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3780 | int perf_event__process_feature(struct perf_session *session, |
| 3781 | union perf_event *event) |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 3782 | { |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3783 | struct perf_tool *tool = session->tool; |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 3784 | struct feat_fd ff = { .fd = 0 }; |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3785 | struct perf_record_header_feature *fe = (struct perf_record_header_feature *)event; |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 3786 | int type = fe->header.type; |
| 3787 | u64 feat = fe->feat_id; |
| 3788 | |
| 3789 | if (type < 0 || type >= PERF_RECORD_HEADER_MAX) { |
| 3790 | pr_warning("invalid record type %d in pipe-mode\n", type); |
| 3791 | return 0; |
| 3792 | } |
Ravi Bangoria | 92ead7e | 2018-06-25 18:12:20 +0530 | [diff] [blame] | 3793 | if (feat == HEADER_RESERVED || feat >= HEADER_LAST_FEATURE) { |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 3794 | pr_warning("invalid record type %d in pipe-mode\n", type); |
| 3795 | return -1; |
| 3796 | } |
| 3797 | |
| 3798 | if (!feat_ops[feat].process) |
| 3799 | return 0; |
| 3800 | |
| 3801 | ff.buf = (void *)fe->data; |
Jiri Olsa | 79b2fe5 | 2019-07-15 16:04:26 +0200 | [diff] [blame] | 3802 | ff.size = event->header.size - sizeof(*fe); |
David Carrillo-Cisneros | e9def1b | 2017-07-17 21:25:48 -0700 | [diff] [blame] | 3803 | ff.ph = &session->header; |
| 3804 | |
| 3805 | if (feat_ops[feat].process(&ff, NULL)) |
| 3806 | return -1; |
| 3807 | |
| 3808 | if (!feat_ops[feat].print || !tool->show_feat_hdr) |
| 3809 | return 0; |
| 3810 | |
| 3811 | if (!feat_ops[feat].full_only || |
| 3812 | tool->show_feat_hdr >= SHOW_FEAT_HEADER_FULL_INFO) { |
| 3813 | feat_ops[feat].print(&ff, stdout); |
| 3814 | } else { |
| 3815 | fprintf(stdout, "# %s info available, use -I to display\n", |
| 3816 | feat_ops[feat].name); |
| 3817 | } |
| 3818 | |
| 3819 | return 0; |
| 3820 | } |
| 3821 | |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 3822 | size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp) |
| 3823 | { |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3824 | struct perf_record_event_update *ev = &event->event_update; |
| 3825 | struct perf_record_event_update_scale *ev_scale; |
| 3826 | struct perf_record_event_update_cpus *ev_cpus; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 3827 | struct perf_cpu_map *map; |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 3828 | size_t ret; |
| 3829 | |
Jiri Olsa | 5ded068 | 2019-08-28 15:56:57 +0200 | [diff] [blame] | 3830 | ret = fprintf(fp, "\n... id: %" PRI_lu64 "\n", ev->id); |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 3831 | |
| 3832 | switch (ev->type) { |
| 3833 | case PERF_EVENT_UPDATE__SCALE: |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3834 | ev_scale = (struct perf_record_event_update_scale *)ev->data; |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 3835 | ret += fprintf(fp, "... scale: %f\n", ev_scale->scale); |
| 3836 | break; |
| 3837 | case PERF_EVENT_UPDATE__UNIT: |
| 3838 | ret += fprintf(fp, "... unit: %s\n", ev->data); |
| 3839 | break; |
| 3840 | case PERF_EVENT_UPDATE__NAME: |
| 3841 | ret += fprintf(fp, "... name: %s\n", ev->data); |
| 3842 | break; |
| 3843 | case PERF_EVENT_UPDATE__CPUS: |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3844 | ev_cpus = (struct perf_record_event_update_cpus *)ev->data; |
Jiri Olsa | c853f93 | 2015-10-25 15:51:41 +0100 | [diff] [blame] | 3845 | ret += fprintf(fp, "... "); |
| 3846 | |
| 3847 | map = cpu_map__new_data(&ev_cpus->cpus); |
| 3848 | if (map) |
| 3849 | ret += cpu_map__fprintf(map, fp); |
| 3850 | else |
| 3851 | ret += fprintf(fp, "failed to get cpus\n"); |
| 3852 | break; |
| 3853 | default: |
| 3854 | ret += fprintf(fp, "... unknown type\n"); |
| 3855 | break; |
| 3856 | } |
| 3857 | |
| 3858 | return ret; |
| 3859 | } |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 3860 | |
Adrian Hunter | 47c3d10 | 2013-07-04 16:20:21 +0300 | [diff] [blame] | 3861 | int perf_event__process_attr(struct perf_tool *tool __maybe_unused, |
| 3862 | union perf_event *event, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3863 | struct evlist **pevlist) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3864 | { |
Robert Richter | f4d8343 | 2012-08-16 21:10:17 +0200 | [diff] [blame] | 3865 | u32 i, ids, n_ids; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3866 | struct evsel *evsel; |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3867 | struct evlist *evlist = *pevlist; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3868 | |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 3869 | if (evlist == NULL) { |
Jiri Olsa | 0f98b11 | 2019-07-21 13:23:55 +0200 | [diff] [blame] | 3870 | *pevlist = evlist = evlist__new(); |
Arnaldo Carvalho de Melo | 10d0f08 | 2011-11-11 22:45:41 -0200 | [diff] [blame] | 3871 | if (evlist == NULL) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3872 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3873 | } |
| 3874 | |
Jiri Olsa | 365c3ae | 2019-07-21 13:23:58 +0200 | [diff] [blame] | 3875 | evsel = evsel__new(&event->attr.attr); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3876 | if (evsel == NULL) |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3877 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3878 | |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 3879 | evlist__add(evlist, evsel); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3880 | |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 3881 | ids = event->header.size; |
| 3882 | ids -= (void *)&event->attr.id - (void *)event; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3883 | n_ids = ids / sizeof(u64); |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3884 | /* |
| 3885 | * We don't have the cpu and thread maps on the header, so |
| 3886 | * for allocating the perf_sample_id table we fake 1 cpu and |
| 3887 | * hattr->ids threads. |
| 3888 | */ |
Jiri Olsa | 70c2036 | 2019-09-03 10:34:29 +0200 | [diff] [blame] | 3889 | if (perf_evsel__alloc_id(&evsel->core, 1, n_ids)) |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 3890 | return -ENOMEM; |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3891 | |
| 3892 | for (i = 0; i < n_ids; i++) { |
Jiri Olsa | b0031c2 | 2019-09-03 11:01:04 +0200 | [diff] [blame] | 3893 | perf_evlist__id_add(&evlist->core, &evsel->core, 0, i, event->attr.id[i]); |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3894 | } |
| 3895 | |
Tom Zanussi | 2c46dbb | 2010-04-01 23:59:19 -0500 | [diff] [blame] | 3896 | return 0; |
| 3897 | } |
Tom Zanussi | cd19a03 | 2010-04-01 23:59:20 -0500 | [diff] [blame] | 3898 | |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 3899 | int perf_event__process_event_update(struct perf_tool *tool __maybe_unused, |
| 3900 | union perf_event *event, |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3901 | struct evlist **pevlist) |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 3902 | { |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3903 | struct perf_record_event_update *ev = &event->event_update; |
| 3904 | struct perf_record_event_update_scale *ev_scale; |
| 3905 | struct perf_record_event_update_cpus *ev_cpus; |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3906 | struct evlist *evlist; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3907 | struct evsel *evsel; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 3908 | struct perf_cpu_map *map; |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 3909 | |
| 3910 | if (!pevlist || *pevlist == NULL) |
| 3911 | return -EINVAL; |
| 3912 | |
| 3913 | evlist = *pevlist; |
| 3914 | |
| 3915 | evsel = perf_evlist__id2evsel(evlist, ev->id); |
| 3916 | if (evsel == NULL) |
| 3917 | return -EINVAL; |
| 3918 | |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 3919 | switch (ev->type) { |
| 3920 | case PERF_EVENT_UPDATE__UNIT: |
| 3921 | evsel->unit = strdup(ev->data); |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 3922 | break; |
Jiri Olsa | 802c904 | 2015-10-25 15:51:39 +0100 | [diff] [blame] | 3923 | case PERF_EVENT_UPDATE__NAME: |
| 3924 | evsel->name = strdup(ev->data); |
| 3925 | break; |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 3926 | case PERF_EVENT_UPDATE__SCALE: |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3927 | ev_scale = (struct perf_record_event_update_scale *)ev->data; |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 3928 | evsel->scale = ev_scale->scale; |
Arnaldo Carvalho de Melo | 8434a2e | 2017-02-08 21:57:22 -0300 | [diff] [blame] | 3929 | break; |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 3930 | case PERF_EVENT_UPDATE__CPUS: |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3931 | ev_cpus = (struct perf_record_event_update_cpus *)ev->data; |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 3932 | |
| 3933 | map = cpu_map__new_data(&ev_cpus->cpus); |
| 3934 | if (map) |
Jiri Olsa | fe1f61b | 2019-07-21 13:24:38 +0200 | [diff] [blame] | 3935 | evsel->core.own_cpus = map; |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 3936 | else |
| 3937 | pr_err("failed to get event_update cpus\n"); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 3938 | default: |
| 3939 | break; |
| 3940 | } |
| 3941 | |
Jiri Olsa | ffe77725 | 2015-10-25 15:51:36 +0100 | [diff] [blame] | 3942 | return 0; |
| 3943 | } |
| 3944 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3945 | int perf_event__process_tracing_data(struct perf_session *session, |
| 3946 | union perf_event *event) |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3947 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 3948 | ssize_t size_read, padding, size = event->tracing_data.size; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3949 | int fd = perf_data__fd(session->data); |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 3950 | off_t offset = lseek(fd, 0, SEEK_CUR); |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3951 | char buf[BUFSIZ]; |
| 3952 | |
| 3953 | /* setup for reading amidst mmap */ |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 3954 | lseek(fd, offset + sizeof(struct perf_record_header_tracing_data), |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3955 | SEEK_SET); |
| 3956 | |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 3957 | size_read = trace_report(fd, &session->tevent, |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 3958 | session->repipe); |
Irina Tirdea | 9ac3e48 | 2012-09-11 01:15:01 +0300 | [diff] [blame] | 3959 | padding = PERF_ALIGN(size_read, sizeof(u64)) - size_read; |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3960 | |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 3961 | if (readn(fd, buf, padding) < 0) { |
Arnaldo Carvalho de Melo | 2caa48a | 2013-01-24 22:34:33 -0300 | [diff] [blame] | 3962 | pr_err("%s: reading input file", __func__); |
| 3963 | return -1; |
| 3964 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 3965 | if (session->repipe) { |
| 3966 | int retw = write(STDOUT_FILENO, buf, padding); |
Arnaldo Carvalho de Melo | 2caa48a | 2013-01-24 22:34:33 -0300 | [diff] [blame] | 3967 | if (retw <= 0 || retw != padding) { |
| 3968 | pr_err("%s: repiping tracing data padding", __func__); |
| 3969 | return -1; |
| 3970 | } |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 3971 | } |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3972 | |
Arnaldo Carvalho de Melo | 2caa48a | 2013-01-24 22:34:33 -0300 | [diff] [blame] | 3973 | if (size_read + padding != size) { |
| 3974 | pr_err("%s: tracing data size mismatch", __func__); |
| 3975 | return -1; |
| 3976 | } |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3977 | |
Namhyung Kim | 831394b | 2012-09-06 11:10:46 +0900 | [diff] [blame] | 3978 | perf_evlist__prepare_tracepoint_events(session->evlist, |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 3979 | session->tevent.pevent); |
Arnaldo Carvalho de Melo | 8b6ee4c | 2012-08-07 23:36:16 -0300 | [diff] [blame] | 3980 | |
Tom Zanussi | 9215545 | 2010-04-01 23:59:21 -0500 | [diff] [blame] | 3981 | return size_read + padding; |
| 3982 | } |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 3983 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 3984 | int perf_event__process_build_id(struct perf_session *session, |
| 3985 | union perf_event *event) |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 3986 | { |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 3987 | __event_process_build_id(&event->build_id, |
| 3988 | event->build_id.filename, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 3989 | session); |
Tom Zanussi | c7929e4 | 2010-04-01 23:59:22 -0500 | [diff] [blame] | 3990 | return 0; |
| 3991 | } |