Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 1 | #include <linux/types.h> |
| 2 | #include "event.h" |
| 3 | #include "debug.h" |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 4 | #include "session.h" |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame^] | 5 | #include "sort.h" |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 6 | #include "string.h" |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame^] | 7 | #include "strlist.h" |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 8 | #include "thread.h" |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 9 | |
| 10 | static pid_t event__synthesize_comm(pid_t pid, int full, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 11 | int (*process)(event_t *event, |
| 12 | struct perf_session *session), |
| 13 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 14 | { |
| 15 | event_t ev; |
| 16 | char filename[PATH_MAX]; |
| 17 | char bf[BUFSIZ]; |
| 18 | FILE *fp; |
| 19 | size_t size = 0; |
| 20 | DIR *tasks; |
| 21 | struct dirent dirent, *next; |
| 22 | pid_t tgid = 0; |
| 23 | |
| 24 | snprintf(filename, sizeof(filename), "/proc/%d/status", pid); |
| 25 | |
| 26 | fp = fopen(filename, "r"); |
| 27 | if (fp == NULL) { |
| 28 | out_race: |
| 29 | /* |
| 30 | * We raced with a task exiting - just return: |
| 31 | */ |
| 32 | pr_debug("couldn't open %s\n", filename); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | memset(&ev.comm, 0, sizeof(ev.comm)); |
| 37 | while (!ev.comm.comm[0] || !ev.comm.pid) { |
| 38 | if (fgets(bf, sizeof(bf), fp) == NULL) |
| 39 | goto out_failure; |
| 40 | |
| 41 | if (memcmp(bf, "Name:", 5) == 0) { |
| 42 | char *name = bf + 5; |
| 43 | while (*name && isspace(*name)) |
| 44 | ++name; |
| 45 | size = strlen(name) - 1; |
| 46 | memcpy(ev.comm.comm, name, size++); |
| 47 | } else if (memcmp(bf, "Tgid:", 5) == 0) { |
| 48 | char *tgids = bf + 5; |
| 49 | while (*tgids && isspace(*tgids)) |
| 50 | ++tgids; |
| 51 | tgid = ev.comm.pid = atoi(tgids); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | ev.comm.header.type = PERF_RECORD_COMM; |
| 56 | size = ALIGN(size, sizeof(u64)); |
| 57 | ev.comm.header.size = sizeof(ev.comm) - (sizeof(ev.comm.comm) - size); |
| 58 | |
| 59 | if (!full) { |
| 60 | ev.comm.tid = pid; |
| 61 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 62 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 63 | goto out_fclose; |
| 64 | } |
| 65 | |
| 66 | snprintf(filename, sizeof(filename), "/proc/%d/task", pid); |
| 67 | |
| 68 | tasks = opendir(filename); |
| 69 | if (tasks == NULL) |
| 70 | goto out_race; |
| 71 | |
| 72 | while (!readdir_r(tasks, &dirent, &next) && next) { |
| 73 | char *end; |
| 74 | pid = strtol(dirent.d_name, &end, 10); |
| 75 | if (*end) |
| 76 | continue; |
| 77 | |
| 78 | ev.comm.tid = pid; |
| 79 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 80 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 81 | } |
| 82 | closedir(tasks); |
| 83 | |
| 84 | out_fclose: |
| 85 | fclose(fp); |
| 86 | return tgid; |
| 87 | |
| 88 | out_failure: |
| 89 | pr_warning("couldn't get COMM and pgid, malformed %s\n", filename); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 94 | int (*process)(event_t *event, |
| 95 | struct perf_session *session), |
| 96 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 97 | { |
| 98 | char filename[PATH_MAX]; |
| 99 | FILE *fp; |
| 100 | |
| 101 | snprintf(filename, sizeof(filename), "/proc/%d/maps", pid); |
| 102 | |
| 103 | fp = fopen(filename, "r"); |
| 104 | if (fp == NULL) { |
| 105 | /* |
| 106 | * We raced with a task exiting - just return: |
| 107 | */ |
| 108 | pr_debug("couldn't open %s\n", filename); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | while (1) { |
| 113 | char bf[BUFSIZ], *pbf = bf; |
| 114 | event_t ev = { |
| 115 | .header = { .type = PERF_RECORD_MMAP }, |
| 116 | }; |
| 117 | int n; |
| 118 | size_t size; |
| 119 | if (fgets(bf, sizeof(bf), fp) == NULL) |
| 120 | break; |
| 121 | |
| 122 | /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ |
| 123 | n = hex2u64(pbf, &ev.mmap.start); |
| 124 | if (n < 0) |
| 125 | continue; |
| 126 | pbf += n + 1; |
| 127 | n = hex2u64(pbf, &ev.mmap.len); |
| 128 | if (n < 0) |
| 129 | continue; |
| 130 | pbf += n + 3; |
| 131 | if (*pbf == 'x') { /* vm_exec */ |
| 132 | char *execname = strchr(bf, '/'); |
| 133 | |
| 134 | /* Catch VDSO */ |
| 135 | if (execname == NULL) |
| 136 | execname = strstr(bf, "[vdso]"); |
| 137 | |
| 138 | if (execname == NULL) |
| 139 | continue; |
| 140 | |
| 141 | size = strlen(execname); |
| 142 | execname[size - 1] = '\0'; /* Remove \n */ |
| 143 | memcpy(ev.mmap.filename, execname, size); |
| 144 | size = ALIGN(size, sizeof(u64)); |
| 145 | ev.mmap.len -= ev.mmap.start; |
| 146 | ev.mmap.header.size = (sizeof(ev.mmap) - |
| 147 | (sizeof(ev.mmap.filename) - size)); |
| 148 | ev.mmap.pid = tgid; |
| 149 | ev.mmap.tid = pid; |
| 150 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 151 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | fclose(fp); |
| 156 | return 0; |
| 157 | } |
| 158 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 159 | int event__synthesize_thread(pid_t pid, |
| 160 | int (*process)(event_t *event, |
| 161 | struct perf_session *session), |
| 162 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 163 | { |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 164 | pid_t tgid = event__synthesize_comm(pid, 1, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 165 | if (tgid == -1) |
| 166 | return -1; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 167 | return event__synthesize_mmap_events(pid, tgid, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 168 | } |
| 169 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 170 | void event__synthesize_threads(int (*process)(event_t *event, |
| 171 | struct perf_session *session), |
| 172 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 173 | { |
| 174 | DIR *proc; |
| 175 | struct dirent dirent, *next; |
| 176 | |
| 177 | proc = opendir("/proc"); |
| 178 | |
| 179 | while (!readdir_r(proc, &dirent, &next) && next) { |
| 180 | char *end; |
| 181 | pid_t pid = strtol(dirent.d_name, &end, 10); |
| 182 | |
| 183 | if (*end) /* only interested in proper numerical dirents */ |
| 184 | continue; |
| 185 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 186 | event__synthesize_thread(pid, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | closedir(proc); |
| 190 | } |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 191 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 192 | int event__process_comm(event_t *self, struct perf_session *session) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 193 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 194 | struct thread *thread = perf_session__findnew(session, self->comm.pid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 195 | |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 196 | dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 197 | |
| 198 | if (thread == NULL || thread__set_comm(thread, self->comm.comm)) { |
| 199 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Arnaldo Carvalho de Melo | f823e44 | 2009-12-14 15:06:01 -0200 | [diff] [blame] | 206 | int event__process_lost(event_t *self, struct perf_session *session) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 207 | { |
| 208 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); |
Arnaldo Carvalho de Melo | f823e44 | 2009-12-14 15:06:01 -0200 | [diff] [blame] | 209 | session->events_stats.lost += self->lost.lost; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 213 | int event__process_mmap(event_t *self, struct perf_session *session) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 214 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 215 | struct thread *thread = perf_session__findnew(session, self->mmap.pid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 216 | struct map *map = map__new(&self->mmap, MAP__FUNCTION, |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 217 | session->cwd, session->cwdlen); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 218 | |
| 219 | dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n", |
| 220 | self->mmap.pid, self->mmap.tid, |
| 221 | (void *)(long)self->mmap.start, |
| 222 | (void *)(long)self->mmap.len, |
| 223 | (void *)(long)self->mmap.pgoff, |
| 224 | self->mmap.filename); |
| 225 | |
| 226 | if (thread == NULL || map == NULL) |
| 227 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); |
| 228 | else |
| 229 | thread__insert_map(thread, map); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 234 | int event__process_task(event_t *self, struct perf_session *session) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 235 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 236 | struct thread *thread = perf_session__findnew(session, self->fork.pid); |
| 237 | struct thread *parent = perf_session__findnew(session, self->fork.ppid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 238 | |
| 239 | dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid, |
| 240 | self->fork.ppid, self->fork.ptid); |
| 241 | /* |
| 242 | * A thread clone will have the same PID for both parent and child. |
| 243 | */ |
| 244 | if (thread == parent) |
| 245 | return 0; |
| 246 | |
| 247 | if (self->header.type == PERF_RECORD_EXIT) |
| 248 | return 0; |
| 249 | |
| 250 | if (thread == NULL || parent == NULL || |
| 251 | thread__fork(thread, parent) < 0) { |
| 252 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | return 0; |
| 257 | } |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 258 | |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 259 | void thread__find_addr_location(struct thread *self, |
| 260 | struct perf_session *session, u8 cpumode, |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 261 | enum map_type type, u64 addr, |
| 262 | struct addr_location *al, |
| 263 | symbol_filter_t filter) |
| 264 | { |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 265 | struct map_groups *mg = &self->mg; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 266 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 267 | al->thread = self; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 268 | al->addr = addr; |
| 269 | |
| 270 | if (cpumode & PERF_RECORD_MISC_KERNEL) { |
| 271 | al->level = 'k'; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 272 | mg = &session->kmaps; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 273 | } else if (cpumode & PERF_RECORD_MISC_USER) |
| 274 | al->level = '.'; |
| 275 | else { |
| 276 | al->level = 'H'; |
| 277 | al->map = NULL; |
| 278 | al->sym = NULL; |
| 279 | return; |
| 280 | } |
| 281 | try_again: |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 282 | al->map = map_groups__find(mg, type, al->addr); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 283 | if (al->map == NULL) { |
| 284 | /* |
| 285 | * If this is outside of all known maps, and is a negative |
| 286 | * address, try to look it up in the kernel dso, as it might be |
| 287 | * a vsyscall or vdso (which executes in user-mode). |
| 288 | * |
| 289 | * XXX This is nasty, we should have a symbol list in the |
| 290 | * "[vdso]" dso, but for now lets use the old trick of looking |
| 291 | * in the whole kernel symbol list. |
| 292 | */ |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 293 | if ((long long)al->addr < 0 && mg != &session->kmaps) { |
| 294 | mg = &session->kmaps; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 295 | goto try_again; |
| 296 | } |
| 297 | al->sym = NULL; |
| 298 | } else { |
| 299 | al->addr = al->map->map_ip(al->map, al->addr); |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 300 | al->sym = map__find_symbol(al->map, session, al->addr, filter); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame^] | 304 | static void dso__calc_col_width(struct dso *self) |
| 305 | { |
| 306 | if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 307 | (!symbol_conf.dso_list || |
| 308 | strlist__has_entry(symbol_conf.dso_list, self->name))) { |
| 309 | unsigned int slen = strlen(self->name); |
| 310 | if (slen > dsos__col_width) |
| 311 | dsos__col_width = slen; |
| 312 | } |
| 313 | |
| 314 | self->slen_calculated = 1; |
| 315 | } |
| 316 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 317 | int event__preprocess_sample(const event_t *self, struct perf_session *session, |
| 318 | struct addr_location *al, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 319 | { |
| 320 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 321 | struct thread *thread = perf_session__findnew(session, self->ip.pid); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 322 | |
| 323 | if (thread == NULL) |
| 324 | return -1; |
| 325 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame^] | 326 | if (symbol_conf.comm_list && |
| 327 | !strlist__has_entry(symbol_conf.comm_list, thread->comm)) |
| 328 | goto out_filtered; |
| 329 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 330 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 331 | |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 332 | thread__find_addr_location(thread, session, cpumode, MAP__FUNCTION, |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 333 | self->ip.ip, al, filter); |
| 334 | dump_printf(" ...... dso: %s\n", |
| 335 | al->map ? al->map->dso->long_name : |
| 336 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame^] | 337 | /* |
| 338 | * We have to do this here as we may have a dso with no symbol hit that |
| 339 | * has a name longer than the ones with symbols sampled. |
| 340 | */ |
| 341 | if (al->map && !sort_dso.elide && !al->map->dso->slen_calculated) |
| 342 | dso__calc_col_width(al->map->dso); |
| 343 | |
| 344 | if (symbol_conf.dso_list && |
| 345 | (!al->map || !al->map->dso || |
| 346 | !(strlist__has_entry(symbol_conf.dso_list, al->map->dso->short_name) || |
| 347 | (al->map->dso->short_name != al->map->dso->long_name && |
| 348 | strlist__has_entry(symbol_conf.dso_list, al->map->dso->long_name))))) |
| 349 | goto out_filtered; |
| 350 | |
| 351 | if (symbol_conf.sym_list && al->sym && |
| 352 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) |
| 353 | goto out_filtered; |
| 354 | |
| 355 | al->filtered = false; |
| 356 | return 0; |
| 357 | |
| 358 | out_filtered: |
| 359 | al->filtered = true; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 360 | return 0; |
| 361 | } |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 362 | |
| 363 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data) |
| 364 | { |
| 365 | u64 *array = event->sample.array; |
| 366 | |
| 367 | if (type & PERF_SAMPLE_IP) { |
| 368 | data->ip = event->ip.ip; |
| 369 | array++; |
| 370 | } |
| 371 | |
| 372 | if (type & PERF_SAMPLE_TID) { |
| 373 | u32 *p = (u32 *)array; |
| 374 | data->pid = p[0]; |
| 375 | data->tid = p[1]; |
| 376 | array++; |
| 377 | } |
| 378 | |
| 379 | if (type & PERF_SAMPLE_TIME) { |
| 380 | data->time = *array; |
| 381 | array++; |
| 382 | } |
| 383 | |
| 384 | if (type & PERF_SAMPLE_ADDR) { |
| 385 | data->addr = *array; |
| 386 | array++; |
| 387 | } |
| 388 | |
| 389 | if (type & PERF_SAMPLE_ID) { |
| 390 | data->id = *array; |
| 391 | array++; |
| 392 | } |
| 393 | |
| 394 | if (type & PERF_SAMPLE_STREAM_ID) { |
| 395 | data->stream_id = *array; |
| 396 | array++; |
| 397 | } |
| 398 | |
| 399 | if (type & PERF_SAMPLE_CPU) { |
| 400 | u32 *p = (u32 *)array; |
| 401 | data->cpu = *p; |
| 402 | array++; |
| 403 | } |
| 404 | |
| 405 | if (type & PERF_SAMPLE_PERIOD) { |
| 406 | data->period = *array; |
| 407 | array++; |
| 408 | } |
| 409 | |
| 410 | if (type & PERF_SAMPLE_READ) { |
| 411 | pr_debug("PERF_SAMPLE_READ is unsuported for now\n"); |
| 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | if (type & PERF_SAMPLE_CALLCHAIN) { |
| 416 | data->callchain = (struct ip_callchain *)array; |
| 417 | array += 1 + data->callchain->nr; |
| 418 | } |
| 419 | |
| 420 | if (type & PERF_SAMPLE_RAW) { |
| 421 | u32 *p = (u32 *)array; |
| 422 | data->raw_size = *p; |
| 423 | p++; |
| 424 | data->raw_data = p; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |