diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2009-11-16 23:31:06 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2009-11-16 23:51:09 -0500 |
| commit | 32ba4ff2b06810f2fa32f4e9fdc347229b7845f3 (patch) | |
| tree | cf4d624ad2da806d486dd37d615eb4a106d751bb | |
| parent | ecdf2bf0eb103a466231e811e7d675ae71315748 (diff) | |
Convert parse-envents.c to use trace_seq for output
To allow other users to take adavantage of the parse-events code,
convert it to trace_seq.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | parse-events.c | 220 | ||||
| -rw-r--r-- | parse-events.h | 5 | ||||
| -rw-r--r-- | trace-read.c | 5 |
3 files changed, 126 insertions, 104 deletions
diff --git a/parse-events.c b/parse-events.c index a9a06b9..2bb2ad9 100644 --- a/parse-events.c +++ b/parse-events.c | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include <errno.h> | 29 | #include <errno.h> |
| 30 | 30 | ||
| 31 | #include "parse-events.h" | 31 | #include "parse-events.h" |
| 32 | #include "trace-seq.h" | ||
| 32 | 33 | ||
| 33 | int header_page_ts_offset; | 34 | int header_page_ts_offset; |
| 34 | int header_page_ts_size; | 35 | int header_page_ts_size; |
| @@ -2161,7 +2162,7 @@ static unsigned long long eval_flag(const char *flag) | |||
| 2161 | return 0; | 2162 | return 0; |
| 2162 | } | 2163 | } |
| 2163 | 2164 | ||
| 2164 | static void print_str_arg(void *data, int size, | 2165 | static void print_str_arg(struct trace_seq *s, void *data, int size, |
| 2165 | struct event *event, struct print_arg *arg) | 2166 | struct event *event, struct print_arg *arg) |
| 2166 | { | 2167 | { |
| 2167 | struct print_flag_sym *flag; | 2168 | struct print_flag_sym *flag; |
| @@ -2174,7 +2175,7 @@ static void print_str_arg(void *data, int size, | |||
| 2174 | /* ?? */ | 2175 | /* ?? */ |
| 2175 | return; | 2176 | return; |
| 2176 | case PRINT_ATOM: | 2177 | case PRINT_ATOM: |
| 2177 | printf("%s", arg->atom.atom); | 2178 | trace_seq_puts(s, arg->atom.atom); |
| 2178 | return; | 2179 | return; |
| 2179 | case PRINT_FIELD: | 2180 | case PRINT_FIELD: |
| 2180 | if (!arg->field.field) { | 2181 | if (!arg->field.field) { |
| @@ -2186,7 +2187,7 @@ static void print_str_arg(void *data, int size, | |||
| 2186 | memcpy(str, data + arg->field.field->offset, | 2187 | memcpy(str, data + arg->field.field->offset, |
| 2187 | arg->field.field->size); | 2188 | arg->field.field->size); |
| 2188 | str[arg->field.field->size] = 0; | 2189 | str[arg->field.field->size] = 0; |
| 2189 | printf("%s", str); | 2190 | trace_seq_puts(s, str); |
| 2190 | free(str); | 2191 | free(str); |
| 2191 | break; | 2192 | break; |
| 2192 | case PRINT_FLAGS: | 2193 | case PRINT_FLAGS: |
| @@ -2195,13 +2196,13 @@ static void print_str_arg(void *data, int size, | |||
| 2195 | for (flag = arg->flags.flags; flag; flag = flag->next) { | 2196 | for (flag = arg->flags.flags; flag; flag = flag->next) { |
| 2196 | fval = eval_flag(flag->value); | 2197 | fval = eval_flag(flag->value); |
| 2197 | if (!val && !fval) { | 2198 | if (!val && !fval) { |
| 2198 | printf("%s", flag->str); | 2199 | trace_seq_puts(s, flag->str); |
| 2199 | break; | 2200 | break; |
| 2200 | } | 2201 | } |
| 2201 | if (fval && (val & fval) == fval) { | 2202 | if (fval && (val & fval) == fval) { |
| 2202 | if (print && arg->flags.delim) | 2203 | if (print && arg->flags.delim) |
| 2203 | printf("%s", arg->flags.delim); | 2204 | trace_seq_puts(s, arg->flags.delim); |
| 2204 | printf("%s", flag->str); | 2205 | trace_seq_puts(s, flag->str); |
| 2205 | print = 1; | 2206 | print = 1; |
| 2206 | val &= ~fval; | 2207 | val &= ~fval; |
| 2207 | } | 2208 | } |
| @@ -2212,7 +2213,7 @@ static void print_str_arg(void *data, int size, | |||
| 2212 | for (flag = arg->symbol.symbols; flag; flag = flag->next) { | 2213 | for (flag = arg->symbol.symbols; flag; flag = flag->next) { |
| 2213 | fval = eval_flag(flag->value); | 2214 | fval = eval_flag(flag->value); |
| 2214 | if (val == fval) { | 2215 | if (val == fval) { |
| 2215 | printf("%s", flag->str); | 2216 | trace_seq_puts(s, flag->str); |
| 2216 | break; | 2217 | break; |
| 2217 | } | 2218 | } |
| 2218 | } | 2219 | } |
| @@ -2231,7 +2232,7 @@ static void print_str_arg(void *data, int size, | |||
| 2231 | } | 2232 | } |
| 2232 | str_offset = *(int *)(data + arg->string.offset); | 2233 | str_offset = *(int *)(data + arg->string.offset); |
| 2233 | str_offset &= 0xffff; | 2234 | str_offset &= 0xffff; |
| 2234 | printf("%s", ((char *)data) + str_offset); | 2235 | trace_seq_puts(s, ((char *)data) + str_offset); |
| 2235 | break; | 2236 | break; |
| 2236 | } | 2237 | } |
| 2237 | case PRINT_OP: | 2238 | case PRINT_OP: |
| @@ -2242,9 +2243,9 @@ static void print_str_arg(void *data, int size, | |||
| 2242 | return; | 2243 | return; |
| 2243 | val = eval_num_arg(data, size, event, arg->op.left); | 2244 | val = eval_num_arg(data, size, event, arg->op.left); |
| 2244 | if (val) | 2245 | if (val) |
| 2245 | print_str_arg(data, size, event, arg->op.right->op.left); | 2246 | print_str_arg(s, data, size, event, arg->op.right->op.left); |
| 2246 | else | 2247 | else |
| 2247 | print_str_arg(data, size, event, arg->op.right->op.right); | 2248 | print_str_arg(s, data, size, event, arg->op.right->op.right); |
| 2248 | break; | 2249 | break; |
| 2249 | default: | 2250 | default: |
| 2250 | /* well... */ | 2251 | /* well... */ |
| @@ -2365,7 +2366,8 @@ static void free_args(struct print_arg *args) | |||
| 2365 | } | 2366 | } |
| 2366 | } | 2367 | } |
| 2367 | 2368 | ||
| 2368 | static char *get_bprint_format(void *data, int size __unused, struct event *event) | 2369 | static char * |
| 2370 | get_bprint_format(void *data, int size __unused, struct event *event) | ||
| 2369 | { | 2371 | { |
| 2370 | unsigned long long addr; | 2372 | unsigned long long addr; |
| 2371 | static struct format_field *field; | 2373 | static struct format_field *field; |
| @@ -2408,7 +2410,7 @@ static char *get_bprint_format(void *data, int size __unused, struct event *even | |||
| 2408 | return format; | 2410 | return format; |
| 2409 | } | 2411 | } |
| 2410 | 2412 | ||
| 2411 | static void pretty_print(void *data, int size, struct event *event) | 2413 | static void pretty_print(struct trace_seq *s, void *data, int size, struct event *event) |
| 2412 | { | 2414 | { |
| 2413 | struct print_fmt *print_fmt = &event->print_fmt; | 2415 | struct print_fmt *print_fmt = &event->print_fmt; |
| 2414 | struct print_arg *arg = print_fmt->args; | 2416 | struct print_arg *arg = print_fmt->args; |
| @@ -2439,19 +2441,19 @@ static void pretty_print(void *data, int size, struct event *event) | |||
| 2439 | ptr++; | 2441 | ptr++; |
| 2440 | switch (*ptr) { | 2442 | switch (*ptr) { |
| 2441 | case 'n': | 2443 | case 'n': |
| 2442 | printf("\n"); | 2444 | trace_seq_putc(s, '\n'); |
| 2443 | break; | 2445 | break; |
| 2444 | case 't': | 2446 | case 't': |
| 2445 | printf("\t"); | 2447 | trace_seq_putc(s, '\t'); |
| 2446 | break; | 2448 | break; |
| 2447 | case 'r': | 2449 | case 'r': |
| 2448 | printf("\r"); | 2450 | trace_seq_putc(s, '\r'); |
| 2449 | break; | 2451 | break; |
| 2450 | case '\\': | 2452 | case '\\': |
| 2451 | printf("\\"); | 2453 | trace_seq_putc(s, '\\'); |
| 2452 | break; | 2454 | break; |
| 2453 | default: | 2455 | default: |
| 2454 | printf("%c", *ptr); | 2456 | trace_seq_putc(s, *ptr); |
| 2455 | break; | 2457 | break; |
| 2456 | } | 2458 | } |
| 2457 | 2459 | ||
| @@ -2462,7 +2464,7 @@ static void pretty_print(void *data, int size, struct event *event) | |||
| 2462 | ptr++; | 2464 | ptr++; |
| 2463 | switch (*ptr) { | 2465 | switch (*ptr) { |
| 2464 | case '%': | 2466 | case '%': |
| 2465 | printf("%%"); | 2467 | trace_seq_putc(s, '%'); |
| 2466 | break; | 2468 | break; |
| 2467 | case 'l': | 2469 | case 'l': |
| 2468 | ls++; | 2470 | ls++; |
| @@ -2511,22 +2513,23 @@ static void pretty_print(void *data, int size, struct event *event) | |||
| 2511 | if (show_func) { | 2513 | if (show_func) { |
| 2512 | func = find_func(val); | 2514 | func = find_func(val); |
| 2513 | if (func) { | 2515 | if (func) { |
| 2514 | printf("%s", func->func); | 2516 | trace_seq_puts(s, func->func); |
| 2515 | if (show_func == 'F') | 2517 | if (show_func == 'F') |
| 2516 | printf("+0x%llx", | 2518 | trace_seq_printf(s, |
| 2519 | "+0x%llx", | ||
| 2517 | val - func->addr); | 2520 | val - func->addr); |
| 2518 | break; | 2521 | break; |
| 2519 | } | 2522 | } |
| 2520 | } | 2523 | } |
| 2521 | switch (ls) { | 2524 | switch (ls) { |
| 2522 | case 0: | 2525 | case 0: |
| 2523 | printf(format, (int)val); | 2526 | trace_seq_printf(s, format, (int)val); |
| 2524 | break; | 2527 | break; |
| 2525 | case 1: | 2528 | case 1: |
| 2526 | printf(format, (long)val); | 2529 | trace_seq_printf(s, format, (long)val); |
| 2527 | break; | 2530 | break; |
| 2528 | case 2: | 2531 | case 2: |
| 2529 | printf(format, (long long)val); | 2532 | trace_seq_printf(s, format, (long long)val); |
| 2530 | break; | 2533 | break; |
| 2531 | default: | 2534 | default: |
| 2532 | die("bad count (%d)", ls); | 2535 | die("bad count (%d)", ls); |
| @@ -2536,15 +2539,15 @@ static void pretty_print(void *data, int size, struct event *event) | |||
| 2536 | if (!arg) | 2539 | if (!arg) |
| 2537 | die("no matching argument"); | 2540 | die("no matching argument"); |
| 2538 | 2541 | ||
| 2539 | print_str_arg(data, size, event, arg); | 2542 | print_str_arg(s, data, size, event, arg); |
| 2540 | arg = arg->next; | 2543 | arg = arg->next; |
| 2541 | break; | 2544 | break; |
| 2542 | default: | 2545 | default: |
| 2543 | printf(">%c<", *ptr); | 2546 | trace_seq_printf(s, ">%c<", *ptr); |
| 2544 | 2547 | ||
| 2545 | } | 2548 | } |
| 2546 | } else | 2549 | } else |
| 2547 | printf("%c", *ptr); | 2550 | trace_seq_putc(s, *ptr); |
| 2548 | } | 2551 | } |
| 2549 | 2552 | ||
| 2550 | if (args) { | 2553 | if (args) { |
| @@ -2562,7 +2565,7 @@ static inline int log10_cpu(int nb) | |||
| 2562 | return 1; | 2565 | return 1; |
| 2563 | } | 2566 | } |
| 2564 | 2567 | ||
| 2565 | static void print_lat_fmt(void *data, int size __unused) | 2568 | static void print_lat_fmt(struct trace_seq *s, void *data, int size __unused) |
| 2566 | { | 2569 | { |
| 2567 | unsigned int lat_flags; | 2570 | unsigned int lat_flags; |
| 2568 | unsigned int pc; | 2571 | unsigned int pc; |
| @@ -2577,7 +2580,7 @@ static void print_lat_fmt(void *data, int size __unused) | |||
| 2577 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; | 2580 | hardirq = lat_flags & TRACE_FLAG_HARDIRQ; |
| 2578 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; | 2581 | softirq = lat_flags & TRACE_FLAG_SOFTIRQ; |
| 2579 | 2582 | ||
| 2580 | printf("%c%c%c", | 2583 | trace_seq_printf(s, "%c%c%c", |
| 2581 | (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' : | 2584 | (lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' : |
| 2582 | (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ? | 2585 | (lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ? |
| 2583 | 'X' : '.', | 2586 | 'X' : '.', |
| @@ -2587,18 +2590,18 @@ static void print_lat_fmt(void *data, int size __unused) | |||
| 2587 | hardirq ? 'h' : softirq ? 's' : '.'); | 2590 | hardirq ? 'h' : softirq ? 's' : '.'); |
| 2588 | 2591 | ||
| 2589 | if (pc) | 2592 | if (pc) |
| 2590 | printf("%x", pc); | 2593 | trace_seq_printf(s, "%x", pc); |
| 2591 | else | 2594 | else |
| 2592 | printf("."); | 2595 | trace_seq_putc(s, '.'); |
| 2593 | 2596 | ||
| 2594 | if (lock_depth < 0) | 2597 | if (lock_depth < 0) |
| 2595 | printf("."); | 2598 | trace_seq_putc(s, '.'); |
| 2596 | else | 2599 | else |
| 2597 | printf("%d", lock_depth); | 2600 | trace_seq_printf(s, "%d", lock_depth); |
| 2598 | } | 2601 | } |
| 2599 | 2602 | ||
| 2600 | /* taken from Linux, written by Frederic Weisbecker */ | 2603 | /* taken from Linux, written by Frederic Weisbecker */ |
| 2601 | static void print_graph_cpu(int cpu) | 2604 | static void print_graph_cpu(struct trace_seq *s, int cpu) |
| 2602 | { | 2605 | { |
| 2603 | int i; | 2606 | int i; |
| 2604 | int log10_this = log10_cpu(cpu); | 2607 | int log10_this = log10_cpu(cpu); |
| @@ -2610,7 +2613,7 @@ static void print_graph_cpu(int cpu) | |||
| 2610 | * to the right a bit when trace output is pasted into | 2613 | * to the right a bit when trace output is pasted into |
| 2611 | * email: | 2614 | * email: |
| 2612 | */ | 2615 | */ |
| 2613 | printf(" "); | 2616 | trace_seq_putc(s, ' '); |
| 2614 | 2617 | ||
| 2615 | /* | 2618 | /* |
| 2616 | * Tricky - we space the CPU field according to the max | 2619 | * Tricky - we space the CPU field according to the max |
| @@ -2619,15 +2622,15 @@ static void print_graph_cpu(int cpu) | |||
| 2619 | * take up to 3 digits: | 2622 | * take up to 3 digits: |
| 2620 | */ | 2623 | */ |
| 2621 | for (i = 0; i < log10_all - log10_this; i++) | 2624 | for (i = 0; i < log10_all - log10_this; i++) |
| 2622 | printf(" "); | 2625 | trace_seq_putc(s, ' '); |
| 2623 | 2626 | ||
| 2624 | printf("%d) ", cpu); | 2627 | trace_seq_printf(s, "%d) ", cpu); |
| 2625 | } | 2628 | } |
| 2626 | 2629 | ||
| 2627 | #define TRACE_GRAPH_PROCINFO_LENGTH 14 | 2630 | #define TRACE_GRAPH_PROCINFO_LENGTH 14 |
| 2628 | #define TRACE_GRAPH_INDENT 2 | 2631 | #define TRACE_GRAPH_INDENT 2 |
| 2629 | 2632 | ||
| 2630 | static void print_graph_proc(int pid, const char *comm) | 2633 | static void print_graph_proc(struct trace_seq *s, int pid, const char *comm) |
| 2631 | { | 2634 | { |
| 2632 | /* sign + log10(MAX_INT) + '\0' */ | 2635 | /* sign + log10(MAX_INT) + '\0' */ |
| 2633 | char pid_str[11]; | 2636 | char pid_str[11]; |
| @@ -2645,13 +2648,13 @@ static void print_graph_proc(int pid, const char *comm) | |||
| 2645 | 2648 | ||
| 2646 | /* First spaces to align center */ | 2649 | /* First spaces to align center */ |
| 2647 | for (i = 0; i < spaces / 2; i++) | 2650 | for (i = 0; i < spaces / 2; i++) |
| 2648 | printf(" "); | 2651 | trace_seq_putc(s, ' '); |
| 2649 | 2652 | ||
| 2650 | printf("%s-%s", comm, pid_str); | 2653 | trace_seq_printf(s, "%s-%s", comm, pid_str); |
| 2651 | 2654 | ||
| 2652 | /* Last spaces to align center */ | 2655 | /* Last spaces to align center */ |
| 2653 | for (i = 0; i < spaces - (spaces / 2); i++) | 2656 | for (i = 0; i < spaces - (spaces / 2); i++) |
| 2654 | printf(" "); | 2657 | trace_seq_putc(s, ' '); |
| 2655 | } | 2658 | } |
| 2656 | 2659 | ||
| 2657 | static struct record * | 2660 | static struct record * |
| @@ -2687,24 +2690,25 @@ get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func, | |||
| 2687 | } | 2690 | } |
| 2688 | 2691 | ||
| 2689 | /* Signal a overhead of time execution to the output */ | 2692 | /* Signal a overhead of time execution to the output */ |
| 2690 | static void print_graph_overhead(unsigned long long duration) | 2693 | static void print_graph_overhead(struct trace_seq *s, |
| 2694 | unsigned long long duration) | ||
| 2691 | { | 2695 | { |
| 2692 | /* Non nested entry or return */ | 2696 | /* Non nested entry or return */ |
| 2693 | if (duration == ~0ULL) | 2697 | if (duration == ~0ULL) |
| 2694 | return (void)printf(" "); | 2698 | return (void)trace_seq_printf(s, " "); |
| 2695 | 2699 | ||
| 2696 | /* Duration exceeded 100 msecs */ | 2700 | /* Duration exceeded 100 msecs */ |
| 2697 | if (duration > 100000ULL) | 2701 | if (duration > 100000ULL) |
| 2698 | return (void)printf("! "); | 2702 | return (void)trace_seq_printf(s, "! "); |
| 2699 | 2703 | ||
| 2700 | /* Duration exceeded 10 msecs */ | 2704 | /* Duration exceeded 10 msecs */ |
| 2701 | if (duration > 10000ULL) | 2705 | if (duration > 10000ULL) |
| 2702 | return (void)printf("+ "); | 2706 | return (void)trace_seq_printf(s, "+ "); |
| 2703 | 2707 | ||
| 2704 | printf(" "); | 2708 | trace_seq_printf(s, " "); |
| 2705 | } | 2709 | } |
| 2706 | 2710 | ||
| 2707 | static void print_graph_duration(unsigned long long duration) | 2711 | static void print_graph_duration(struct trace_seq *s, unsigned long long duration) |
| 2708 | { | 2712 | { |
| 2709 | unsigned long usecs = duration / 1000; | 2713 | unsigned long usecs = duration / 1000; |
| 2710 | unsigned long nsecs_rem = duration % 1000; | 2714 | unsigned long nsecs_rem = duration % 1000; |
| @@ -2717,25 +2721,26 @@ static void print_graph_duration(unsigned long long duration) | |||
| 2717 | sprintf(msecs_str, "%lu", usecs); | 2721 | sprintf(msecs_str, "%lu", usecs); |
| 2718 | 2722 | ||
| 2719 | /* Print msecs */ | 2723 | /* Print msecs */ |
| 2720 | len = printf("%lu", usecs); | 2724 | len = trace_seq_printf(s, "%lu", usecs); |
| 2721 | 2725 | ||
| 2722 | /* Print nsecs (we don't want to exceed 7 numbers) */ | 2726 | /* Print nsecs (we don't want to exceed 7 numbers) */ |
| 2723 | if (len < 7) { | 2727 | if (len < 7) { |
| 2724 | snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem); | 2728 | snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem); |
| 2725 | len += printf(".%s", nsecs_str); | 2729 | len += trace_seq_printf(s, ".%s", nsecs_str); |
| 2726 | } | 2730 | } |
| 2727 | 2731 | ||
| 2728 | printf(" us "); | 2732 | trace_seq_puts(s, " us "); |
| 2729 | 2733 | ||
| 2730 | /* Print remaining spaces to fit the row's width */ | 2734 | /* Print remaining spaces to fit the row's width */ |
| 2731 | for (i = len; i < 7; i++) | 2735 | for (i = len; i < 7; i++) |
| 2732 | printf(" "); | 2736 | trace_seq_putc(s, ' '); |
| 2733 | 2737 | ||
| 2734 | printf("| "); | 2738 | trace_seq_puts(s, "| "); |
| 2735 | } | 2739 | } |
| 2736 | 2740 | ||
| 2737 | static void | 2741 | static void |
| 2738 | print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec) | 2742 | print_graph_entry_leaf(struct trace_seq *s, |
| 2743 | struct event *event, void *data, struct record *ret_rec) | ||
| 2739 | { | 2744 | { |
| 2740 | unsigned long long rettime, calltime; | 2745 | unsigned long long rettime, calltime; |
| 2741 | unsigned long long duration, depth; | 2746 | unsigned long long duration, depth; |
| @@ -2762,10 +2767,10 @@ print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec) | |||
| 2762 | duration = rettime - calltime; | 2767 | duration = rettime - calltime; |
| 2763 | 2768 | ||
| 2764 | /* Overhead */ | 2769 | /* Overhead */ |
| 2765 | print_graph_overhead(duration); | 2770 | print_graph_overhead(s, duration); |
| 2766 | 2771 | ||
| 2767 | /* Duration */ | 2772 | /* Duration */ |
| 2768 | print_graph_duration(duration); | 2773 | print_graph_duration(s, duration); |
| 2769 | 2774 | ||
| 2770 | field = find_field(event, "depth"); | 2775 | field = find_field(event, "depth"); |
| 2771 | if (!field) | 2776 | if (!field) |
| @@ -2774,7 +2779,7 @@ print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec) | |||
| 2774 | 2779 | ||
| 2775 | /* Function */ | 2780 | /* Function */ |
| 2776 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) | 2781 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) |
| 2777 | printf(" "); | 2782 | trace_seq_putc(s, ' '); |
| 2778 | 2783 | ||
| 2779 | field = find_field(event, "func"); | 2784 | field = find_field(event, "func"); |
| 2780 | if (!field) | 2785 | if (!field) |
| @@ -2783,12 +2788,13 @@ print_graph_entry_leaf(struct event *event, void *data, struct record *ret_rec) | |||
| 2783 | func = find_func(val); | 2788 | func = find_func(val); |
| 2784 | 2789 | ||
| 2785 | if (func) | 2790 | if (func) |
| 2786 | printf("%s();", func->func); | 2791 | trace_seq_printf(s, "%s();", func->func); |
| 2787 | else | 2792 | else |
| 2788 | printf("%llx();", val); | 2793 | trace_seq_printf(s, "%llx();", val); |
| 2789 | } | 2794 | } |
| 2790 | 2795 | ||
| 2791 | static void print_graph_nested(struct event *event, void *data) | 2796 | static void print_graph_nested(struct trace_seq *s, |
| 2797 | struct event *event, void *data) | ||
| 2792 | { | 2798 | { |
| 2793 | struct format_field *field; | 2799 | struct format_field *field; |
| 2794 | unsigned long long depth; | 2800 | unsigned long long depth; |
| @@ -2797,10 +2803,10 @@ static void print_graph_nested(struct event *event, void *data) | |||
| 2797 | int i; | 2803 | int i; |
| 2798 | 2804 | ||
| 2799 | /* No overhead */ | 2805 | /* No overhead */ |
| 2800 | print_graph_overhead(-1); | 2806 | print_graph_overhead(s, -1); |
| 2801 | 2807 | ||
| 2802 | /* No time */ | 2808 | /* No time */ |
| 2803 | printf(" | "); | 2809 | trace_seq_puts(s, " | "); |
| 2804 | 2810 | ||
| 2805 | field = find_field(event, "depth"); | 2811 | field = find_field(event, "depth"); |
| 2806 | if (!field) | 2812 | if (!field) |
| @@ -2809,7 +2815,7 @@ static void print_graph_nested(struct event *event, void *data) | |||
| 2809 | 2815 | ||
| 2810 | /* Function */ | 2816 | /* Function */ |
| 2811 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) | 2817 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) |
| 2812 | printf(" "); | 2818 | trace_seq_putc(s, ' '); |
| 2813 | 2819 | ||
| 2814 | field = find_field(event, "func"); | 2820 | field = find_field(event, "func"); |
| 2815 | if (!field) | 2821 | if (!field) |
| @@ -2818,13 +2824,14 @@ static void print_graph_nested(struct event *event, void *data) | |||
| 2818 | func = find_func(val); | 2824 | func = find_func(val); |
| 2819 | 2825 | ||
| 2820 | if (func) | 2826 | if (func) |
| 2821 | printf("%s() {", func->func); | 2827 | trace_seq_printf(s, "%s() {", func->func); |
| 2822 | else | 2828 | else |
| 2823 | printf("%llx() {", val); | 2829 | trace_seq_printf(s, "%llx() {", val); |
| 2824 | } | 2830 | } |
| 2825 | 2831 | ||
| 2826 | static void | 2832 | static void |
| 2827 | pretty_print_func_ent(void *data, int size, struct event *event, | 2833 | pretty_print_func_ent(struct trace_seq *s, |
| 2834 | void *data, int size, struct event *event, | ||
| 2828 | int cpu, int pid, const char *comm, | 2835 | int cpu, int pid, const char *comm, |
| 2829 | unsigned long secs, unsigned long usecs) | 2836 | unsigned long secs, unsigned long usecs) |
| 2830 | { | 2837 | { |
| @@ -2833,16 +2840,16 @@ pretty_print_func_ent(void *data, int size, struct event *event, | |||
| 2833 | void *copy_data; | 2840 | void *copy_data; |
| 2834 | unsigned long val; | 2841 | unsigned long val; |
| 2835 | 2842 | ||
| 2836 | printf("%5lu.%06lu | ", secs, usecs); | 2843 | trace_seq_printf(s, "%5lu.%06lu | ", secs, usecs); |
| 2837 | 2844 | ||
| 2838 | print_graph_cpu(cpu); | 2845 | print_graph_cpu(s, cpu); |
| 2839 | print_graph_proc(pid, comm); | 2846 | print_graph_proc(s, pid, comm); |
| 2840 | 2847 | ||
| 2841 | printf(" | "); | 2848 | trace_seq_puts(s, " | "); |
| 2842 | 2849 | ||
| 2843 | if (latency_format) { | 2850 | if (latency_format) { |
| 2844 | print_lat_fmt(data, size); | 2851 | print_lat_fmt(s, data, size); |
| 2845 | printf(" | "); | 2852 | trace_seq_puts(s, " | "); |
| 2846 | } | 2853 | } |
| 2847 | 2854 | ||
| 2848 | field = find_field(event, "func"); | 2855 | field = find_field(event, "func"); |
| @@ -2862,17 +2869,18 @@ pretty_print_func_ent(void *data, int size, struct event *event, | |||
| 2862 | if (rec) { | 2869 | if (rec) { |
| 2863 | rec = get_return_for_leaf(cpu, pid, val, rec); | 2870 | rec = get_return_for_leaf(cpu, pid, val, rec); |
| 2864 | if (rec) { | 2871 | if (rec) { |
| 2865 | print_graph_entry_leaf(event, data, rec); | 2872 | print_graph_entry_leaf(s, event, data, rec); |
| 2866 | goto out_free; | 2873 | goto out_free; |
| 2867 | } | 2874 | } |
| 2868 | } | 2875 | } |
| 2869 | print_graph_nested(event, data); | 2876 | print_graph_nested(s, event, data); |
| 2870 | out_free: | 2877 | out_free: |
| 2871 | free(data); | 2878 | free(data); |
| 2872 | } | 2879 | } |
| 2873 | 2880 | ||
| 2874 | static void | 2881 | static void |
| 2875 | pretty_print_func_ret(void *data, int size __unused, struct event *event, | 2882 | pretty_print_func_ret(struct trace_seq *s, |
| 2883 | void *data, int size __unused, struct event *event, | ||
| 2876 | int cpu, int pid, const char *comm, | 2884 | int cpu, int pid, const char *comm, |
| 2877 | unsigned long secs, unsigned long usecs) | 2885 | unsigned long secs, unsigned long usecs) |
| 2878 | { | 2886 | { |
| @@ -2881,16 +2889,16 @@ pretty_print_func_ret(void *data, int size __unused, struct event *event, | |||
| 2881 | struct format_field *field; | 2889 | struct format_field *field; |
| 2882 | int i; | 2890 | int i; |
| 2883 | 2891 | ||
| 2884 | printf("%5lu.%06lu | ", secs, usecs); | 2892 | trace_seq_printf(s, "%5lu.%06lu | ", secs, usecs); |
| 2885 | 2893 | ||
| 2886 | print_graph_cpu(cpu); | 2894 | print_graph_cpu(s, cpu); |
| 2887 | print_graph_proc(pid, comm); | 2895 | print_graph_proc(s, pid, comm); |
| 2888 | 2896 | ||
| 2889 | printf(" | "); | 2897 | trace_seq_puts(s, " | "); |
| 2890 | 2898 | ||
| 2891 | if (latency_format) { | 2899 | if (latency_format) { |
| 2892 | print_lat_fmt(data, size); | 2900 | print_lat_fmt(s, data, size); |
| 2893 | printf(" | "); | 2901 | trace_seq_puts(s, " | "); |
| 2894 | } | 2902 | } |
| 2895 | 2903 | ||
| 2896 | field = find_field(event, "rettime"); | 2904 | field = find_field(event, "rettime"); |
| @@ -2906,10 +2914,10 @@ pretty_print_func_ret(void *data, int size __unused, struct event *event, | |||
| 2906 | duration = rettime - calltime; | 2914 | duration = rettime - calltime; |
| 2907 | 2915 | ||
| 2908 | /* Overhead */ | 2916 | /* Overhead */ |
| 2909 | print_graph_overhead(duration); | 2917 | print_graph_overhead(s, duration); |
| 2910 | 2918 | ||
| 2911 | /* Duration */ | 2919 | /* Duration */ |
| 2912 | print_graph_duration(duration); | 2920 | print_graph_duration(s, duration); |
| 2913 | 2921 | ||
| 2914 | field = find_field(event, "depth"); | 2922 | field = find_field(event, "depth"); |
| 2915 | if (!field) | 2923 | if (!field) |
| @@ -2918,26 +2926,28 @@ pretty_print_func_ret(void *data, int size __unused, struct event *event, | |||
| 2918 | 2926 | ||
| 2919 | /* Function */ | 2927 | /* Function */ |
| 2920 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) | 2928 | for (i = 0; i < (int)(depth * TRACE_GRAPH_INDENT); i++) |
| 2921 | printf(" "); | 2929 | trace_seq_putc(s, ' '); |
| 2922 | 2930 | ||
| 2923 | printf("}"); | 2931 | trace_seq_putc(s, '}'); |
| 2924 | } | 2932 | } |
| 2925 | 2933 | ||
| 2926 | static void | 2934 | static void |
| 2927 | pretty_print_func_graph(void *data, int size, struct event *event, | 2935 | pretty_print_func_graph(struct trace_seq *s, |
| 2936 | void *data, int size, struct event *event, | ||
| 2928 | int cpu, int pid, const char *comm, | 2937 | int cpu, int pid, const char *comm, |
| 2929 | unsigned long secs, unsigned long usecs) | 2938 | unsigned long secs, unsigned long usecs) |
| 2930 | { | 2939 | { |
| 2931 | if (event->flags & EVENT_FL_ISFUNCENT) | 2940 | if (event->flags & EVENT_FL_ISFUNCENT) |
| 2932 | pretty_print_func_ent(data, size, event, | 2941 | pretty_print_func_ent(s, data, size, event, |
| 2933 | cpu, pid, comm, secs, usecs); | 2942 | cpu, pid, comm, secs, usecs); |
| 2934 | else if (event->flags & EVENT_FL_ISFUNCRET) | 2943 | else if (event->flags & EVENT_FL_ISFUNCRET) |
| 2935 | pretty_print_func_ret(data, size, event, | 2944 | pretty_print_func_ret(s, data, size, event, |
| 2936 | cpu, pid, comm, secs, usecs); | 2945 | cpu, pid, comm, secs, usecs); |
| 2937 | printf("\n"); | 2946 | trace_seq_putc(s, '\n'); |
| 2938 | } | 2947 | } |
| 2939 | 2948 | ||
| 2940 | void print_event(int cpu, void *data, int size, unsigned long long nsecs) | 2949 | void print_event(struct trace_seq *s, |
| 2950 | int cpu, void *data, int size, unsigned long long nsecs) | ||
| 2941 | { | 2951 | { |
| 2942 | struct event *event; | 2952 | struct event *event; |
| 2943 | unsigned long secs; | 2953 | unsigned long secs; |
| @@ -2962,40 +2972,42 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs) | |||
| 2962 | comm = find_cmdline(pid); | 2972 | comm = find_cmdline(pid); |
| 2963 | 2973 | ||
| 2964 | if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET)) | 2974 | if (event->flags & (EVENT_FL_ISFUNCENT | EVENT_FL_ISFUNCRET)) |
| 2965 | return pretty_print_func_graph(data, size, event, cpu, | 2975 | return pretty_print_func_graph(s, data, size, event, cpu, |
| 2966 | pid, comm, secs, usecs); | 2976 | pid, comm, secs, usecs); |
| 2967 | 2977 | ||
| 2968 | if (latency_format) { | 2978 | if (latency_format) { |
| 2969 | printf("%8.8s-%-5d %3d", | 2979 | trace_seq_printf(s, "%8.8s-%-5d %3d", |
| 2970 | comm, pid, cpu); | 2980 | comm, pid, cpu); |
| 2971 | print_lat_fmt(data, size); | 2981 | print_lat_fmt(s, data, size); |
| 2972 | } else | 2982 | } else |
| 2973 | printf("%16s-%-5d [%03d]", comm, pid, cpu); | 2983 | trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, cpu); |
| 2974 | 2984 | ||
| 2975 | printf(" %5lu.%06lu: %s: ", secs, usecs, event->name); | 2985 | trace_seq_printf(s, " %5lu.%06lu: %s: ", secs, usecs, event->name); |
| 2976 | 2986 | ||
| 2977 | if (event->flags & EVENT_FL_FAILED) { | 2987 | if (event->flags & EVENT_FL_FAILED) { |
| 2978 | printf("EVENT '%s' FAILED TO PARSE\n", | 2988 | trace_seq_printf(s, "EVENT '%s' FAILED TO PARSE\n", |
| 2979 | event->name); | 2989 | event->name); |
| 2980 | return; | 2990 | return; |
| 2981 | } | 2991 | } |
| 2982 | 2992 | ||
| 2983 | pretty_print(data, size, event); | 2993 | pretty_print(s, data, size, event); |
| 2984 | printf("\n"); | 2994 | trace_seq_putc(s, '\n'); |
| 2985 | } | 2995 | } |
| 2986 | 2996 | ||
| 2987 | static void print_fields(struct print_flag_sym *field) | 2997 | static void print_fields(struct trace_seq *s, struct print_flag_sym *field) |
| 2988 | { | 2998 | { |
| 2989 | printf("{ %s, %s }", field->value, field->str); | 2999 | trace_seq_printf(s, "{ %s, %s }", field->value, field->str); |
| 2990 | if (field->next) { | 3000 | if (field->next) { |
| 2991 | printf(", "); | 3001 | trace_seq_puts(s, ", "); |
| 2992 | print_fields(field->next); | 3002 | print_fields(s, field->next); |
| 2993 | } | 3003 | } |
| 2994 | } | 3004 | } |
| 2995 | 3005 | ||
| 3006 | /* for debugging */ | ||
| 2996 | static void print_args(struct print_arg *args) | 3007 | static void print_args(struct print_arg *args) |
| 2997 | { | 3008 | { |
| 2998 | int print_paren = 1; | 3009 | int print_paren = 1; |
| 3010 | struct trace_seq s; | ||
| 2999 | 3011 | ||
| 3000 | switch (args->type) { | 3012 | switch (args->type) { |
| 3001 | case PRINT_NULL: | 3013 | case PRINT_NULL: |
| @@ -3011,14 +3023,18 @@ static void print_args(struct print_arg *args) | |||
| 3011 | printf("__print_flags("); | 3023 | printf("__print_flags("); |
| 3012 | print_args(args->flags.field); | 3024 | print_args(args->flags.field); |
| 3013 | printf(", %s, ", args->flags.delim); | 3025 | printf(", %s, ", args->flags.delim); |
| 3014 | print_fields(args->flags.flags); | 3026 | trace_seq_init(&s); |
| 3027 | print_fields(&s, args->flags.flags); | ||
| 3028 | trace_seq_do_printf(&s); | ||
| 3015 | printf(")"); | 3029 | printf(")"); |
| 3016 | break; | 3030 | break; |
| 3017 | case PRINT_SYMBOL: | 3031 | case PRINT_SYMBOL: |
| 3018 | printf("__print_symbolic("); | 3032 | printf("__print_symbolic("); |
| 3019 | print_args(args->symbol.field); | 3033 | print_args(args->symbol.field); |
| 3020 | printf(", "); | 3034 | printf(", "); |
| 3021 | print_fields(args->symbol.symbols); | 3035 | trace_seq_init(&s); |
| 3036 | print_fields(&s, args->symbol.symbols); | ||
| 3037 | trace_seq_do_printf(&s); | ||
| 3022 | printf(")"); | 3038 | printf(")"); |
| 3023 | break; | 3039 | break; |
| 3024 | case PRINT_STRING: | 3040 | case PRINT_STRING: |
diff --git a/parse-events.h b/parse-events.h index 92248e5..740da6c 100644 --- a/parse-events.h +++ b/parse-events.h | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | #define __unused __attribute__ ((unused)) | 5 | #define __unused __attribute__ ((unused)) |
| 6 | #endif | 6 | #endif |
| 7 | 7 | ||
| 8 | #include "trace-seq.h" | ||
| 9 | |||
| 8 | /* unique to trace-cmd */ | 10 | /* unique to trace-cmd */ |
| 9 | extern unsigned int page_size; | 11 | extern unsigned int page_size; |
| 10 | void usage(char **argv); | 12 | void usage(char **argv); |
| @@ -178,7 +180,8 @@ void print_printk(void); | |||
| 178 | 180 | ||
| 179 | int parse_ftrace_file(char *buf, unsigned long size); | 181 | int parse_ftrace_file(char *buf, unsigned long size); |
| 180 | int parse_event_file(char *buf, unsigned long size, char *sys); | 182 | int parse_event_file(char *buf, unsigned long size, char *sys); |
| 181 | void print_event(int cpu, void *data, int size, unsigned long long nsecs); | 183 | void print_event(struct trace_seq *s, |
| 184 | int cpu, void *data, int size, unsigned long long nsecs); | ||
| 182 | 185 | ||
| 183 | extern int file_bigendian; | 186 | extern int file_bigendian; |
| 184 | extern int host_bigendian; | 187 | extern int host_bigendian; |
diff --git a/trace-read.c b/trace-read.c index bbe0395..e2c614a 100644 --- a/trace-read.c +++ b/trace-read.c | |||
| @@ -500,10 +500,13 @@ struct record *trace_read_data(int cpu) | |||
| 500 | static void show_data(int cpu) | 500 | static void show_data(int cpu) |
| 501 | { | 501 | { |
| 502 | struct record *record; | 502 | struct record *record; |
| 503 | struct trace_seq s; | ||
| 503 | 504 | ||
| 504 | record = trace_read_data(cpu); | 505 | record = trace_read_data(cpu); |
| 505 | 506 | ||
| 506 | print_event(cpu, record->data, record->size, record->ts); | 507 | trace_seq_init(&s); |
| 508 | print_event(&s, cpu, record->data, record->size, record->ts); | ||
| 509 | trace_seq_do_printf(&s); | ||
| 507 | 510 | ||
| 508 | free(record); | 511 | free(record); |
| 509 | } | 512 | } |
