diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-09-03 11:20:12 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-09 10:08:15 -0400 |
commit | 01533e9720c8527faf0bc6e476c4c911a488e268 (patch) | |
tree | ebbd5690fe402c66a7a2987bf95671acc849b659 /tools/perf/builtin-trace.c | |
parent | 165108a92fc554d51e73b143b69b77e7c278da78 (diff) |
perf trace: Put syscall formatter parms into struct
So that we can add more state to formatters without having to modify
all of them.
Example is to pass a table to a generic string formatter, like for
setitimer 'which' arg.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-zyi2esmas5wfrxznh0x0fkiz@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-trace.c')
-rw-r--r-- | tools/perf/builtin-trace.c | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 71aa3e35406b..939426c7dbde 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -33,22 +33,24 @@ | |||
33 | # define MADV_UNMERGEABLE 13 | 33 | # define MADV_UNMERGEABLE 13 |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | struct syscall_arg { | ||
37 | unsigned long val; | ||
38 | u8 idx; | ||
39 | u8 mask; | ||
40 | }; | ||
41 | |||
36 | static size_t syscall_arg__scnprintf_hex(char *bf, size_t size, | 42 | static size_t syscall_arg__scnprintf_hex(char *bf, size_t size, |
37 | unsigned long arg, | 43 | struct syscall_arg *arg) |
38 | u8 arg_idx __maybe_unused, | ||
39 | u8 *arg_mask __maybe_unused) | ||
40 | { | 44 | { |
41 | return scnprintf(bf, size, "%#lx", arg); | 45 | return scnprintf(bf, size, "%#lx", arg->val); |
42 | } | 46 | } |
43 | 47 | ||
44 | #define SCA_HEX syscall_arg__scnprintf_hex | 48 | #define SCA_HEX syscall_arg__scnprintf_hex |
45 | 49 | ||
46 | static size_t syscall_arg__scnprintf_whence(char *bf, size_t size, | 50 | static size_t syscall_arg__scnprintf_whence(char *bf, size_t size, |
47 | unsigned long arg, | 51 | struct syscall_arg *arg) |
48 | u8 arg_idx __maybe_unused, | ||
49 | u8 *arg_mask __maybe_unused) | ||
50 | { | 52 | { |
51 | int whence = arg; | 53 | int whence = arg->val; |
52 | 54 | ||
53 | switch (whence) { | 55 | switch (whence) { |
54 | #define P_WHENCE(n) case SEEK_##n: return scnprintf(bf, size, #n) | 56 | #define P_WHENCE(n) case SEEK_##n: return scnprintf(bf, size, #n) |
@@ -71,11 +73,9 @@ static size_t syscall_arg__scnprintf_whence(char *bf, size_t size, | |||
71 | #define SCA_WHENCE syscall_arg__scnprintf_whence | 73 | #define SCA_WHENCE syscall_arg__scnprintf_whence |
72 | 74 | ||
73 | static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, | 75 | static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, |
74 | unsigned long arg, | 76 | struct syscall_arg *arg) |
75 | u8 arg_idx __maybe_unused, | ||
76 | u8 *arg_mask __maybe_unused) | ||
77 | { | 77 | { |
78 | int printed = 0, prot = arg; | 78 | int printed = 0, prot = arg->val; |
79 | 79 | ||
80 | if (prot == PROT_NONE) | 80 | if (prot == PROT_NONE) |
81 | return scnprintf(bf, size, "NONE"); | 81 | return scnprintf(bf, size, "NONE"); |
@@ -104,10 +104,9 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, | |||
104 | #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot | 104 | #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot |
105 | 105 | ||
106 | static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, | 106 | static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, |
107 | unsigned long arg, u8 arg_idx __maybe_unused, | 107 | struct syscall_arg *arg) |
108 | u8 *arg_mask __maybe_unused) | ||
109 | { | 108 | { |
110 | int printed = 0, flags = arg; | 109 | int printed = 0, flags = arg->val; |
111 | 110 | ||
112 | #define P_MMAP_FLAG(n) \ | 111 | #define P_MMAP_FLAG(n) \ |
113 | if (flags & MAP_##n) { \ | 112 | if (flags & MAP_##n) { \ |
@@ -148,10 +147,9 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, | |||
148 | #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags | 147 | #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags |
149 | 148 | ||
150 | static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, | 149 | static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, |
151 | unsigned long arg, u8 arg_idx __maybe_unused, | 150 | struct syscall_arg *arg) |
152 | u8 *arg_mask __maybe_unused) | ||
153 | { | 151 | { |
154 | int behavior = arg; | 152 | int behavior = arg->val; |
155 | 153 | ||
156 | switch (behavior) { | 154 | switch (behavior) { |
157 | #define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n) | 155 | #define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n) |
@@ -190,8 +188,7 @@ static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, | |||
190 | 188 | ||
191 | #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior | 189 | #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior |
192 | 190 | ||
193 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned long arg, | 191 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg) |
194 | u8 arg_idx __maybe_unused, u8 *arg_mask) | ||
195 | { | 192 | { |
196 | enum syscall_futex_args { | 193 | enum syscall_futex_args { |
197 | SCF_UADDR = (1 << 0), | 194 | SCF_UADDR = (1 << 0), |
@@ -201,24 +198,24 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned lo | |||
201 | SCF_UADDR2 = (1 << 4), | 198 | SCF_UADDR2 = (1 << 4), |
202 | SCF_VAL3 = (1 << 5), | 199 | SCF_VAL3 = (1 << 5), |
203 | }; | 200 | }; |
204 | int op = arg; | 201 | int op = arg->val; |
205 | int cmd = op & FUTEX_CMD_MASK; | 202 | int cmd = op & FUTEX_CMD_MASK; |
206 | size_t printed = 0; | 203 | size_t printed = 0; |
207 | 204 | ||
208 | switch (cmd) { | 205 | switch (cmd) { |
209 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); | 206 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); |
210 | P_FUTEX_OP(WAIT); *arg_mask |= SCF_VAL3|SCF_UADDR2; break; | 207 | P_FUTEX_OP(WAIT); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
211 | P_FUTEX_OP(WAKE); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; | 208 | P_FUTEX_OP(WAKE); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
212 | P_FUTEX_OP(FD); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; | 209 | P_FUTEX_OP(FD); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
213 | P_FUTEX_OP(REQUEUE); *arg_mask |= SCF_VAL3|SCF_TIMEOUT; break; | 210 | P_FUTEX_OP(REQUEUE); arg->mask |= SCF_VAL3|SCF_TIMEOUT; break; |
214 | P_FUTEX_OP(CMP_REQUEUE); *arg_mask |= SCF_TIMEOUT; break; | 211 | P_FUTEX_OP(CMP_REQUEUE); arg->mask |= SCF_TIMEOUT; break; |
215 | P_FUTEX_OP(CMP_REQUEUE_PI); *arg_mask |= SCF_TIMEOUT; break; | 212 | P_FUTEX_OP(CMP_REQUEUE_PI); arg->mask |= SCF_TIMEOUT; break; |
216 | P_FUTEX_OP(WAKE_OP); break; | 213 | P_FUTEX_OP(WAKE_OP); break; |
217 | P_FUTEX_OP(LOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; | 214 | P_FUTEX_OP(LOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
218 | P_FUTEX_OP(UNLOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; | 215 | P_FUTEX_OP(UNLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
219 | P_FUTEX_OP(TRYLOCK_PI); *arg_mask |= SCF_VAL3|SCF_UADDR2; break; | 216 | P_FUTEX_OP(TRYLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
220 | P_FUTEX_OP(WAIT_BITSET); *arg_mask |= SCF_UADDR2; break; | 217 | P_FUTEX_OP(WAIT_BITSET); arg->mask |= SCF_UADDR2; break; |
221 | P_FUTEX_OP(WAKE_BITSET); *arg_mask |= SCF_UADDR2; break; | 218 | P_FUTEX_OP(WAKE_BITSET); arg->mask |= SCF_UADDR2; break; |
222 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; | 219 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; |
223 | default: printed = scnprintf(bf, size, "%#x", cmd); break; | 220 | default: printed = scnprintf(bf, size, "%#x", cmd); break; |
224 | } | 221 | } |
@@ -235,13 +232,12 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned lo | |||
235 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op | 232 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op |
236 | 233 | ||
237 | static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, | 234 | static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, |
238 | unsigned long arg, | 235 | struct syscall_arg *arg) |
239 | u8 arg_idx, u8 *arg_mask) | ||
240 | { | 236 | { |
241 | int printed = 0, flags = arg; | 237 | int printed = 0, flags = arg->val; |
242 | 238 | ||
243 | if (!(flags & O_CREAT)) | 239 | if (!(flags & O_CREAT)) |
244 | *arg_mask |= 1 << (arg_idx + 1); /* Mask the mode parm */ | 240 | arg->mask |= 1 << (arg->idx + 1); /* Mask the mode parm */ |
245 | 241 | ||
246 | if (flags == 0) | 242 | if (flags == 0) |
247 | return scnprintf(bf, size, "RDONLY"); | 243 | return scnprintf(bf, size, "RDONLY"); |
@@ -294,7 +290,7 @@ static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, | |||
294 | static struct syscall_fmt { | 290 | static struct syscall_fmt { |
295 | const char *name; | 291 | const char *name; |
296 | const char *alias; | 292 | const char *alias; |
297 | size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg, u8 arg_idx, u8 *arg_mask); | 293 | size_t (*arg_scnprintf[6])(char *bf, size_t size, struct syscall_arg *arg); |
298 | bool errmsg; | 294 | bool errmsg; |
299 | bool timeout; | 295 | bool timeout; |
300 | bool hexret; | 296 | bool hexret; |
@@ -364,8 +360,7 @@ struct syscall { | |||
364 | const char *name; | 360 | const char *name; |
365 | bool filtered; | 361 | bool filtered; |
366 | struct syscall_fmt *fmt; | 362 | struct syscall_fmt *fmt; |
367 | size_t (**arg_scnprintf)(char *bf, size_t size, | 363 | size_t (**arg_scnprintf)(char *bf, size_t size, struct syscall_arg *arg); |
368 | unsigned long arg, u8 arg_idx, u8 *args_mask); | ||
369 | }; | 364 | }; |
370 | 365 | ||
371 | static size_t fprintf_duration(unsigned long t, FILE *fp) | 366 | static size_t fprintf_duration(unsigned long t, FILE *fp) |
@@ -605,30 +600,35 @@ static int trace__read_syscall_info(struct trace *trace, int id) | |||
605 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, | 600 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
606 | unsigned long *args) | 601 | unsigned long *args) |
607 | { | 602 | { |
608 | int i = 0; | ||
609 | size_t printed = 0; | 603 | size_t printed = 0; |
610 | 604 | ||
611 | if (sc->tp_format != NULL) { | 605 | if (sc->tp_format != NULL) { |
612 | struct format_field *field; | 606 | struct format_field *field; |
613 | u8 mask = 0, bit = 1; | 607 | u8 bit = 1; |
608 | struct syscall_arg arg = { | ||
609 | .idx = 0, | ||
610 | .mask = 0, | ||
611 | }; | ||
614 | 612 | ||
615 | for (field = sc->tp_format->format.fields->next; field; | 613 | for (field = sc->tp_format->format.fields->next; field; |
616 | field = field->next, ++i, bit <<= 1) { | 614 | field = field->next, ++arg.idx, bit <<= 1) { |
617 | if (mask & bit) | 615 | if (arg.mask & bit) |
618 | continue; | 616 | continue; |
619 | 617 | ||
620 | printed += scnprintf(bf + printed, size - printed, | 618 | printed += scnprintf(bf + printed, size - printed, |
621 | "%s%s: ", printed ? ", " : "", field->name); | 619 | "%s%s: ", printed ? ", " : "", field->name); |
622 | 620 | if (sc->arg_scnprintf && sc->arg_scnprintf[arg.idx]) { | |
623 | if (sc->arg_scnprintf && sc->arg_scnprintf[i]) { | 621 | arg.val = args[arg.idx]; |
624 | printed += sc->arg_scnprintf[i](bf + printed, size - printed, | 622 | printed += sc->arg_scnprintf[arg.idx](bf + printed, |
625 | args[i], i, &mask); | 623 | size - printed, &arg); |
626 | } else { | 624 | } else { |
627 | printed += scnprintf(bf + printed, size - printed, | 625 | printed += scnprintf(bf + printed, size - printed, |
628 | "%ld", args[i]); | 626 | "%ld", args[arg.idx]); |
629 | } | 627 | } |
630 | } | 628 | } |
631 | } else { | 629 | } else { |
630 | int i = 0; | ||
631 | |||
632 | while (i < 6) { | 632 | while (i < 6) { |
633 | printed += scnprintf(bf + printed, size - printed, | 633 | printed += scnprintf(bf + printed, size - printed, |
634 | "%sarg%d: %ld", | 634 | "%sarg%d: %ld", |