diff options
Diffstat (limited to 'trace-read.c')
-rw-r--r-- | trace-read.c | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/trace-read.c b/trace-read.c index a5c27e2..f8455a3 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -56,6 +56,8 @@ const char *default_input_file = "trace.dat"; | |||
56 | const char *input_file; | 56 | const char *input_file; |
57 | 57 | ||
58 | static int filter_cpu = -1; | 58 | static int filter_cpu = -1; |
59 | static int *filter_cpus; | ||
60 | static int nr_filter_cpus; | ||
59 | 61 | ||
60 | static int show_wakeup; | 62 | static int show_wakeup; |
61 | static int wakeup_id; | 63 | static int wakeup_id; |
@@ -106,6 +108,7 @@ static void show_test(struct tracecmd_input *handle) | |||
106 | trace_seq_init(&s); | 108 | trace_seq_init(&s); |
107 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | 109 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); |
108 | trace_seq_do_printf(&s); | 110 | trace_seq_do_printf(&s); |
111 | trace_seq_destroy(&s); | ||
109 | printf("\n"); | 112 | printf("\n"); |
110 | 113 | ||
111 | free_record(record); | 114 | free_record(record); |
@@ -152,6 +155,7 @@ static void show_test(struct tracecmd_input *handle) | |||
152 | trace_seq_init(&s); | 155 | trace_seq_init(&s); |
153 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | 156 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); |
154 | trace_seq_do_printf(&s); | 157 | trace_seq_do_printf(&s); |
158 | trace_seq_destroy(&s); | ||
155 | printf("\n"); | 159 | printf("\n"); |
156 | 160 | ||
157 | free_record(record); | 161 | free_record(record); |
@@ -192,6 +196,7 @@ static void show_test(struct tracecmd_input *handle) | |||
192 | trace_seq_init(&s); | 196 | trace_seq_init(&s); |
193 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | 197 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); |
194 | trace_seq_do_printf(&s); | 198 | trace_seq_do_printf(&s); |
199 | trace_seq_destroy(&s); | ||
195 | printf("\n"); | 200 | printf("\n"); |
196 | 201 | ||
197 | free_record(record); | 202 | free_record(record); |
@@ -207,6 +212,7 @@ static void show_test(struct tracecmd_input *handle) | |||
207 | trace_seq_init(&s); | 212 | trace_seq_init(&s); |
208 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); | 213 | pevent_print_event(pevent, &s, cpu, record->data, record->size, record->ts); |
209 | trace_seq_do_printf(&s); | 214 | trace_seq_do_printf(&s); |
215 | trace_seq_destroy(&s); | ||
210 | printf("\n"); | 216 | printf("\n"); |
211 | 217 | ||
212 | free_record(record); | 218 | free_record(record); |
@@ -471,6 +477,7 @@ static void show_data(struct tracecmd_input *handle, | |||
471 | record->cpu); | 477 | record->cpu); |
472 | pevent_print_event(pevent, &s, record); | 478 | pevent_print_event(pevent, &s, record); |
473 | trace_seq_do_printf(&s); | 479 | trace_seq_do_printf(&s); |
480 | trace_seq_destroy(&s); | ||
474 | 481 | ||
475 | process_wakeup(pevent, record); | 482 | process_wakeup(pevent, record); |
476 | 483 | ||
@@ -519,7 +526,26 @@ static void read_data_info(struct tracecmd_input *handle) | |||
519 | do { | 526 | do { |
520 | next = -1; | 527 | next = -1; |
521 | ts = 0; | 528 | ts = 0; |
522 | if (filter_cpu >= 0) { | 529 | if (filter_cpus) { |
530 | unsigned long long last_stamp = 0; | ||
531 | struct record *precord; | ||
532 | int next_cpu = -1; | ||
533 | int i; | ||
534 | |||
535 | for (i = 0; (cpu = filter_cpus[i]) >= 0; i++) { | ||
536 | precord = tracecmd_peek_data(handle, cpu); | ||
537 | if (precord && | ||
538 | (!last_stamp || precord->ts < last_stamp)) { | ||
539 | next_cpu = cpu; | ||
540 | last_stamp = precord->ts; | ||
541 | } | ||
542 | } | ||
543 | if (last_stamp) | ||
544 | record = tracecmd_read_data(handle, next_cpu); | ||
545 | else | ||
546 | record = NULL; | ||
547 | |||
548 | } else if (filter_cpu >= 0) { | ||
523 | cpu = filter_cpu; | 549 | cpu = filter_cpu; |
524 | record = tracecmd_read_data(handle, cpu); | 550 | record = tracecmd_read_data(handle, cpu); |
525 | } else | 551 | } else |
@@ -560,6 +586,82 @@ static void sig_end(int sig) | |||
560 | exit(0); | 586 | exit(0); |
561 | } | 587 | } |
562 | 588 | ||
589 | static const char *inc_and_test_char(const char *p, const char *cpu_str) | ||
590 | { | ||
591 | p++; | ||
592 | while (isspace(*p)) | ||
593 | p++; | ||
594 | if (!isdigit(*p)) | ||
595 | die("invalid character '%c' in cpu string '%s'", | ||
596 | *p, cpu_str); | ||
597 | return p; | ||
598 | } | ||
599 | |||
600 | static void __add_cpu(int cpu) | ||
601 | { | ||
602 | filter_cpus = tracecmd_add_id(filter_cpus, cpu, nr_filter_cpus++); | ||
603 | } | ||
604 | |||
605 | static int process_cpu_str(const char *cpu_str) | ||
606 | { | ||
607 | const char *p = cpu_str; | ||
608 | int cpu, ncpu, ret_cpu = 1; | ||
609 | |||
610 | do { | ||
611 | while (isspace(*p)) | ||
612 | p++; | ||
613 | |||
614 | cpu = atoi(p); | ||
615 | __add_cpu(cpu); | ||
616 | |||
617 | again: | ||
618 | while (isdigit(*p)) | ||
619 | p++; | ||
620 | while (isspace(*p)) | ||
621 | p++; | ||
622 | |||
623 | if (*p) { | ||
624 | ret_cpu = 0; | ||
625 | switch (*p) { | ||
626 | case '-': | ||
627 | p = inc_and_test_char(p, cpu_str); | ||
628 | ncpu = atoi(p); | ||
629 | if (ncpu < cpu) | ||
630 | die("range of cpu numbers must be lower to greater"); | ||
631 | for (; cpu <= ncpu; cpu++) | ||
632 | __add_cpu(cpu); | ||
633 | break; | ||
634 | |||
635 | case ',': | ||
636 | case ':': | ||
637 | p = inc_and_test_char(p, cpu_str); | ||
638 | ncpu = atoi(p); | ||
639 | __add_cpu(ncpu); | ||
640 | break; | ||
641 | default: | ||
642 | die("invalid character '%c' in cpu string '%s'", | ||
643 | *p, cpu_str); | ||
644 | } | ||
645 | goto again; | ||
646 | } | ||
647 | } while (*p); | ||
648 | |||
649 | if (ret_cpu) | ||
650 | return cpu; | ||
651 | |||
652 | /* Return -1 if we added more than one CPU */ | ||
653 | return -1; | ||
654 | } | ||
655 | |||
656 | static void add_cpu(const char *cpu_str) | ||
657 | { | ||
658 | int cpu; | ||
659 | |||
660 | cpu = process_cpu_str(cpu_str); | ||
661 | if (cpu >= 0) | ||
662 | __add_cpu(cpu); | ||
663 | } | ||
664 | |||
563 | void trace_report (int argc, char **argv) | 665 | void trace_report (int argc, char **argv) |
564 | { | 666 | { |
565 | struct tracecmd_input *handle; | 667 | struct tracecmd_input *handle; |
@@ -650,7 +752,10 @@ void trace_report (int argc, char **argv) | |||
650 | case 0: | 752 | case 0: |
651 | switch(option_index) { | 753 | switch(option_index) { |
652 | case 0: | 754 | case 0: |
653 | filter_cpu = atoi(optarg); | 755 | if (filter_cpu) |
756 | add_cpu(optarg); | ||
757 | else | ||
758 | filter_cpu = atoi(optarg); | ||
654 | break; | 759 | break; |
655 | case 1: | 760 | case 1: |
656 | print_events = 1; | 761 | print_events = 1; |