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 | cf55311 | 2010-01-07 19:59:40 -0200 | [diff] [blame] | 11 | event__handler_t process, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 12 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 13 | { |
| 14 | event_t ev; |
| 15 | char filename[PATH_MAX]; |
| 16 | char bf[BUFSIZ]; |
| 17 | FILE *fp; |
| 18 | size_t size = 0; |
| 19 | DIR *tasks; |
| 20 | struct dirent dirent, *next; |
| 21 | pid_t tgid = 0; |
| 22 | |
| 23 | snprintf(filename, sizeof(filename), "/proc/%d/status", pid); |
| 24 | |
| 25 | fp = fopen(filename, "r"); |
| 26 | if (fp == NULL) { |
| 27 | out_race: |
| 28 | /* |
| 29 | * We raced with a task exiting - just return: |
| 30 | */ |
| 31 | pr_debug("couldn't open %s\n", filename); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | memset(&ev.comm, 0, sizeof(ev.comm)); |
| 36 | while (!ev.comm.comm[0] || !ev.comm.pid) { |
| 37 | if (fgets(bf, sizeof(bf), fp) == NULL) |
| 38 | goto out_failure; |
| 39 | |
| 40 | if (memcmp(bf, "Name:", 5) == 0) { |
| 41 | char *name = bf + 5; |
| 42 | while (*name && isspace(*name)) |
| 43 | ++name; |
| 44 | size = strlen(name) - 1; |
| 45 | memcpy(ev.comm.comm, name, size++); |
| 46 | } else if (memcmp(bf, "Tgid:", 5) == 0) { |
| 47 | char *tgids = bf + 5; |
| 48 | while (*tgids && isspace(*tgids)) |
| 49 | ++tgids; |
| 50 | tgid = ev.comm.pid = atoi(tgids); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | ev.comm.header.type = PERF_RECORD_COMM; |
| 55 | size = ALIGN(size, sizeof(u64)); |
| 56 | ev.comm.header.size = sizeof(ev.comm) - (sizeof(ev.comm.comm) - size); |
| 57 | |
| 58 | if (!full) { |
| 59 | ev.comm.tid = pid; |
| 60 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 61 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 62 | goto out_fclose; |
| 63 | } |
| 64 | |
| 65 | snprintf(filename, sizeof(filename), "/proc/%d/task", pid); |
| 66 | |
| 67 | tasks = opendir(filename); |
| 68 | if (tasks == NULL) |
| 69 | goto out_race; |
| 70 | |
| 71 | while (!readdir_r(tasks, &dirent, &next) && next) { |
| 72 | char *end; |
| 73 | pid = strtol(dirent.d_name, &end, 10); |
| 74 | if (*end) |
| 75 | continue; |
| 76 | |
| 77 | ev.comm.tid = pid; |
| 78 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 79 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 80 | } |
| 81 | closedir(tasks); |
| 82 | |
| 83 | out_fclose: |
| 84 | fclose(fp); |
| 85 | return tgid; |
| 86 | |
| 87 | out_failure: |
| 88 | pr_warning("couldn't get COMM and pgid, malformed %s\n", filename); |
| 89 | return -1; |
| 90 | } |
| 91 | |
| 92 | static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, |
Arnaldo Carvalho de Melo | cf55311 | 2010-01-07 19:59:40 -0200 | [diff] [blame] | 93 | event__handler_t process, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 94 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 95 | { |
| 96 | char filename[PATH_MAX]; |
| 97 | FILE *fp; |
| 98 | |
| 99 | snprintf(filename, sizeof(filename), "/proc/%d/maps", pid); |
| 100 | |
| 101 | fp = fopen(filename, "r"); |
| 102 | if (fp == NULL) { |
| 103 | /* |
| 104 | * We raced with a task exiting - just return: |
| 105 | */ |
| 106 | pr_debug("couldn't open %s\n", filename); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | while (1) { |
| 111 | char bf[BUFSIZ], *pbf = bf; |
| 112 | event_t ev = { |
Arnaldo Carvalho de Melo | 18c3daa | 2010-01-14 23:45:28 -0200 | [diff] [blame] | 113 | .header = { |
| 114 | .type = PERF_RECORD_MMAP, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 115 | /* |
| 116 | * Just like the kernel, see __perf_event_mmap |
| 117 | * in kernel/perf_event.c |
| 118 | */ |
| 119 | .misc = PERF_RECORD_MISC_USER, |
Arnaldo Carvalho de Melo | 18c3daa | 2010-01-14 23:45:28 -0200 | [diff] [blame] | 120 | }, |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 121 | }; |
| 122 | int n; |
| 123 | size_t size; |
| 124 | if (fgets(bf, sizeof(bf), fp) == NULL) |
| 125 | break; |
| 126 | |
| 127 | /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ |
| 128 | n = hex2u64(pbf, &ev.mmap.start); |
| 129 | if (n < 0) |
| 130 | continue; |
| 131 | pbf += n + 1; |
| 132 | n = hex2u64(pbf, &ev.mmap.len); |
| 133 | if (n < 0) |
| 134 | continue; |
| 135 | pbf += n + 3; |
| 136 | if (*pbf == 'x') { /* vm_exec */ |
Anton Blanchard | 4af8b35 | 2010-04-03 22:53:31 +1100 | [diff] [blame] | 137 | u64 vm_pgoff; |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 138 | char *execname = strchr(bf, '/'); |
| 139 | |
| 140 | /* Catch VDSO */ |
| 141 | if (execname == NULL) |
| 142 | execname = strstr(bf, "[vdso]"); |
| 143 | |
| 144 | if (execname == NULL) |
| 145 | continue; |
| 146 | |
Anton Blanchard | 4af8b35 | 2010-04-03 22:53:31 +1100 | [diff] [blame] | 147 | pbf += 3; |
| 148 | n = hex2u64(pbf, &vm_pgoff); |
| 149 | /* pgoff is in bytes, not pages */ |
| 150 | if (n >= 0) |
| 151 | ev.mmap.pgoff = vm_pgoff << getpagesize(); |
| 152 | else |
| 153 | ev.mmap.pgoff = 0; |
| 154 | |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 155 | size = strlen(execname); |
| 156 | execname[size - 1] = '\0'; /* Remove \n */ |
| 157 | memcpy(ev.mmap.filename, execname, size); |
| 158 | size = ALIGN(size, sizeof(u64)); |
| 159 | ev.mmap.len -= ev.mmap.start; |
| 160 | ev.mmap.header.size = (sizeof(ev.mmap) - |
| 161 | (sizeof(ev.mmap.filename) - size)); |
| 162 | ev.mmap.pid = tgid; |
| 163 | ev.mmap.tid = pid; |
| 164 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 165 | process(&ev, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | fclose(fp); |
| 170 | return 0; |
| 171 | } |
| 172 | |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 173 | int event__synthesize_modules(event__handler_t process, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 174 | struct perf_session *session, |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 175 | struct machine *machine) |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 176 | { |
| 177 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 178 | struct map_groups *kmaps = &machine->kmaps; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 179 | u16 misc; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 180 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 181 | /* |
| 182 | * kernel uses 0 for user space maps, see kernel/perf_event.c |
| 183 | * __perf_event_mmap |
| 184 | */ |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 185 | if (machine__is_host(machine)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 186 | misc = PERF_RECORD_MISC_KERNEL; |
| 187 | else |
| 188 | misc = PERF_RECORD_MISC_GUEST_KERNEL; |
| 189 | |
| 190 | for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 191 | nd; nd = rb_next(nd)) { |
| 192 | event_t ev; |
| 193 | size_t size; |
| 194 | struct map *pos = rb_entry(nd, struct map, rb_node); |
| 195 | |
| 196 | if (pos->dso->kernel) |
| 197 | continue; |
| 198 | |
| 199 | size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); |
| 200 | memset(&ev, 0, sizeof(ev)); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 201 | ev.mmap.header.misc = misc; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 202 | ev.mmap.header.type = PERF_RECORD_MMAP; |
| 203 | ev.mmap.header.size = (sizeof(ev.mmap) - |
| 204 | (sizeof(ev.mmap.filename) - size)); |
| 205 | ev.mmap.start = pos->start; |
| 206 | ev.mmap.len = pos->end - pos->start; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 207 | ev.mmap.pid = machine->pid; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 208 | |
| 209 | memcpy(ev.mmap.filename, pos->dso->long_name, |
| 210 | pos->dso->long_name_len + 1); |
| 211 | process(&ev, session); |
| 212 | } |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
Arnaldo Carvalho de Melo | cf55311 | 2010-01-07 19:59:40 -0200 | [diff] [blame] | 217 | int event__synthesize_thread(pid_t pid, event__handler_t process, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 218 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 219 | { |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 220 | pid_t tgid = event__synthesize_comm(pid, 1, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 221 | if (tgid == -1) |
| 222 | return -1; |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 223 | return event__synthesize_mmap_events(pid, tgid, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 224 | } |
| 225 | |
Arnaldo Carvalho de Melo | cf55311 | 2010-01-07 19:59:40 -0200 | [diff] [blame] | 226 | void event__synthesize_threads(event__handler_t process, |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 227 | struct perf_session *session) |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 228 | { |
| 229 | DIR *proc; |
| 230 | struct dirent dirent, *next; |
| 231 | |
| 232 | proc = opendir("/proc"); |
| 233 | |
| 234 | while (!readdir_r(proc, &dirent, &next) && next) { |
| 235 | char *end; |
| 236 | pid_t pid = strtol(dirent.d_name, &end, 10); |
| 237 | |
| 238 | if (*end) /* only interested in proper numerical dirents */ |
| 239 | continue; |
| 240 | |
Arnaldo Carvalho de Melo | d8f6624 | 2009-12-13 19:50:24 -0200 | [diff] [blame] | 241 | event__synthesize_thread(pid, process, session); |
Arnaldo Carvalho de Melo | 234fbbf | 2009-10-26 19:23:18 -0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | closedir(proc); |
| 245 | } |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 246 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 247 | struct process_symbol_args { |
| 248 | const char *name; |
| 249 | u64 start; |
| 250 | }; |
| 251 | |
| 252 | static int find_symbol_cb(void *arg, const char *name, char type, u64 start) |
| 253 | { |
| 254 | struct process_symbol_args *args = arg; |
| 255 | |
Arnaldo Carvalho de Melo | 881516e | 2010-01-15 18:08:27 -0200 | [diff] [blame] | 256 | /* |
| 257 | * Must be a function or at least an alias, as in PARISC64, where "_text" is |
| 258 | * an 'A' to the same address as "_stext". |
| 259 | */ |
| 260 | if (!(symbol_type__is_a(type, MAP__FUNCTION) || |
| 261 | type == 'A') || strcmp(name, args->name)) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 262 | return 0; |
| 263 | |
| 264 | args->start = start; |
| 265 | return 1; |
| 266 | } |
| 267 | |
Arnaldo Carvalho de Melo | cf55311 | 2010-01-07 19:59:40 -0200 | [diff] [blame] | 268 | int event__synthesize_kernel_mmap(event__handler_t process, |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 269 | struct perf_session *session, |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 270 | struct machine *machine, |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 271 | const char *symbol_name) |
| 272 | { |
| 273 | size_t size; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 274 | const char *filename, *mmap_name; |
| 275 | char path[PATH_MAX]; |
| 276 | char name_buff[PATH_MAX]; |
| 277 | struct map *map; |
| 278 | |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 279 | event_t ev = { |
Arnaldo Carvalho de Melo | 18c3daa | 2010-01-14 23:45:28 -0200 | [diff] [blame] | 280 | .header = { |
| 281 | .type = PERF_RECORD_MMAP, |
Arnaldo Carvalho de Melo | 18c3daa | 2010-01-14 23:45:28 -0200 | [diff] [blame] | 282 | }, |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 283 | }; |
| 284 | /* |
| 285 | * We should get this from /sys/kernel/sections/.text, but till that is |
| 286 | * available use this, and after it is use this as a fallback for older |
| 287 | * kernels. |
| 288 | */ |
| 289 | struct process_symbol_args args = { .name = symbol_name, }; |
| 290 | |
Arnaldo Carvalho de Melo | 48ea8f5 | 2010-04-27 21:19:05 -0300 | [diff] [blame] | 291 | mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff)); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 292 | if (machine__is_host(machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 293 | /* |
| 294 | * kernel uses PERF_RECORD_MISC_USER for user space maps, |
| 295 | * see kernel/perf_event.c __perf_event_mmap |
| 296 | */ |
| 297 | ev.header.misc = PERF_RECORD_MISC_KERNEL; |
| 298 | filename = "/proc/kallsyms"; |
| 299 | } else { |
| 300 | ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 301 | if (machine__is_default_guest(machine)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 302 | filename = (char *) symbol_conf.default_guest_kallsyms; |
| 303 | else { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 304 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 305 | filename = path; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0) |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 310 | return -ENOENT; |
| 311 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 312 | map = machine->vmlinux_maps[MAP__FUNCTION]; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 313 | size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename), |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 314 | "%s%s", mmap_name, symbol_name) + 1; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 315 | size = ALIGN(size, sizeof(u64)); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 316 | ev.mmap.header.size = (sizeof(ev.mmap) - |
| 317 | (sizeof(ev.mmap.filename) - size)); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 318 | ev.mmap.pgoff = args.start; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 319 | ev.mmap.start = map->start; |
| 320 | ev.mmap.len = map->end - ev.mmap.start; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 321 | ev.mmap.pid = machine->pid; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 322 | |
| 323 | return process(&ev, session); |
| 324 | } |
| 325 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 326 | static void thread__comm_adjust(struct thread *self) |
| 327 | { |
| 328 | char *comm = self->comm; |
| 329 | |
| 330 | if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 331 | (!symbol_conf.comm_list || |
| 332 | strlist__has_entry(symbol_conf.comm_list, comm))) { |
| 333 | unsigned int slen = strlen(comm); |
| 334 | |
| 335 | if (slen > comms__col_width) { |
| 336 | comms__col_width = slen; |
| 337 | threads__col_width = slen + 6; |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | static int thread__set_comm_adjust(struct thread *self, const char *comm) |
| 343 | { |
| 344 | int ret = thread__set_comm(self, comm); |
| 345 | |
| 346 | if (ret) |
| 347 | return ret; |
| 348 | |
| 349 | thread__comm_adjust(self); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 354 | 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] | 355 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 356 | struct thread *thread = perf_session__findnew(session, self->comm.pid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 357 | |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 358 | 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] | 359 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 360 | if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm)) { |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 361 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); |
| 362 | return -1; |
| 363 | } |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
Arnaldo Carvalho de Melo | f823e44 | 2009-12-14 15:06:01 -0200 | [diff] [blame] | 368 | 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] | 369 | { |
| 370 | 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] | 371 | session->events_stats.lost += self->lost.lost; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 375 | static void event_set_kernel_mmap_len(struct map **maps, event_t *self) |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 376 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 377 | maps[MAP__FUNCTION]->start = self->mmap.start; |
| 378 | maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len; |
| 379 | /* |
| 380 | * Be a bit paranoid here, some perf.data file came with |
| 381 | * a zero sized synthesized MMAP event for the kernel. |
| 382 | */ |
| 383 | if (maps[MAP__FUNCTION]->end == 0) |
| 384 | maps[MAP__FUNCTION]->end = ~0UL; |
| 385 | } |
| 386 | |
| 387 | static int event__process_kernel_mmap(event_t *self, |
| 388 | struct perf_session *session) |
| 389 | { |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 390 | struct map *map; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 391 | char kmmap_prefix[PATH_MAX]; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 392 | struct machine *machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 393 | enum dso_kernel_type kernel_type; |
| 394 | bool is_kernel_mmap; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 395 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 396 | machine = perf_session__findnew_machine(session, self->mmap.pid); |
| 397 | if (!machine) { |
| 398 | pr_err("Can't find id %d's machine\n", self->mmap.pid); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 399 | goto out_problem; |
| 400 | } |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 401 | |
Arnaldo Carvalho de Melo | 48ea8f5 | 2010-04-27 21:19:05 -0300 | [diff] [blame] | 402 | machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix)); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 403 | if (machine__is_host(machine)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 404 | kernel_type = DSO_TYPE_KERNEL; |
| 405 | else |
| 406 | kernel_type = DSO_TYPE_GUEST_KERNEL; |
| 407 | |
| 408 | is_kernel_mmap = memcmp(self->mmap.filename, |
| 409 | kmmap_prefix, |
| 410 | strlen(kmmap_prefix)) == 0; |
| 411 | if (self->mmap.filename[0] == '/' || |
| 412 | (!is_kernel_mmap && self->mmap.filename[0] == '[')) { |
| 413 | |
| 414 | char short_module_name[1024]; |
| 415 | char *name, *dot; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 416 | |
| 417 | if (self->mmap.filename[0] == '/') { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 418 | name = strrchr(self->mmap.filename, '/'); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 419 | if (name == NULL) |
| 420 | goto out_problem; |
| 421 | |
| 422 | ++name; /* skip / */ |
| 423 | dot = strrchr(name, '.'); |
| 424 | if (dot == NULL) |
| 425 | goto out_problem; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 426 | snprintf(short_module_name, sizeof(short_module_name), |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 427 | "[%.*s]", (int)(dot - name), name); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 428 | strxfrchar(short_module_name, '-', '_'); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 429 | } else |
| 430 | strcpy(short_module_name, self->mmap.filename); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 431 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 432 | map = machine__new_module(machine, self->mmap.start, |
| 433 | self->mmap.filename); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 434 | if (map == NULL) |
| 435 | goto out_problem; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 436 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 437 | name = strdup(short_module_name); |
| 438 | if (name == NULL) |
| 439 | goto out_problem; |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 440 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 441 | map->dso->short_name = name; |
| 442 | map->end = map->start + self->mmap.len; |
| 443 | } else if (is_kernel_mmap) { |
| 444 | const char *symbol_name = (self->mmap.filename + |
| 445 | strlen(kmmap_prefix)); |
| 446 | /* |
| 447 | * Should be there already, from the build-id table in |
| 448 | * the header. |
| 449 | */ |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 450 | struct dso *kernel = __dsos__findnew(&machine->kernel_dsos, |
| 451 | kmmap_prefix); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 452 | if (kernel == NULL) |
| 453 | goto out_problem; |
| 454 | |
| 455 | kernel->kernel = kernel_type; |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 456 | if (__machine__create_kernel_maps(machine, kernel) < 0) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 457 | goto out_problem; |
| 458 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 459 | event_set_kernel_mmap_len(machine->vmlinux_maps, self); |
| 460 | perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, |
| 461 | symbol_name, |
| 462 | self->mmap.pgoff); |
| 463 | if (machine__is_default_guest(machine)) { |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 464 | /* |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 465 | * preload dso of guest kernel and modules |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 466 | */ |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 467 | dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION], |
| 468 | NULL); |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 469 | } |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 470 | } |
| 471 | return 0; |
| 472 | out_problem: |
| 473 | return -1; |
| 474 | } |
| 475 | |
| 476 | int event__process_mmap(event_t *self, struct perf_session *session) |
| 477 | { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 478 | struct machine *machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 479 | struct thread *thread; |
| 480 | struct map *map; |
| 481 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 482 | int ret = 0; |
| 483 | |
| 484 | dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n", |
| 485 | self->mmap.pid, self->mmap.tid, self->mmap.start, |
| 486 | self->mmap.len, self->mmap.pgoff, self->mmap.filename); |
| 487 | |
| 488 | if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || |
| 489 | cpumode == PERF_RECORD_MISC_KERNEL) { |
| 490 | ret = event__process_kernel_mmap(self, session); |
| 491 | if (ret < 0) |
| 492 | goto out_problem; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | thread = perf_session__findnew(session, self->mmap.pid); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 497 | machine = perf_session__find_host_machine(session); |
| 498 | map = map__new(&machine->user_dsos, self->mmap.start, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 499 | self->mmap.len, self->mmap.pgoff, |
| 500 | self->mmap.pid, self->mmap.filename, |
| 501 | MAP__FUNCTION, session->cwd, session->cwdlen); |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 502 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 503 | if (thread == NULL || map == NULL) |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 504 | goto out_problem; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 505 | |
Arnaldo Carvalho de Melo | b7cece7 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 506 | thread__insert_map(thread, map); |
| 507 | return 0; |
| 508 | |
| 509 | out_problem: |
| 510 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 514 | 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] | 515 | { |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 516 | struct thread *thread = perf_session__findnew(session, self->fork.pid); |
| 517 | struct thread *parent = perf_session__findnew(session, self->fork.ppid); |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 518 | |
| 519 | dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid, |
| 520 | self->fork.ppid, self->fork.ptid); |
| 521 | /* |
| 522 | * A thread clone will have the same PID for both parent and child. |
| 523 | */ |
| 524 | if (thread == parent) |
| 525 | return 0; |
| 526 | |
| 527 | if (self->header.type == PERF_RECORD_EXIT) |
| 528 | return 0; |
| 529 | |
| 530 | if (thread == NULL || parent == NULL || |
| 531 | thread__fork(thread, parent) < 0) { |
| 532 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); |
| 533 | return -1; |
| 534 | } |
| 535 | |
| 536 | return 0; |
| 537 | } |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 538 | |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 539 | void thread__find_addr_map(struct thread *self, |
| 540 | struct perf_session *session, u8 cpumode, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 541 | enum map_type type, pid_t pid, u64 addr, |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 542 | struct addr_location *al) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 543 | { |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 544 | struct map_groups *mg = &self->mg; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 545 | struct machine *machine = NULL; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 546 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 547 | al->thread = self; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 548 | al->addr = addr; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 549 | al->cpumode = cpumode; |
| 550 | al->filtered = false; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 551 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 552 | if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 553 | al->level = 'k'; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 554 | machine = perf_session__find_host_machine(session); |
| 555 | mg = &machine->kmaps; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 556 | } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 557 | al->level = '.'; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 558 | machine = perf_session__find_host_machine(session); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 559 | } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { |
| 560 | al->level = 'g'; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 561 | machine = perf_session__find_machine(session, pid); |
| 562 | if (!machine) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 563 | al->map = NULL; |
| 564 | return; |
| 565 | } |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 566 | mg = &machine->kmaps; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 567 | } else { |
| 568 | /* |
| 569 | * 'u' means guest os user space. |
| 570 | * TODO: We don't support guest user space. Might support late. |
| 571 | */ |
| 572 | if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) |
| 573 | al->level = 'u'; |
| 574 | else |
| 575 | al->level = 'H'; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 576 | al->map = NULL; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 577 | |
| 578 | if ((cpumode == PERF_RECORD_MISC_GUEST_USER || |
| 579 | cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && |
| 580 | !perf_guest) |
| 581 | al->filtered = true; |
| 582 | if ((cpumode == PERF_RECORD_MISC_USER || |
| 583 | cpumode == PERF_RECORD_MISC_KERNEL) && |
| 584 | !perf_host) |
| 585 | al->filtered = true; |
| 586 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 587 | return; |
| 588 | } |
| 589 | try_again: |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 590 | al->map = map_groups__find(mg, type, al->addr); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 591 | if (al->map == NULL) { |
| 592 | /* |
| 593 | * If this is outside of all known maps, and is a negative |
| 594 | * address, try to look it up in the kernel dso, as it might be |
| 595 | * a vsyscall or vdso (which executes in user-mode). |
| 596 | * |
| 597 | * XXX This is nasty, we should have a symbol list in the |
| 598 | * "[vdso]" dso, but for now lets use the old trick of looking |
| 599 | * in the whole kernel symbol list. |
| 600 | */ |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 601 | if ((long long)al->addr < 0 && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 602 | cpumode == PERF_RECORD_MISC_KERNEL && |
| 603 | machine && mg != &machine->kmaps) { |
| 604 | mg = &machine->kmaps; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 605 | goto try_again; |
| 606 | } |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 607 | } else |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 608 | al->addr = al->map->map_ip(al->map, al->addr); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | void thread__find_addr_location(struct thread *self, |
| 612 | struct perf_session *session, u8 cpumode, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 613 | enum map_type type, pid_t pid, u64 addr, |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 614 | struct addr_location *al, |
| 615 | symbol_filter_t filter) |
| 616 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 617 | thread__find_addr_map(self, session, cpumode, type, pid, addr, al); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 618 | if (al->map != NULL) |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 619 | al->sym = map__find_symbol(al->map, al->addr, filter); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 620 | else |
| 621 | al->sym = NULL; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 622 | } |
| 623 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 624 | static void dso__calc_col_width(struct dso *self) |
| 625 | { |
| 626 | if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 627 | (!symbol_conf.dso_list || |
| 628 | strlist__has_entry(symbol_conf.dso_list, self->name))) { |
Arnaldo Carvalho de Melo | 9890948 | 2010-05-04 20:58:51 -0300 | [diff] [blame^] | 629 | u16 slen = self->short_name_len; |
| 630 | if (verbose) |
| 631 | slen = self->long_name_len; |
| 632 | if (dsos__col_width < slen) |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 633 | dsos__col_width = slen; |
| 634 | } |
| 635 | |
| 636 | self->slen_calculated = 1; |
| 637 | } |
| 638 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 639 | int event__preprocess_sample(const event_t *self, struct perf_session *session, |
| 640 | struct addr_location *al, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 641 | { |
| 642 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 643 | struct thread *thread = perf_session__findnew(session, self->ip.pid); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 644 | |
| 645 | if (thread == NULL) |
| 646 | return -1; |
| 647 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 648 | if (symbol_conf.comm_list && |
| 649 | !strlist__has_entry(symbol_conf.comm_list, thread->comm)) |
| 650 | goto out_filtered; |
| 651 | |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 652 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
| 653 | |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 654 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 655 | self->ip.pid, self->ip.ip, al); |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 656 | dump_printf(" ...... dso: %s\n", |
| 657 | al->map ? al->map->dso->long_name : |
| 658 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 659 | al->sym = NULL; |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 660 | |
Arnaldo Carvalho de Melo | 96415e4 | 2010-03-24 16:40:15 -0300 | [diff] [blame] | 661 | if (al->map) { |
| 662 | if (symbol_conf.dso_list && |
| 663 | (!al->map || !al->map->dso || |
| 664 | !(strlist__has_entry(symbol_conf.dso_list, |
| 665 | al->map->dso->short_name) || |
| 666 | (al->map->dso->short_name != al->map->dso->long_name && |
| 667 | strlist__has_entry(symbol_conf.dso_list, |
| 668 | al->map->dso->long_name))))) |
| 669 | goto out_filtered; |
| 670 | /* |
| 671 | * We have to do this here as we may have a dso with no symbol |
| 672 | * hit that has a name longer than the ones with symbols |
| 673 | * sampled. |
| 674 | */ |
| 675 | if (!sort_dso.elide && !al->map->dso->slen_calculated) |
| 676 | dso__calc_col_width(al->map->dso); |
| 677 | |
| 678 | al->sym = map__find_symbol(al->map, al->addr, filter); |
| 679 | } |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 680 | |
| 681 | if (symbol_conf.sym_list && al->sym && |
| 682 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) |
| 683 | goto out_filtered; |
| 684 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 685 | return 0; |
| 686 | |
| 687 | out_filtered: |
| 688 | al->filtered = true; |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 689 | return 0; |
| 690 | } |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 691 | |
| 692 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data) |
| 693 | { |
| 694 | u64 *array = event->sample.array; |
| 695 | |
| 696 | if (type & PERF_SAMPLE_IP) { |
| 697 | data->ip = event->ip.ip; |
| 698 | array++; |
| 699 | } |
| 700 | |
| 701 | if (type & PERF_SAMPLE_TID) { |
| 702 | u32 *p = (u32 *)array; |
| 703 | data->pid = p[0]; |
| 704 | data->tid = p[1]; |
| 705 | array++; |
| 706 | } |
| 707 | |
| 708 | if (type & PERF_SAMPLE_TIME) { |
| 709 | data->time = *array; |
| 710 | array++; |
| 711 | } |
| 712 | |
| 713 | if (type & PERF_SAMPLE_ADDR) { |
| 714 | data->addr = *array; |
| 715 | array++; |
| 716 | } |
| 717 | |
Anton Blanchard | 02bf60a | 2010-05-04 21:19:15 +1000 | [diff] [blame] | 718 | data->id = -1ULL; |
OGAWA Hirofumi | 180f95e | 2009-12-06 20:08:24 +0900 | [diff] [blame] | 719 | if (type & PERF_SAMPLE_ID) { |
| 720 | data->id = *array; |
| 721 | array++; |
| 722 | } |
| 723 | |
| 724 | if (type & PERF_SAMPLE_STREAM_ID) { |
| 725 | data->stream_id = *array; |
| 726 | array++; |
| 727 | } |
| 728 | |
| 729 | if (type & PERF_SAMPLE_CPU) { |
| 730 | u32 *p = (u32 *)array; |
| 731 | data->cpu = *p; |
| 732 | array++; |
| 733 | } |
| 734 | |
| 735 | if (type & PERF_SAMPLE_PERIOD) { |
| 736 | data->period = *array; |
| 737 | array++; |
| 738 | } |
| 739 | |
| 740 | if (type & PERF_SAMPLE_READ) { |
| 741 | pr_debug("PERF_SAMPLE_READ is unsuported for now\n"); |
| 742 | return -1; |
| 743 | } |
| 744 | |
| 745 | if (type & PERF_SAMPLE_CALLCHAIN) { |
| 746 | data->callchain = (struct ip_callchain *)array; |
| 747 | array += 1 + data->callchain->nr; |
| 748 | } |
| 749 | |
| 750 | if (type & PERF_SAMPLE_RAW) { |
| 751 | u32 *p = (u32 *)array; |
| 752 | data->raw_size = *p; |
| 753 | p++; |
| 754 | data->raw_data = p; |
| 755 | } |
| 756 | |
| 757 | return 0; |
| 758 | } |