Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 1 | #include <traceevent/event-parse.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2 | #include "builtin.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 3 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 4 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 5 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 6 | #include "util/machine.h" |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 7 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 8 | #include "util/thread.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 9 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 10 | #include "util/strlist.h" |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 11 | #include "util/intlist.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 12 | #include "util/thread_map.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 13 | |
| 14 | #include <libaudit.h> |
| 15 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 16 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 17 | #include <linux/futex.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 18 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 19 | static size_t syscall_arg__scnprintf_hex(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 20 | unsigned long arg, |
| 21 | u8 arg_idx __maybe_unused, |
| 22 | u8 *arg_mask __maybe_unused) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 23 | { |
| 24 | return scnprintf(bf, size, "%#lx", arg); |
| 25 | } |
| 26 | |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 27 | #define SCA_HEX syscall_arg__scnprintf_hex |
| 28 | |
Arnaldo Carvalho de Melo | 579e786 | 2013-09-02 15:37:32 -0300 | [diff] [blame] | 29 | static size_t syscall_arg__scnprintf_whence(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 30 | unsigned long arg, |
| 31 | u8 arg_idx __maybe_unused, |
| 32 | u8 *arg_mask __maybe_unused) |
Arnaldo Carvalho de Melo | 579e786 | 2013-09-02 15:37:32 -0300 | [diff] [blame] | 33 | { |
| 34 | int whence = arg; |
| 35 | |
| 36 | switch (whence) { |
| 37 | #define P_WHENCE(n) case SEEK_##n: return scnprintf(bf, size, #n) |
| 38 | P_WHENCE(SET); |
| 39 | P_WHENCE(CUR); |
| 40 | P_WHENCE(END); |
| 41 | #ifdef SEEK_DATA |
| 42 | P_WHENCE(DATA); |
| 43 | #endif |
| 44 | #ifdef SEEK_HOLE |
| 45 | P_WHENCE(HOLE); |
| 46 | #endif |
| 47 | #undef P_WHENCE |
| 48 | default: break; |
| 49 | } |
| 50 | |
| 51 | return scnprintf(bf, size, "%#x", whence); |
| 52 | } |
| 53 | |
| 54 | #define SCA_WHENCE syscall_arg__scnprintf_whence |
| 55 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 56 | static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 57 | unsigned long arg, |
| 58 | u8 arg_idx __maybe_unused, |
| 59 | u8 *arg_mask __maybe_unused) |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 60 | { |
| 61 | int printed = 0, prot = arg; |
| 62 | |
| 63 | if (prot == PROT_NONE) |
| 64 | return scnprintf(bf, size, "NONE"); |
| 65 | #define P_MMAP_PROT(n) \ |
| 66 | if (prot & PROT_##n) { \ |
| 67 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 68 | prot &= ~PROT_##n; \ |
| 69 | } |
| 70 | |
| 71 | P_MMAP_PROT(EXEC); |
| 72 | P_MMAP_PROT(READ); |
| 73 | P_MMAP_PROT(WRITE); |
| 74 | #ifdef PROT_SEM |
| 75 | P_MMAP_PROT(SEM); |
| 76 | #endif |
| 77 | P_MMAP_PROT(GROWSDOWN); |
| 78 | P_MMAP_PROT(GROWSUP); |
| 79 | #undef P_MMAP_PROT |
| 80 | |
| 81 | if (prot) |
| 82 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot); |
| 83 | |
| 84 | return printed; |
| 85 | } |
| 86 | |
| 87 | #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot |
| 88 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 89 | static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 90 | unsigned long arg, u8 arg_idx __maybe_unused, |
| 91 | u8 *arg_mask __maybe_unused) |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 92 | { |
| 93 | int printed = 0, flags = arg; |
| 94 | |
| 95 | #define P_MMAP_FLAG(n) \ |
| 96 | if (flags & MAP_##n) { \ |
| 97 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 98 | flags &= ~MAP_##n; \ |
| 99 | } |
| 100 | |
| 101 | P_MMAP_FLAG(SHARED); |
| 102 | P_MMAP_FLAG(PRIVATE); |
| 103 | P_MMAP_FLAG(32BIT); |
| 104 | P_MMAP_FLAG(ANONYMOUS); |
| 105 | P_MMAP_FLAG(DENYWRITE); |
| 106 | P_MMAP_FLAG(EXECUTABLE); |
| 107 | P_MMAP_FLAG(FILE); |
| 108 | P_MMAP_FLAG(FIXED); |
| 109 | P_MMAP_FLAG(GROWSDOWN); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 110 | #ifdef MAP_HUGETLB |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 111 | P_MMAP_FLAG(HUGETLB); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 112 | #endif |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 113 | P_MMAP_FLAG(LOCKED); |
| 114 | P_MMAP_FLAG(NONBLOCK); |
| 115 | P_MMAP_FLAG(NORESERVE); |
| 116 | P_MMAP_FLAG(POPULATE); |
| 117 | P_MMAP_FLAG(STACK); |
| 118 | #ifdef MAP_UNINITIALIZED |
| 119 | P_MMAP_FLAG(UNINITIALIZED); |
| 120 | #endif |
| 121 | #undef P_MMAP_FLAG |
| 122 | |
| 123 | if (flags) |
| 124 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 125 | |
| 126 | return printed; |
| 127 | } |
| 128 | |
| 129 | #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags |
| 130 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 131 | static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 132 | unsigned long arg, u8 arg_idx __maybe_unused, |
| 133 | u8 *arg_mask __maybe_unused) |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 134 | { |
| 135 | int behavior = arg; |
| 136 | |
| 137 | switch (behavior) { |
| 138 | #define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n) |
| 139 | P_MADV_BHV(NORMAL); |
| 140 | P_MADV_BHV(RANDOM); |
| 141 | P_MADV_BHV(SEQUENTIAL); |
| 142 | P_MADV_BHV(WILLNEED); |
| 143 | P_MADV_BHV(DONTNEED); |
| 144 | P_MADV_BHV(REMOVE); |
| 145 | P_MADV_BHV(DONTFORK); |
| 146 | P_MADV_BHV(DOFORK); |
| 147 | P_MADV_BHV(HWPOISON); |
| 148 | #ifdef MADV_SOFT_OFFLINE |
| 149 | P_MADV_BHV(SOFT_OFFLINE); |
| 150 | #endif |
| 151 | P_MADV_BHV(MERGEABLE); |
| 152 | P_MADV_BHV(UNMERGEABLE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 153 | #ifdef MADV_HUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 154 | P_MADV_BHV(HUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 155 | #endif |
| 156 | #ifdef MADV_NOHUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 157 | P_MADV_BHV(NOHUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 158 | #endif |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 159 | #ifdef MADV_DONTDUMP |
| 160 | P_MADV_BHV(DONTDUMP); |
| 161 | #endif |
| 162 | #ifdef MADV_DODUMP |
| 163 | P_MADV_BHV(DODUMP); |
| 164 | #endif |
| 165 | #undef P_MADV_PHV |
| 166 | default: break; |
| 167 | } |
| 168 | |
| 169 | return scnprintf(bf, size, "%#x", behavior); |
| 170 | } |
| 171 | |
| 172 | #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior |
| 173 | |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 174 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned long arg, |
| 175 | u8 arg_idx __maybe_unused, u8 *arg_mask) |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 176 | { |
| 177 | enum syscall_futex_args { |
| 178 | SCF_UADDR = (1 << 0), |
| 179 | SCF_OP = (1 << 1), |
| 180 | SCF_VAL = (1 << 2), |
| 181 | SCF_TIMEOUT = (1 << 3), |
| 182 | SCF_UADDR2 = (1 << 4), |
| 183 | SCF_VAL3 = (1 << 5), |
| 184 | }; |
| 185 | int op = arg; |
| 186 | int cmd = op & FUTEX_CMD_MASK; |
| 187 | size_t printed = 0; |
| 188 | |
| 189 | switch (cmd) { |
| 190 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); |
| 191 | P_FUTEX_OP(WAIT); *arg_mask |= SCF_VAL3|SCF_UADDR2; break; |
| 192 | P_FUTEX_OP(WAKE); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 193 | P_FUTEX_OP(FD); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 194 | P_FUTEX_OP(REQUEUE); *arg_mask |= SCF_VAL3|SCF_TIMEOUT; break; |
| 195 | P_FUTEX_OP(CMP_REQUEUE); *arg_mask |= SCF_TIMEOUT; break; |
| 196 | P_FUTEX_OP(CMP_REQUEUE_PI); *arg_mask |= SCF_TIMEOUT; break; |
| 197 | P_FUTEX_OP(WAKE_OP); break; |
| 198 | P_FUTEX_OP(LOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 199 | P_FUTEX_OP(UNLOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 200 | P_FUTEX_OP(TRYLOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2; break; |
| 201 | P_FUTEX_OP(WAIT_BITSET); *arg_mask |= SCF_UADDR2; break; |
| 202 | P_FUTEX_OP(WAKE_BITSET); *arg_mask |= SCF_UADDR2; break; |
| 203 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; |
| 204 | default: printed = scnprintf(bf, size, "%#x", cmd); break; |
| 205 | } |
| 206 | |
| 207 | if (op & FUTEX_PRIVATE_FLAG) |
| 208 | printed += scnprintf(bf + printed, size - printed, "|PRIV"); |
| 209 | |
| 210 | if (op & FUTEX_CLOCK_REALTIME) |
| 211 | printed += scnprintf(bf + printed, size - printed, "|CLKRT"); |
| 212 | |
| 213 | return printed; |
| 214 | } |
| 215 | |
| 216 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op |
| 217 | |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 218 | static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 219 | unsigned long arg, |
| 220 | u8 arg_idx, u8 *arg_mask) |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 221 | { |
| 222 | int printed = 0, flags = arg; |
| 223 | |
| 224 | if (!(flags & O_CREAT)) |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 225 | *arg_mask |= 1 << (arg_idx + 1); /* Mask the mode parm */ |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 226 | |
| 227 | if (flags == 0) |
| 228 | return scnprintf(bf, size, "RDONLY"); |
| 229 | #define P_FLAG(n) \ |
| 230 | if (flags & O_##n) { \ |
| 231 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 232 | flags &= ~O_##n; \ |
| 233 | } |
| 234 | |
| 235 | P_FLAG(APPEND); |
| 236 | P_FLAG(ASYNC); |
| 237 | P_FLAG(CLOEXEC); |
| 238 | P_FLAG(CREAT); |
| 239 | P_FLAG(DIRECT); |
| 240 | P_FLAG(DIRECTORY); |
| 241 | P_FLAG(EXCL); |
| 242 | P_FLAG(LARGEFILE); |
| 243 | P_FLAG(NOATIME); |
| 244 | P_FLAG(NOCTTY); |
| 245 | #ifdef O_NONBLOCK |
| 246 | P_FLAG(NONBLOCK); |
| 247 | #elif O_NDELAY |
| 248 | P_FLAG(NDELAY); |
| 249 | #endif |
| 250 | #ifdef O_PATH |
| 251 | P_FLAG(PATH); |
| 252 | #endif |
| 253 | P_FLAG(RDWR); |
| 254 | #ifdef O_DSYNC |
| 255 | if ((flags & O_SYNC) == O_SYNC) |
| 256 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", "SYNC"); |
| 257 | else { |
| 258 | P_FLAG(DSYNC); |
| 259 | } |
| 260 | #else |
| 261 | P_FLAG(SYNC); |
| 262 | #endif |
| 263 | P_FLAG(TRUNC); |
| 264 | P_FLAG(WRONLY); |
| 265 | #undef P_FLAG |
| 266 | |
| 267 | if (flags) |
| 268 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 269 | |
| 270 | return printed; |
| 271 | } |
| 272 | |
| 273 | #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags |
| 274 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 275 | static struct syscall_fmt { |
| 276 | const char *name; |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 277 | const char *alias; |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 278 | size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg, u8 arg_idx, u8 *arg_mask); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 279 | bool errmsg; |
| 280 | bool timeout; |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 281 | bool hexret; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 282 | } syscall_fmts[] = { |
Arnaldo Carvalho de Melo | 8b74526 | 2012-10-18 19:06:13 -0300 | [diff] [blame] | 283 | { .name = "access", .errmsg = true, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 284 | { .name = "arch_prctl", .errmsg = true, .alias = "prctl", }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 285 | { .name = "brk", .hexret = true, |
| 286 | .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, }, |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 287 | { .name = "mmap", .hexret = true, }, |
Arnaldo Carvalho de Melo | a14bb86 | 2013-07-30 16:38:23 -0300 | [diff] [blame] | 288 | { .name = "connect", .errmsg = true, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 289 | { .name = "fstat", .errmsg = true, .alias = "newfstat", }, |
| 290 | { .name = "fstatat", .errmsg = true, .alias = "newfstatat", }, |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 291 | { .name = "futex", .errmsg = true, |
| 292 | .arg_scnprintf = { [1] = SCA_FUTEX_OP, /* op */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 293 | { .name = "ioctl", .errmsg = true, |
| 294 | .arg_scnprintf = { [2] = SCA_HEX, /* arg */ }, }, |
Arnaldo Carvalho de Melo | 579e786 | 2013-09-02 15:37:32 -0300 | [diff] [blame] | 295 | { .name = "lseek", .errmsg = true, |
| 296 | .arg_scnprintf = { [2] = SCA_WHENCE, /* whence */ }, }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 297 | { .name = "lstat", .errmsg = true, .alias = "newlstat", }, |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 298 | { .name = "madvise", .errmsg = true, |
| 299 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 300 | [2] = SCA_MADV_BHV, /* behavior */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 301 | { .name = "mmap", .hexret = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 302 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 303 | [2] = SCA_MMAP_PROT, /* prot */ |
| 304 | [3] = SCA_MMAP_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 305 | { .name = "mprotect", .errmsg = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 306 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 307 | [2] = SCA_MMAP_PROT, /* prot */ }, }, |
| 308 | { .name = "mremap", .hexret = true, |
| 309 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
| 310 | [4] = SCA_HEX, /* new_addr */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 311 | { .name = "munmap", .errmsg = true, |
| 312 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 313 | { .name = "open", .errmsg = true, |
| 314 | .arg_scnprintf = { [1] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 315 | { .name = "open_by_handle_at", .errmsg = true, |
| 316 | .arg_scnprintf = { [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
| 317 | { .name = "openat", .errmsg = true, |
| 318 | .arg_scnprintf = { [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 319 | { .name = "poll", .errmsg = true, .timeout = true, }, |
| 320 | { .name = "ppoll", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 321 | { .name = "pread", .errmsg = true, .alias = "pread64", }, |
| 322 | { .name = "pwrite", .errmsg = true, .alias = "pwrite64", }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 323 | { .name = "read", .errmsg = true, }, |
| 324 | { .name = "recvfrom", .errmsg = true, }, |
| 325 | { .name = "select", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | 8b74526 | 2012-10-18 19:06:13 -0300 | [diff] [blame] | 326 | { .name = "socket", .errmsg = true, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 327 | { .name = "stat", .errmsg = true, .alias = "newstat", }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 328 | { .name = "uname", .errmsg = true, .alias = "newuname", }, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | static int syscall_fmt__cmp(const void *name, const void *fmtp) |
| 332 | { |
| 333 | const struct syscall_fmt *fmt = fmtp; |
| 334 | return strcmp(name, fmt->name); |
| 335 | } |
| 336 | |
| 337 | static struct syscall_fmt *syscall_fmt__find(const char *name) |
| 338 | { |
| 339 | const int nmemb = ARRAY_SIZE(syscall_fmts); |
| 340 | return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); |
| 341 | } |
| 342 | |
| 343 | struct syscall { |
| 344 | struct event_format *tp_format; |
| 345 | const char *name; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 346 | bool filtered; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 347 | struct syscall_fmt *fmt; |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 348 | size_t (**arg_scnprintf)(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 349 | unsigned long arg, u8 arg_idx, u8 *args_mask); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 350 | }; |
| 351 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 352 | static size_t fprintf_duration(unsigned long t, FILE *fp) |
| 353 | { |
| 354 | double duration = (double)t / NSEC_PER_MSEC; |
| 355 | size_t printed = fprintf(fp, "("); |
| 356 | |
| 357 | if (duration >= 1.0) |
| 358 | printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); |
| 359 | else if (duration >= 0.01) |
| 360 | printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); |
| 361 | else |
| 362 | printed += color_fprintf(fp, PERF_COLOR_NORMAL, "%6.3f ms", duration); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 363 | return printed + fprintf(fp, "): "); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 364 | } |
| 365 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 366 | struct thread_trace { |
| 367 | u64 entry_time; |
| 368 | u64 exit_time; |
| 369 | bool entry_pending; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 370 | unsigned long nr_events; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 371 | char *entry_str; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 372 | double runtime_ms; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | static struct thread_trace *thread_trace__new(void) |
| 376 | { |
| 377 | return zalloc(sizeof(struct thread_trace)); |
| 378 | } |
| 379 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 380 | static struct thread_trace *thread__trace(struct thread *thread, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 381 | { |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 382 | struct thread_trace *ttrace; |
| 383 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 384 | if (thread == NULL) |
| 385 | goto fail; |
| 386 | |
| 387 | if (thread->priv == NULL) |
| 388 | thread->priv = thread_trace__new(); |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 389 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 390 | if (thread->priv == NULL) |
| 391 | goto fail; |
| 392 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 393 | ttrace = thread->priv; |
| 394 | ++ttrace->nr_events; |
| 395 | |
| 396 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 397 | fail: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 398 | color_fprintf(fp, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 399 | "WARNING: not enough memory, dropping samples!\n"); |
| 400 | return NULL; |
| 401 | } |
| 402 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 403 | struct trace { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 404 | struct perf_tool tool; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 405 | int audit_machine; |
| 406 | struct { |
| 407 | int max; |
| 408 | struct syscall *table; |
| 409 | } syscalls; |
| 410 | struct perf_record_opts opts; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 411 | struct machine host; |
| 412 | u64 base_time; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 413 | FILE *output; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 414 | unsigned long nr_events; |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 415 | struct strlist *ev_qualifier; |
| 416 | bool not_ev_qualifier; |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 417 | struct intlist *tid_list; |
| 418 | struct intlist *pid_list; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 419 | bool sched; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 420 | bool multiple_threads; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 421 | double duration_filter; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 422 | double runtime_ms; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 423 | }; |
| 424 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 425 | static bool trace__filter_duration(struct trace *trace, double t) |
| 426 | { |
| 427 | return t < (trace->duration_filter * NSEC_PER_MSEC); |
| 428 | } |
| 429 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 430 | static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
| 431 | { |
| 432 | double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; |
| 433 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 434 | return fprintf(fp, "%10.3f ", ts); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 435 | } |
| 436 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 437 | static bool done = false; |
| 438 | |
| 439 | static void sig_handler(int sig __maybe_unused) |
| 440 | { |
| 441 | done = true; |
| 442 | } |
| 443 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 444 | static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 445 | u64 duration, u64 tstamp, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 446 | { |
| 447 | size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 448 | printed += fprintf_duration(duration, fp); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 449 | |
| 450 | if (trace->multiple_threads) |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 451 | printed += fprintf(fp, "%d ", thread->tid); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 452 | |
| 453 | return printed; |
| 454 | } |
| 455 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 456 | static int trace__process_event(struct trace *trace, struct machine *machine, |
| 457 | union perf_event *event) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 458 | { |
| 459 | int ret = 0; |
| 460 | |
| 461 | switch (event->header.type) { |
| 462 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 463 | color_fprintf(trace->output, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 464 | "LOST %" PRIu64 " events!\n", event->lost.lost); |
| 465 | ret = machine__process_lost_event(machine, event); |
| 466 | default: |
| 467 | ret = machine__process_event(machine, event); |
| 468 | break; |
| 469 | } |
| 470 | |
| 471 | return ret; |
| 472 | } |
| 473 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 474 | static int trace__tool_process(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 475 | union perf_event *event, |
| 476 | struct perf_sample *sample __maybe_unused, |
| 477 | struct machine *machine) |
| 478 | { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 479 | struct trace *trace = container_of(tool, struct trace, tool); |
| 480 | return trace__process_event(trace, machine, event); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) |
| 484 | { |
| 485 | int err = symbol__init(); |
| 486 | |
| 487 | if (err) |
| 488 | return err; |
| 489 | |
| 490 | machine__init(&trace->host, "", HOST_KERNEL_ID); |
| 491 | machine__create_kernel_maps(&trace->host); |
| 492 | |
| 493 | if (perf_target__has_task(&trace->opts.target)) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 494 | err = perf_event__synthesize_thread_map(&trace->tool, evlist->threads, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 495 | trace__tool_process, |
| 496 | &trace->host); |
| 497 | } else { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 498 | err = perf_event__synthesize_threads(&trace->tool, trace__tool_process, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 499 | &trace->host); |
| 500 | } |
| 501 | |
| 502 | if (err) |
| 503 | symbol__exit(); |
| 504 | |
| 505 | return err; |
| 506 | } |
| 507 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 508 | static int syscall__set_arg_fmts(struct syscall *sc) |
| 509 | { |
| 510 | struct format_field *field; |
| 511 | int idx = 0; |
| 512 | |
| 513 | sc->arg_scnprintf = calloc(sc->tp_format->format.nr_fields - 1, sizeof(void *)); |
| 514 | if (sc->arg_scnprintf == NULL) |
| 515 | return -1; |
| 516 | |
| 517 | for (field = sc->tp_format->format.fields->next; field; field = field->next) { |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 518 | if (sc->fmt && sc->fmt->arg_scnprintf[idx]) |
| 519 | sc->arg_scnprintf[idx] = sc->fmt->arg_scnprintf[idx]; |
| 520 | else if (field->flags & FIELD_IS_POINTER) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 521 | sc->arg_scnprintf[idx] = syscall_arg__scnprintf_hex; |
| 522 | ++idx; |
| 523 | } |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 528 | static int trace__read_syscall_info(struct trace *trace, int id) |
| 529 | { |
| 530 | char tp_name[128]; |
| 531 | struct syscall *sc; |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 532 | const char *name = audit_syscall_to_name(id, trace->audit_machine); |
| 533 | |
| 534 | if (name == NULL) |
| 535 | return -1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 536 | |
| 537 | if (id > trace->syscalls.max) { |
| 538 | struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); |
| 539 | |
| 540 | if (nsyscalls == NULL) |
| 541 | return -1; |
| 542 | |
| 543 | if (trace->syscalls.max != -1) { |
| 544 | memset(nsyscalls + trace->syscalls.max + 1, 0, |
| 545 | (id - trace->syscalls.max) * sizeof(*sc)); |
| 546 | } else { |
| 547 | memset(nsyscalls, 0, (id + 1) * sizeof(*sc)); |
| 548 | } |
| 549 | |
| 550 | trace->syscalls.table = nsyscalls; |
| 551 | trace->syscalls.max = id; |
| 552 | } |
| 553 | |
| 554 | sc = trace->syscalls.table + id; |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 555 | sc->name = name; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 556 | |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 557 | if (trace->ev_qualifier) { |
| 558 | bool in = strlist__find(trace->ev_qualifier, name) != NULL; |
| 559 | |
| 560 | if (!(in ^ trace->not_ev_qualifier)) { |
| 561 | sc->filtered = true; |
| 562 | /* |
| 563 | * No need to do read tracepoint information since this will be |
| 564 | * filtered out. |
| 565 | */ |
| 566 | return 0; |
| 567 | } |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 568 | } |
| 569 | |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 570 | sc->fmt = syscall_fmt__find(sc->name); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 571 | |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 572 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); |
| 573 | sc->tp_format = event_format__new("syscalls", tp_name); |
| 574 | |
| 575 | if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) { |
| 576 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); |
| 577 | sc->tp_format = event_format__new("syscalls", tp_name); |
| 578 | } |
| 579 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 580 | if (sc->tp_format == NULL) |
| 581 | return -1; |
| 582 | |
| 583 | return syscall__set_arg_fmts(sc); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 584 | } |
| 585 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 586 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
| 587 | unsigned long *args) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 588 | { |
| 589 | int i = 0; |
| 590 | size_t printed = 0; |
| 591 | |
| 592 | if (sc->tp_format != NULL) { |
| 593 | struct format_field *field; |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 594 | u8 mask = 0, bit = 1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 595 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 596 | for (field = sc->tp_format->format.fields->next; field; |
| 597 | field = field->next, ++i, bit <<= 1) { |
| 598 | if (mask & bit) |
| 599 | continue; |
| 600 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 601 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 602 | "%s%s: ", printed ? ", " : "", field->name); |
| 603 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 604 | if (sc->arg_scnprintf && sc->arg_scnprintf[i]) { |
| 605 | printed += sc->arg_scnprintf[i](bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame^] | 606 | args[i], i, &mask); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 607 | } else { |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 608 | printed += scnprintf(bf + printed, size - printed, |
| 609 | "%ld", args[i]); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 610 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 611 | } |
| 612 | } else { |
| 613 | while (i < 6) { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 614 | printed += scnprintf(bf + printed, size - printed, |
| 615 | "%sarg%d: %ld", |
| 616 | printed ? ", " : "", i, args[i]); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 617 | ++i; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | return printed; |
| 622 | } |
| 623 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 624 | typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel, |
| 625 | struct perf_sample *sample); |
| 626 | |
| 627 | static struct syscall *trace__syscall_info(struct trace *trace, |
| 628 | struct perf_evsel *evsel, |
| 629 | struct perf_sample *sample) |
| 630 | { |
| 631 | int id = perf_evsel__intval(evsel, sample, "id"); |
| 632 | |
| 633 | if (id < 0) { |
Arnaldo Carvalho de Melo | adaa18b | 2013-08-22 17:55:25 -0300 | [diff] [blame] | 634 | |
| 635 | /* |
| 636 | * XXX: Noticed on x86_64, reproduced as far back as 3.0.36, haven't tried |
| 637 | * before that, leaving at a higher verbosity level till that is |
| 638 | * explained. Reproduced with plain ftrace with: |
| 639 | * |
| 640 | * echo 1 > /t/events/raw_syscalls/sys_exit/enable |
| 641 | * grep "NR -1 " /t/trace_pipe |
| 642 | * |
| 643 | * After generating some load on the machine. |
| 644 | */ |
| 645 | if (verbose > 1) { |
| 646 | static u64 n; |
| 647 | fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", |
| 648 | id, perf_evsel__name(evsel), ++n); |
| 649 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 650 | return NULL; |
| 651 | } |
| 652 | |
| 653 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && |
| 654 | trace__read_syscall_info(trace, id)) |
| 655 | goto out_cant_read; |
| 656 | |
| 657 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) |
| 658 | goto out_cant_read; |
| 659 | |
| 660 | return &trace->syscalls.table[id]; |
| 661 | |
| 662 | out_cant_read: |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 663 | if (verbose) { |
| 664 | fprintf(trace->output, "Problems reading syscall %d", id); |
| 665 | if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) |
| 666 | fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); |
| 667 | fputs(" information\n", trace->output); |
| 668 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 669 | return NULL; |
| 670 | } |
| 671 | |
| 672 | static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, |
| 673 | struct perf_sample *sample) |
| 674 | { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 675 | char *msg; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 676 | void *args; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 677 | size_t printed = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 678 | struct thread *thread; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 679 | struct syscall *sc = trace__syscall_info(trace, evsel, sample); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 680 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 681 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 682 | if (sc == NULL) |
| 683 | return -1; |
| 684 | |
| 685 | if (sc->filtered) |
| 686 | return 0; |
| 687 | |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 688 | thread = machine__findnew_thread(&trace->host, sample->pid, |
| 689 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 690 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 691 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 692 | return -1; |
| 693 | |
| 694 | args = perf_evsel__rawptr(evsel, sample, "args"); |
| 695 | if (args == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 696 | fprintf(trace->output, "Problems reading syscall arguments\n"); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 697 | return -1; |
| 698 | } |
| 699 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 700 | ttrace = thread->priv; |
| 701 | |
| 702 | if (ttrace->entry_str == NULL) { |
| 703 | ttrace->entry_str = malloc(1024); |
| 704 | if (!ttrace->entry_str) |
| 705 | return -1; |
| 706 | } |
| 707 | |
| 708 | ttrace->entry_time = sample->time; |
| 709 | msg = ttrace->entry_str; |
| 710 | printed += scnprintf(msg + printed, 1024 - printed, "%s(", sc->name); |
| 711 | |
| 712 | printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, args); |
| 713 | |
| 714 | if (!strcmp(sc->name, "exit_group") || !strcmp(sc->name, "exit")) { |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 715 | if (!trace->duration_filter) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 716 | trace__fprintf_entry_head(trace, thread, 1, sample->time, trace->output); |
| 717 | fprintf(trace->output, "%-70s\n", ttrace->entry_str); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 718 | } |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 719 | } else |
| 720 | ttrace->entry_pending = true; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, |
| 726 | struct perf_sample *sample) |
| 727 | { |
| 728 | int ret; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 729 | u64 duration = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 730 | struct thread *thread; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 731 | struct syscall *sc = trace__syscall_info(trace, evsel, sample); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 732 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 733 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 734 | if (sc == NULL) |
| 735 | return -1; |
| 736 | |
| 737 | if (sc->filtered) |
| 738 | return 0; |
| 739 | |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 740 | thread = machine__findnew_thread(&trace->host, sample->pid, |
| 741 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 742 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 743 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 744 | return -1; |
| 745 | |
| 746 | ret = perf_evsel__intval(evsel, sample, "ret"); |
| 747 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 748 | ttrace = thread->priv; |
| 749 | |
| 750 | ttrace->exit_time = sample->time; |
| 751 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 752 | if (ttrace->entry_time) { |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 753 | duration = sample->time - ttrace->entry_time; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 754 | if (trace__filter_duration(trace, duration)) |
| 755 | goto out; |
| 756 | } else if (trace->duration_filter) |
| 757 | goto out; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 758 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 759 | trace__fprintf_entry_head(trace, thread, duration, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 760 | |
| 761 | if (ttrace->entry_pending) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 762 | fprintf(trace->output, "%-70s", ttrace->entry_str); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 763 | } else { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 764 | fprintf(trace->output, " ... ["); |
| 765 | color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); |
| 766 | fprintf(trace->output, "]: %s()", sc->name); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 767 | } |
| 768 | |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 769 | if (sc->fmt == NULL) { |
| 770 | signed_print: |
| 771 | fprintf(trace->output, ") = %d", ret); |
| 772 | } else if (ret < 0 && sc->fmt->errmsg) { |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 773 | char bf[256]; |
| 774 | const char *emsg = strerror_r(-ret, bf, sizeof(bf)), |
| 775 | *e = audit_errno_to_name(-ret); |
| 776 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 777 | fprintf(trace->output, ") = -1 %s %s", e, emsg); |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 778 | } else if (ret == 0 && sc->fmt->timeout) |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 779 | fprintf(trace->output, ") = 0 Timeout"); |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 780 | else if (sc->fmt->hexret) |
| 781 | fprintf(trace->output, ") = %#x", ret); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 782 | else |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 783 | goto signed_print; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 784 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 785 | fputc('\n', trace->output); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 786 | out: |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 787 | ttrace->entry_pending = false; |
| 788 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 789 | return 0; |
| 790 | } |
| 791 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 792 | static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel, |
| 793 | struct perf_sample *sample) |
| 794 | { |
| 795 | u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); |
| 796 | double runtime_ms = (double)runtime / NSEC_PER_MSEC; |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 797 | struct thread *thread = machine__findnew_thread(&trace->host, |
| 798 | sample->pid, |
| 799 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 800 | struct thread_trace *ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 801 | |
| 802 | if (ttrace == NULL) |
| 803 | goto out_dump; |
| 804 | |
| 805 | ttrace->runtime_ms += runtime_ms; |
| 806 | trace->runtime_ms += runtime_ms; |
| 807 | return 0; |
| 808 | |
| 809 | out_dump: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 810 | fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 811 | evsel->name, |
| 812 | perf_evsel__strval(evsel, sample, "comm"), |
| 813 | (pid_t)perf_evsel__intval(evsel, sample, "pid"), |
| 814 | runtime, |
| 815 | perf_evsel__intval(evsel, sample, "vruntime")); |
| 816 | return 0; |
| 817 | } |
| 818 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 819 | static bool skip_sample(struct trace *trace, struct perf_sample *sample) |
| 820 | { |
| 821 | if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) || |
| 822 | (trace->tid_list && intlist__find(trace->tid_list, sample->tid))) |
| 823 | return false; |
| 824 | |
| 825 | if (trace->pid_list || trace->tid_list) |
| 826 | return true; |
| 827 | |
| 828 | return false; |
| 829 | } |
| 830 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 831 | static int trace__process_sample(struct perf_tool *tool, |
| 832 | union perf_event *event __maybe_unused, |
| 833 | struct perf_sample *sample, |
| 834 | struct perf_evsel *evsel, |
| 835 | struct machine *machine __maybe_unused) |
| 836 | { |
| 837 | struct trace *trace = container_of(tool, struct trace, tool); |
| 838 | int err = 0; |
| 839 | |
| 840 | tracepoint_handler handler = evsel->handler.func; |
| 841 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 842 | if (skip_sample(trace, sample)) |
| 843 | return 0; |
| 844 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 845 | if (trace->base_time == 0) |
| 846 | trace->base_time = sample->time; |
| 847 | |
| 848 | if (handler) |
| 849 | handler(trace, evsel, sample); |
| 850 | |
| 851 | return err; |
| 852 | } |
| 853 | |
| 854 | static bool |
| 855 | perf_session__has_tp(struct perf_session *session, const char *name) |
| 856 | { |
| 857 | struct perf_evsel *evsel; |
| 858 | |
| 859 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, name); |
| 860 | |
| 861 | return evsel != NULL; |
| 862 | } |
| 863 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 864 | static int parse_target_str(struct trace *trace) |
| 865 | { |
| 866 | if (trace->opts.target.pid) { |
| 867 | trace->pid_list = intlist__new(trace->opts.target.pid); |
| 868 | if (trace->pid_list == NULL) { |
| 869 | pr_err("Error parsing process id string\n"); |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | if (trace->opts.target.tid) { |
| 875 | trace->tid_list = intlist__new(trace->opts.target.tid); |
| 876 | if (trace->tid_list == NULL) { |
| 877 | pr_err("Error parsing thread id string\n"); |
| 878 | return -EINVAL; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 885 | static int trace__run(struct trace *trace, int argc, const char **argv) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 886 | { |
Namhyung Kim | 334fe7a | 2013-03-11 16:43:12 +0900 | [diff] [blame] | 887 | struct perf_evlist *evlist = perf_evlist__new(); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 888 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 889 | int err = -1, i; |
| 890 | unsigned long before; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 891 | const bool forks = argc > 0; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 892 | |
| 893 | if (evlist == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 894 | fprintf(trace->output, "Not enough memory to run!\n"); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 895 | goto out; |
| 896 | } |
| 897 | |
Arnaldo Carvalho de Melo | 39876e7 | 2012-10-03 11:40:22 -0300 | [diff] [blame] | 898 | if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) || |
| 899 | perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 900 | fprintf(trace->output, "Couldn't read the raw_syscalls tracepoints information!\n"); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 901 | goto out_delete_evlist; |
| 902 | } |
| 903 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 904 | if (trace->sched && |
| 905 | perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime", |
| 906 | trace__sched_stat_runtime)) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 907 | fprintf(trace->output, "Couldn't read the sched_stat_runtime tracepoint information!\n"); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 908 | goto out_delete_evlist; |
| 909 | } |
| 910 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 911 | err = perf_evlist__create_maps(evlist, &trace->opts.target); |
| 912 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 913 | fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 914 | goto out_delete_evlist; |
| 915 | } |
| 916 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 917 | err = trace__symbols_init(trace, evlist); |
| 918 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 919 | fprintf(trace->output, "Problems initializing symbol libraries!\n"); |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 920 | goto out_delete_maps; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 921 | } |
| 922 | |
Arnaldo Carvalho de Melo | f77a951 | 2012-12-10 16:41:31 -0300 | [diff] [blame] | 923 | perf_evlist__config(evlist, &trace->opts); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 924 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 925 | signal(SIGCHLD, sig_handler); |
| 926 | signal(SIGINT, sig_handler); |
| 927 | |
| 928 | if (forks) { |
Namhyung Kim | 6ef73ec | 2013-03-11 16:43:15 +0900 | [diff] [blame] | 929 | err = perf_evlist__prepare_workload(evlist, &trace->opts.target, |
Namhyung Kim | 55e162e | 2013-03-11 16:43:17 +0900 | [diff] [blame] | 930 | argv, false, false); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 931 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 932 | fprintf(trace->output, "Couldn't run the workload!\n"); |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 933 | goto out_delete_maps; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 937 | err = perf_evlist__open(evlist); |
| 938 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 939 | fprintf(trace->output, "Couldn't create the events: %s\n", strerror(errno)); |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 940 | goto out_delete_maps; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | err = perf_evlist__mmap(evlist, UINT_MAX, false); |
| 944 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 945 | fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno)); |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 946 | goto out_close_evlist; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | perf_evlist__enable(evlist); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 950 | |
| 951 | if (forks) |
| 952 | perf_evlist__start_workload(evlist); |
| 953 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 954 | trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 955 | again: |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 956 | before = trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 957 | |
| 958 | for (i = 0; i < evlist->nr_mmaps; i++) { |
| 959 | union perf_event *event; |
| 960 | |
| 961 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { |
| 962 | const u32 type = event->header.type; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 963 | tracepoint_handler handler; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 964 | struct perf_sample sample; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 965 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 966 | ++trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 967 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 968 | err = perf_evlist__parse_sample(evlist, event, &sample); |
| 969 | if (err) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 970 | fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 971 | continue; |
| 972 | } |
| 973 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 974 | if (trace->base_time == 0) |
| 975 | trace->base_time = sample.time; |
| 976 | |
| 977 | if (type != PERF_RECORD_SAMPLE) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 978 | trace__process_event(trace, &trace->host, event); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 979 | continue; |
| 980 | } |
| 981 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 982 | evsel = perf_evlist__id2evsel(evlist, sample.id); |
| 983 | if (evsel == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 984 | fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample.id); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 985 | continue; |
| 986 | } |
| 987 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 988 | if (sample.raw_data == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 989 | fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 990 | perf_evsel__name(evsel), sample.tid, |
| 991 | sample.cpu, sample.raw_size); |
| 992 | continue; |
| 993 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 994 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 995 | handler = evsel->handler.func; |
| 996 | handler(trace, evsel, &sample); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1000 | if (trace->nr_events == before) { |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1001 | if (done) |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 1002 | goto out_unmap_evlist; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1003 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1004 | poll(evlist->pollfd, evlist->nr_fds, -1); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (done) |
| 1008 | perf_evlist__disable(evlist); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1009 | |
| 1010 | goto again; |
| 1011 | |
Namhyung Kim | 3beb086 | 2013-03-15 14:48:50 +0900 | [diff] [blame] | 1012 | out_unmap_evlist: |
| 1013 | perf_evlist__munmap(evlist); |
| 1014 | out_close_evlist: |
| 1015 | perf_evlist__close(evlist); |
| 1016 | out_delete_maps: |
| 1017 | perf_evlist__delete_maps(evlist); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1018 | out_delete_evlist: |
| 1019 | perf_evlist__delete(evlist); |
| 1020 | out: |
| 1021 | return err; |
| 1022 | } |
| 1023 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1024 | static int trace__replay(struct trace *trace) |
| 1025 | { |
| 1026 | const struct perf_evsel_str_handler handlers[] = { |
| 1027 | { "raw_syscalls:sys_enter", trace__sys_enter, }, |
| 1028 | { "raw_syscalls:sys_exit", trace__sys_exit, }, |
| 1029 | }; |
| 1030 | |
| 1031 | struct perf_session *session; |
| 1032 | int err = -1; |
| 1033 | |
| 1034 | trace->tool.sample = trace__process_sample; |
| 1035 | trace->tool.mmap = perf_event__process_mmap; |
| 1036 | trace->tool.comm = perf_event__process_comm; |
| 1037 | trace->tool.exit = perf_event__process_exit; |
| 1038 | trace->tool.fork = perf_event__process_fork; |
| 1039 | trace->tool.attr = perf_event__process_attr; |
| 1040 | trace->tool.tracing_data = perf_event__process_tracing_data; |
| 1041 | trace->tool.build_id = perf_event__process_build_id; |
| 1042 | |
| 1043 | trace->tool.ordered_samples = true; |
| 1044 | trace->tool.ordering_requires_timestamps = true; |
| 1045 | |
| 1046 | /* add tid to output */ |
| 1047 | trace->multiple_threads = true; |
| 1048 | |
| 1049 | if (symbol__init() < 0) |
| 1050 | return -1; |
| 1051 | |
| 1052 | session = perf_session__new(input_name, O_RDONLY, 0, false, |
| 1053 | &trace->tool); |
| 1054 | if (session == NULL) |
| 1055 | return -ENOMEM; |
| 1056 | |
| 1057 | err = perf_session__set_tracepoints_handlers(session, handlers); |
| 1058 | if (err) |
| 1059 | goto out; |
| 1060 | |
| 1061 | if (!perf_session__has_tp(session, "raw_syscalls:sys_enter")) { |
| 1062 | pr_err("Data file does not have raw_syscalls:sys_enter events\n"); |
| 1063 | goto out; |
| 1064 | } |
| 1065 | |
| 1066 | if (!perf_session__has_tp(session, "raw_syscalls:sys_exit")) { |
| 1067 | pr_err("Data file does not have raw_syscalls:sys_exit events\n"); |
| 1068 | goto out; |
| 1069 | } |
| 1070 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 1071 | err = parse_target_str(trace); |
| 1072 | if (err != 0) |
| 1073 | goto out; |
| 1074 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1075 | setup_pager(); |
| 1076 | |
| 1077 | err = perf_session__process_events(session, &trace->tool); |
| 1078 | if (err) |
| 1079 | pr_err("Failed to process events, error %d", err); |
| 1080 | |
| 1081 | out: |
| 1082 | perf_session__delete(session); |
| 1083 | |
| 1084 | return err; |
| 1085 | } |
| 1086 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1087 | static size_t trace__fprintf_threads_header(FILE *fp) |
| 1088 | { |
| 1089 | size_t printed; |
| 1090 | |
| 1091 | printed = fprintf(fp, "\n _____________________________________________________________________\n"); |
| 1092 | printed += fprintf(fp," __) Summary of events (__\n\n"); |
| 1093 | printed += fprintf(fp," [ task - pid ] [ events ] [ ratio ] [ runtime ]\n"); |
| 1094 | printed += fprintf(fp," _____________________________________________________________________\n\n"); |
| 1095 | |
| 1096 | return printed; |
| 1097 | } |
| 1098 | |
| 1099 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) |
| 1100 | { |
| 1101 | size_t printed = trace__fprintf_threads_header(fp); |
| 1102 | struct rb_node *nd; |
| 1103 | |
| 1104 | for (nd = rb_first(&trace->host.threads); nd; nd = rb_next(nd)) { |
| 1105 | struct thread *thread = rb_entry(nd, struct thread, rb_node); |
| 1106 | struct thread_trace *ttrace = thread->priv; |
| 1107 | const char *color; |
| 1108 | double ratio; |
| 1109 | |
| 1110 | if (ttrace == NULL) |
| 1111 | continue; |
| 1112 | |
| 1113 | ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; |
| 1114 | |
| 1115 | color = PERF_COLOR_NORMAL; |
| 1116 | if (ratio > 50.0) |
| 1117 | color = PERF_COLOR_RED; |
| 1118 | else if (ratio > 25.0) |
| 1119 | color = PERF_COLOR_GREEN; |
| 1120 | else if (ratio > 5.0) |
| 1121 | color = PERF_COLOR_YELLOW; |
| 1122 | |
| 1123 | printed += color_fprintf(fp, color, "%20s", thread->comm); |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1124 | printed += fprintf(fp, " - %-5d :%11lu [", thread->tid, ttrace->nr_events); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1125 | printed += color_fprintf(fp, color, "%5.1f%%", ratio); |
| 1126 | printed += fprintf(fp, " ] %10.3f ms\n", ttrace->runtime_ms); |
| 1127 | } |
| 1128 | |
| 1129 | return printed; |
| 1130 | } |
| 1131 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1132 | static int trace__set_duration(const struct option *opt, const char *str, |
| 1133 | int unset __maybe_unused) |
| 1134 | { |
| 1135 | struct trace *trace = opt->value; |
| 1136 | |
| 1137 | trace->duration_filter = atof(str); |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1141 | static int trace__open_output(struct trace *trace, const char *filename) |
| 1142 | { |
| 1143 | struct stat st; |
| 1144 | |
| 1145 | if (!stat(filename, &st) && st.st_size) { |
| 1146 | char oldname[PATH_MAX]; |
| 1147 | |
| 1148 | scnprintf(oldname, sizeof(oldname), "%s.old", filename); |
| 1149 | unlink(oldname); |
| 1150 | rename(filename, oldname); |
| 1151 | } |
| 1152 | |
| 1153 | trace->output = fopen(filename, "w"); |
| 1154 | |
| 1155 | return trace->output == NULL ? -errno : 0; |
| 1156 | } |
| 1157 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1158 | int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) |
| 1159 | { |
| 1160 | const char * const trace_usage[] = { |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1161 | "perf trace [<options>] [<command>]", |
| 1162 | "perf trace [<options>] -- <command> [<options>]", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1163 | NULL |
| 1164 | }; |
| 1165 | struct trace trace = { |
| 1166 | .audit_machine = audit_detect_machine(), |
| 1167 | .syscalls = { |
| 1168 | . max = -1, |
| 1169 | }, |
| 1170 | .opts = { |
| 1171 | .target = { |
| 1172 | .uid = UINT_MAX, |
| 1173 | .uses_mmap = true, |
| 1174 | }, |
| 1175 | .user_freq = UINT_MAX, |
| 1176 | .user_interval = ULLONG_MAX, |
| 1177 | .no_delay = true, |
| 1178 | .mmap_pages = 1024, |
| 1179 | }, |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1180 | .output = stdout, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1181 | }; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1182 | const char *output_name = NULL; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1183 | const char *ev_qualifier_str = NULL; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1184 | const struct option trace_options[] = { |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1185 | OPT_STRING('e', "expr", &ev_qualifier_str, "expr", |
| 1186 | "list of events to trace"), |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1187 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1188 | OPT_STRING('i', "input", &input_name, "file", "Analyze events in file"), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1189 | OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", |
| 1190 | "trace events on existing process id"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 1191 | OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1192 | "trace events on existing thread id"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 1193 | OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1194 | "system-wide collection from all CPUs"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 1195 | OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1196 | "list of cpus to monitor"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1197 | OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1198 | "child tasks do not inherit counters"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 1199 | OPT_UINTEGER('m', "mmap-pages", &trace.opts.mmap_pages, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1200 | "number of mmap data pages"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 1201 | OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1202 | "user to profile"), |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1203 | OPT_CALLBACK(0, "duration", &trace, "float", |
| 1204 | "show only events with duration > N.M ms", |
| 1205 | trace__set_duration), |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1206 | OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 1207 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1208 | OPT_END() |
| 1209 | }; |
| 1210 | int err; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 1211 | char bf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1212 | |
| 1213 | argc = parse_options(argc, argv, trace_options, trace_usage, 0); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1214 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1215 | if (output_name != NULL) { |
| 1216 | err = trace__open_output(&trace, output_name); |
| 1217 | if (err < 0) { |
| 1218 | perror("failed to create output file"); |
| 1219 | goto out; |
| 1220 | } |
| 1221 | } |
| 1222 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1223 | if (ev_qualifier_str != NULL) { |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 1224 | const char *s = ev_qualifier_str; |
| 1225 | |
| 1226 | trace.not_ev_qualifier = *s == '!'; |
| 1227 | if (trace.not_ev_qualifier) |
| 1228 | ++s; |
| 1229 | trace.ev_qualifier = strlist__new(true, s); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1230 | if (trace.ev_qualifier == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1231 | fputs("Not enough memory to parse event qualifier", |
| 1232 | trace.output); |
| 1233 | err = -ENOMEM; |
| 1234 | goto out_close; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 1238 | err = perf_target__validate(&trace.opts.target); |
| 1239 | if (err) { |
| 1240 | perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1241 | fprintf(trace.output, "%s", bf); |
| 1242 | goto out_close; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 1243 | } |
| 1244 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1245 | err = perf_target__parse_uid(&trace.opts.target); |
| 1246 | if (err) { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1247 | perf_target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1248 | fprintf(trace.output, "%s", bf); |
| 1249 | goto out_close; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1250 | } |
| 1251 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1252 | if (!argc && perf_target__none(&trace.opts.target)) |
Namhyung Kim | ee76120 | 2012-10-05 14:02:14 +0900 | [diff] [blame] | 1253 | trace.opts.target.system_wide = true; |
| 1254 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1255 | if (input_name) |
| 1256 | err = trace__replay(&trace); |
| 1257 | else |
| 1258 | err = trace__run(&trace, argc, argv); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1259 | |
| 1260 | if (trace.sched && !err) |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1261 | trace__fprintf_thread_summary(&trace, trace.output); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1262 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1263 | out_close: |
| 1264 | if (output_name != NULL) |
| 1265 | fclose(trace.output); |
| 1266 | out: |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1267 | return err; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1268 | } |