aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-10-17 09:54:24 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-10-23 15:30:52 -0400
commita1a587073ccdc6ffae414259f65d0a94cadd0a72 (patch)
treef743b5b1df101378cafdf3d0f474cbe233ef72a6 /tools/perf/builtin-script.c
parent923d0c9ae570c3f33a0b5a9517c23ccc816d9b75 (diff)
perf script: Use fprintf like printing uniformly
We've been mixing print() with fprintf() style printing for a while, but now we need to use fprintf() like syntax uniformly as a preparatory patch for supporting printing to different files, one per event. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Cc: yuzhoujian <yuzhoujian@didichuxing.com> Link: http://lkml.kernel.org/n/tip-kv5z3v8ptfghbarv3a9usvin@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c491
1 files changed, 259 insertions, 232 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5a7dfc5691a1..3e83f4735b21 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -500,69 +500,76 @@ out:
500 return 0; 500 return 0;
501} 501}
502 502
503static void print_sample_iregs(struct perf_sample *sample, 503static int perf_sample__fprintf_iregs(struct perf_sample *sample,
504 struct perf_event_attr *attr) 504 struct perf_event_attr *attr, FILE *fp)
505{ 505{
506 struct regs_dump *regs = &sample->intr_regs; 506 struct regs_dump *regs = &sample->intr_regs;
507 uint64_t mask = attr->sample_regs_intr; 507 uint64_t mask = attr->sample_regs_intr;
508 unsigned i = 0, r; 508 unsigned i = 0, r;
509 int printed = 0;
509 510
510 if (!regs) 511 if (!regs)
511 return; 512 return 0;
512 513
513 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { 514 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
514 u64 val = regs->regs[i++]; 515 u64 val = regs->regs[i++];
515 printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val); 516 printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
516 } 517 }
518
519 return printed;
517} 520}
518 521
519static void print_sample_uregs(struct perf_sample *sample, 522static int perf_sample__fprintf_uregs(struct perf_sample *sample,
520 struct perf_event_attr *attr) 523 struct perf_event_attr *attr, FILE *fp)
521{ 524{
522 struct regs_dump *regs = &sample->user_regs; 525 struct regs_dump *regs = &sample->user_regs;
523 uint64_t mask = attr->sample_regs_user; 526 uint64_t mask = attr->sample_regs_user;
524 unsigned i = 0, r; 527 unsigned i = 0, r;
528 int printed = 0;
525 529
526 if (!regs || !regs->regs) 530 if (!regs || !regs->regs)
527 return; 531 return 0;
528 532
529 printf(" ABI:%" PRIu64 " ", regs->abi); 533 printed += fprintf(fp, " ABI:%" PRIu64 " ", regs->abi);
530 534
531 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { 535 for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
532 u64 val = regs->regs[i++]; 536 u64 val = regs->regs[i++];
533 printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val); 537 printed += fprintf(fp, "%5s:0x%"PRIx64" ", perf_reg_name(r), val);
534 } 538 }
539
540 return printed;
535} 541}
536 542
537static void print_sample_start(struct perf_sample *sample, 543static int perf_sample__fprintf_start(struct perf_sample *sample,
538 struct thread *thread, 544 struct thread *thread,
539 struct perf_evsel *evsel) 545 struct perf_evsel *evsel, FILE *fp)
540{ 546{
541 struct perf_event_attr *attr = &evsel->attr; 547 struct perf_event_attr *attr = &evsel->attr;
542 unsigned long secs; 548 unsigned long secs;
543 unsigned long long nsecs; 549 unsigned long long nsecs;
550 int printed = 0;
544 551
545 if (PRINT_FIELD(COMM)) { 552 if (PRINT_FIELD(COMM)) {
546 if (latency_format) 553 if (latency_format)
547 printf("%8.8s ", thread__comm_str(thread)); 554 printed += fprintf(fp, "%8.8s ", thread__comm_str(thread));
548 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain) 555 else if (PRINT_FIELD(IP) && symbol_conf.use_callchain)
549 printf("%s ", thread__comm_str(thread)); 556 printed += fprintf(fp, "%s ", thread__comm_str(thread));
550 else 557 else
551 printf("%16s ", thread__comm_str(thread)); 558 printed += fprintf(fp, "%16s ", thread__comm_str(thread));
552 } 559 }
553 560
554 if (PRINT_FIELD(PID) && PRINT_FIELD(TID)) 561 if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
555 printf("%5d/%-5d ", sample->pid, sample->tid); 562 printed += fprintf(fp, "%5d/%-5d ", sample->pid, sample->tid);
556 else if (PRINT_FIELD(PID)) 563 else if (PRINT_FIELD(PID))
557 printf("%5d ", sample->pid); 564 printed += fprintf(fp, "%5d ", sample->pid);
558 else if (PRINT_FIELD(TID)) 565 else if (PRINT_FIELD(TID))
559 printf("%5d ", sample->tid); 566 printed += fprintf(fp, "%5d ", sample->tid);
560 567
561 if (PRINT_FIELD(CPU)) { 568 if (PRINT_FIELD(CPU)) {
562 if (latency_format) 569 if (latency_format)
563 printf("%3d ", sample->cpu); 570 printed += fprintf(fp, "%3d ", sample->cpu);
564 else 571 else
565 printf("[%03d] ", sample->cpu); 572 printed += fprintf(fp, "[%03d] ", sample->cpu);
566 } 573 }
567 574
568 if (PRINT_FIELD(TIME)) { 575 if (PRINT_FIELD(TIME)) {
@@ -571,13 +578,15 @@ static void print_sample_start(struct perf_sample *sample,
571 nsecs -= secs * NSEC_PER_SEC; 578 nsecs -= secs * NSEC_PER_SEC;
572 579
573 if (nanosecs) 580 if (nanosecs)
574 printf("%5lu.%09llu: ", secs, nsecs); 581 printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs);
575 else { 582 else {
576 char sample_time[32]; 583 char sample_time[32];
577 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time)); 584 timestamp__scnprintf_usec(sample->time, sample_time, sizeof(sample_time));
578 printf("%12s: ", sample_time); 585 printed += fprintf(fp, "%12s: ", sample_time);
579 } 586 }
580 } 587 }
588
589 return printed;
581} 590}
582 591
583static inline char 592static inline char
@@ -589,16 +598,17 @@ mispred_str(struct branch_entry *br)
589 return br->flags.predicted ? 'P' : 'M'; 598 return br->flags.predicted ? 'P' : 'M';
590} 599}
591 600
592static void print_sample_brstack(struct perf_sample *sample, 601static int perf_sample__fprintf_brstack(struct perf_sample *sample,
593 struct thread *thread, 602 struct thread *thread,
594 struct perf_event_attr *attr) 603 struct perf_event_attr *attr, FILE *fp)
595{ 604{
596 struct branch_stack *br = sample->branch_stack; 605 struct branch_stack *br = sample->branch_stack;
597 struct addr_location alf, alt; 606 struct addr_location alf, alt;
598 u64 i, from, to; 607 u64 i, from, to;
608 int printed = 0;
599 609
600 if (!(br && br->nr)) 610 if (!(br && br->nr))
601 return; 611 return 0;
602 612
603 for (i = 0; i < br->nr; i++) { 613 for (i = 0; i < br->nr; i++) {
604 from = br->entries[i].from; 614 from = br->entries[i].from;
@@ -611,38 +621,41 @@ static void print_sample_brstack(struct perf_sample *sample,
611 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); 621 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
612 } 622 }
613 623
614 printf(" 0x%"PRIx64, from); 624 printed += fprintf(fp, " 0x%"PRIx64, from);
615 if (PRINT_FIELD(DSO)) { 625 if (PRINT_FIELD(DSO)) {
616 printf("("); 626 printed += fprintf(fp, "(");
617 map__fprintf_dsoname(alf.map, stdout); 627 printed += map__fprintf_dsoname(alf.map, fp);
618 printf(")"); 628 printed += fprintf(fp, ")");
619 } 629 }
620 630
621 printf("/0x%"PRIx64, to); 631 printed += fprintf(fp, "/0x%"PRIx64, to);
622 if (PRINT_FIELD(DSO)) { 632 if (PRINT_FIELD(DSO)) {
623 printf("("); 633 printed += fprintf(fp, "(");
624 map__fprintf_dsoname(alt.map, stdout); 634 printed += map__fprintf_dsoname(alt.map, fp);
625 printf(")"); 635 printed += fprintf(fp, ")");
626 } 636 }
627 637
628 printf("/%c/%c/%c/%d ", 638 printed += fprintf(fp, "/%c/%c/%c/%d ",
629 mispred_str( br->entries + i), 639 mispred_str( br->entries + i),
630 br->entries[i].flags.in_tx? 'X' : '-', 640 br->entries[i].flags.in_tx? 'X' : '-',
631 br->entries[i].flags.abort? 'A' : '-', 641 br->entries[i].flags.abort? 'A' : '-',
632 br->entries[i].flags.cycles); 642 br->entries[i].flags.cycles);
633 } 643 }
644
645 return printed;
634} 646}
635 647
636static void print_sample_brstacksym(struct perf_sample *sample, 648static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,
637 struct thread *thread, 649 struct thread *thread,
638 struct perf_event_attr *attr) 650 struct perf_event_attr *attr, FILE *fp)
639{ 651{
640 struct branch_stack *br = sample->branch_stack; 652 struct branch_stack *br = sample->branch_stack;
641 struct addr_location alf, alt; 653 struct addr_location alf, alt;
642 u64 i, from, to; 654 u64 i, from, to;
655 int printed = 0;
643 656
644 if (!(br && br->nr)) 657 if (!(br && br->nr))
645 return; 658 return 0;
646 659
647 for (i = 0; i < br->nr; i++) { 660 for (i = 0; i < br->nr; i++) {
648 661
@@ -659,37 +672,40 @@ static void print_sample_brstacksym(struct perf_sample *sample,
659 if (alt.map) 672 if (alt.map)
660 alt.sym = map__find_symbol(alt.map, alt.addr); 673 alt.sym = map__find_symbol(alt.map, alt.addr);
661 674
662 symbol__fprintf_symname_offs(alf.sym, &alf, stdout); 675 printed += symbol__fprintf_symname_offs(alf.sym, &alf, fp);
663 if (PRINT_FIELD(DSO)) { 676 if (PRINT_FIELD(DSO)) {
664 printf("("); 677 printed += fprintf(fp, "(");
665 map__fprintf_dsoname(alf.map, stdout); 678 printed += map__fprintf_dsoname(alf.map, fp);
666 printf(")"); 679 printed += fprintf(fp, ")");
667 } 680 }
668 putchar('/'); 681 printed += fprintf(fp, "%c", '/');
669 symbol__fprintf_symname_offs(alt.sym, &alt, stdout); 682 printed += symbol__fprintf_symname_offs(alt.sym, &alt, fp);
670 if (PRINT_FIELD(DSO)) { 683 if (PRINT_FIELD(DSO)) {
671 printf("("); 684 printed += fprintf(fp, "(");
672 map__fprintf_dsoname(alt.map, stdout); 685 printed += map__fprintf_dsoname(alt.map, fp);
673 printf(")"); 686 printed += fprintf(fp, ")");
674 } 687 }
675 printf("/%c/%c/%c/%d ", 688 printed += fprintf(fp, "/%c/%c/%c/%d ",
676 mispred_str( br->entries + i), 689 mispred_str( br->entries + i),
677 br->entries[i].flags.in_tx? 'X' : '-', 690 br->entries[i].flags.in_tx? 'X' : '-',
678 br->entries[i].flags.abort? 'A' : '-', 691 br->entries[i].flags.abort? 'A' : '-',
679 br->entries[i].flags.cycles); 692 br->entries[i].flags.cycles);
680 } 693 }
694
695 return printed;
681} 696}
682 697
683static void print_sample_brstackoff(struct perf_sample *sample, 698static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
684 struct thread *thread, 699 struct thread *thread,
685 struct perf_event_attr *attr) 700 struct perf_event_attr *attr, FILE *fp)
686{ 701{
687 struct branch_stack *br = sample->branch_stack; 702 struct branch_stack *br = sample->branch_stack;
688 struct addr_location alf, alt; 703 struct addr_location alf, alt;
689 u64 i, from, to; 704 u64 i, from, to;
705 int printed = 0;
690 706
691 if (!(br && br->nr)) 707 if (!(br && br->nr))
692 return; 708 return 0;
693 709
694 for (i = 0; i < br->nr; i++) { 710 for (i = 0; i < br->nr; i++) {
695 711
@@ -706,24 +722,26 @@ static void print_sample_brstackoff(struct perf_sample *sample,
706 if (alt.map && !alt.map->dso->adjust_symbols) 722 if (alt.map && !alt.map->dso->adjust_symbols)
707 to = map__map_ip(alt.map, to); 723 to = map__map_ip(alt.map, to);
708 724
709 printf(" 0x%"PRIx64, from); 725 printed += fprintf(fp, " 0x%"PRIx64, from);
710 if (PRINT_FIELD(DSO)) { 726 if (PRINT_FIELD(DSO)) {
711 printf("("); 727 printed += fprintf(fp, "(");
712 map__fprintf_dsoname(alf.map, stdout); 728 printed += map__fprintf_dsoname(alf.map, fp);
713 printf(")"); 729 printed += fprintf(fp, ")");
714 } 730 }
715 printf("/0x%"PRIx64, to); 731 printed += fprintf(fp, "/0x%"PRIx64, to);
716 if (PRINT_FIELD(DSO)) { 732 if (PRINT_FIELD(DSO)) {
717 printf("("); 733 printed += fprintf(fp, "(");
718 map__fprintf_dsoname(alt.map, stdout); 734 printed += map__fprintf_dsoname(alt.map, fp);
719 printf(")"); 735 printed += fprintf(fp, ")");
720 } 736 }
721 printf("/%c/%c/%c/%d ", 737 printed += fprintf(fp, "/%c/%c/%c/%d ",
722 mispred_str(br->entries + i), 738 mispred_str(br->entries + i),
723 br->entries[i].flags.in_tx ? 'X' : '-', 739 br->entries[i].flags.in_tx ? 'X' : '-',
724 br->entries[i].flags.abort ? 'A' : '-', 740 br->entries[i].flags.abort ? 'A' : '-',
725 br->entries[i].flags.cycles); 741 br->entries[i].flags.cycles);
726 } 742 }
743
744 return printed;
727} 745}
728#define MAXBB 16384UL 746#define MAXBB 16384UL
729 747
@@ -789,31 +807,30 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
789 return len; 807 return len;
790} 808}
791 809
792static void print_jump(uint64_t ip, struct branch_entry *en, 810static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
793 struct perf_insn *x, u8 *inbuf, int len, 811 struct perf_insn *x, u8 *inbuf, int len,
794 int insn) 812 int insn, FILE *fp)
795{ 813{
796 printf("\t%016" PRIx64 "\t%-30s\t#%s%s%s%s", 814 int printed = fprintf(fp, "\t%016" PRIx64 "\t%-30s\t#%s%s%s%s", ip,
797 ip, 815 dump_insn(x, ip, inbuf, len, NULL),
798 dump_insn(x, ip, inbuf, len, NULL), 816 en->flags.predicted ? " PRED" : "",
799 en->flags.predicted ? " PRED" : "", 817 en->flags.mispred ? " MISPRED" : "",
800 en->flags.mispred ? " MISPRED" : "", 818 en->flags.in_tx ? " INTX" : "",
801 en->flags.in_tx ? " INTX" : "", 819 en->flags.abort ? " ABORT" : "");
802 en->flags.abort ? " ABORT" : "");
803 if (en->flags.cycles) { 820 if (en->flags.cycles) {
804 printf(" %d cycles", en->flags.cycles); 821 printed += fprintf(fp, " %d cycles", en->flags.cycles);
805 if (insn) 822 if (insn)
806 printf(" %.2f IPC", (float)insn / en->flags.cycles); 823 printed += fprintf(fp, " %.2f IPC", (float)insn / en->flags.cycles);
807 } 824 }
808 putchar('\n'); 825 return printed + fprintf(fp, "\n");
809} 826}
810 827
811static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu, 828static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
812 uint64_t addr, struct symbol **lastsym, 829 u8 cpumode, int cpu, struct symbol **lastsym,
813 struct perf_event_attr *attr) 830 struct perf_event_attr *attr, FILE *fp)
814{ 831{
815 struct addr_location al; 832 struct addr_location al;
816 int off; 833 int off, printed = 0;
817 834
818 memset(&al, 0, sizeof(al)); 835 memset(&al, 0, sizeof(al));
819 836
@@ -822,7 +839,7 @@ static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu,
822 thread__find_addr_map(thread, cpumode, MAP__VARIABLE, 839 thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
823 addr, &al); 840 addr, &al);
824 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) 841 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
825 return; 842 return 0;
826 843
827 al.cpu = cpu; 844 al.cpu = cpu;
828 al.sym = NULL; 845 al.sym = NULL;
@@ -830,37 +847,39 @@ static void print_ip_sym(struct thread *thread, u8 cpumode, int cpu,
830 al.sym = map__find_symbol(al.map, al.addr); 847 al.sym = map__find_symbol(al.map, al.addr);
831 848
832 if (!al.sym) 849 if (!al.sym)
833 return; 850 return 0;
834 851
835 if (al.addr < al.sym->end) 852 if (al.addr < al.sym->end)
836 off = al.addr - al.sym->start; 853 off = al.addr - al.sym->start;
837 else 854 else
838 off = al.addr - al.map->start - al.sym->start; 855 off = al.addr - al.map->start - al.sym->start;
839 printf("\t%s", al.sym->name); 856 printed += fprintf(fp, "\t%s", al.sym->name);
840 if (off) 857 if (off)
841 printf("%+d", off); 858 printed += fprintf(fp, "%+d", off);
842 putchar(':'); 859 printed += fprintf(fp, ":");
843 if (PRINT_FIELD(SRCLINE)) 860 if (PRINT_FIELD(SRCLINE))
844 map__fprintf_srcline(al.map, al.addr, "\t", stdout); 861 printed += map__fprintf_srcline(al.map, al.addr, "\t", fp);
845 putchar('\n'); 862 printed += fprintf(fp, "\n");
846 *lastsym = al.sym; 863 *lastsym = al.sym;
864
865 return printed;
847} 866}
848 867
849static void print_sample_brstackinsn(struct perf_sample *sample, 868static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
850 struct thread *thread, 869 struct thread *thread,
851 struct perf_event_attr *attr, 870 struct perf_event_attr *attr,
852 struct machine *machine) 871 struct machine *machine, FILE *fp)
853{ 872{
854 struct branch_stack *br = sample->branch_stack; 873 struct branch_stack *br = sample->branch_stack;
855 u64 start, end; 874 u64 start, end;
856 int i, insn, len, nr, ilen; 875 int i, insn, len, nr, ilen, printed = 0;
857 struct perf_insn x; 876 struct perf_insn x;
858 u8 buffer[MAXBB]; 877 u8 buffer[MAXBB];
859 unsigned off; 878 unsigned off;
860 struct symbol *lastsym = NULL; 879 struct symbol *lastsym = NULL;
861 880
862 if (!(br && br->nr)) 881 if (!(br && br->nr))
863 return; 882 return 0;
864 nr = br->nr; 883 nr = br->nr;
865 if (max_blocks && nr > max_blocks + 1) 884 if (max_blocks && nr > max_blocks + 1)
866 nr = max_blocks + 1; 885 nr = max_blocks + 1;
@@ -868,17 +887,17 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
868 x.thread = thread; 887 x.thread = thread;
869 x.cpu = sample->cpu; 888 x.cpu = sample->cpu;
870 889
871 putchar('\n'); 890 printed += fprintf(fp, "%c", '\n');
872 891
873 /* Handle first from jump, of which we don't know the entry. */ 892 /* Handle first from jump, of which we don't know the entry. */
874 len = grab_bb(buffer, br->entries[nr-1].from, 893 len = grab_bb(buffer, br->entries[nr-1].from,
875 br->entries[nr-1].from, 894 br->entries[nr-1].from,
876 machine, thread, &x.is64bit, &x.cpumode, false); 895 machine, thread, &x.is64bit, &x.cpumode, false);
877 if (len > 0) { 896 if (len > 0) {
878 print_ip_sym(thread, x.cpumode, x.cpu, 897 printed += ip__fprintf_sym(br->entries[nr - 1].from, thread,
879 br->entries[nr - 1].from, &lastsym, attr); 898 x.cpumode, x.cpu, &lastsym, attr, fp);
880 print_jump(br->entries[nr - 1].from, &br->entries[nr - 1], 899 printed += ip__fprintf_jump(br->entries[nr - 1].from, &br->entries[nr - 1],
881 &x, buffer, len, 0); 900 &x, buffer, len, 0, fp);
882 } 901 }
883 902
884 /* Print all blocks */ 903 /* Print all blocks */
@@ -904,13 +923,13 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
904 for (off = 0;; off += ilen) { 923 for (off = 0;; off += ilen) {
905 uint64_t ip = start + off; 924 uint64_t ip = start + off;
906 925
907 print_ip_sym(thread, x.cpumode, x.cpu, ip, &lastsym, attr); 926 printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
908 if (ip == end) { 927 if (ip == end) {
909 print_jump(ip, &br->entries[i], &x, buffer + off, len - off, insn); 928 printed += ip__fprintf_jump(ip, &br->entries[i], &x, buffer + off, len - off, insn, fp);
910 break; 929 break;
911 } else { 930 } else {
912 printf("\t%016" PRIx64 "\t%s\n", ip, 931 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", ip,
913 dump_insn(&x, ip, buffer + off, len - off, &ilen)); 932 dump_insn(&x, ip, buffer + off, len - off, &ilen));
914 if (ilen == 0) 933 if (ilen == 0)
915 break; 934 break;
916 insn++; 935 insn++;
@@ -923,9 +942,9 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
923 * has not been executed yet. 942 * has not been executed yet.
924 */ 943 */
925 if (br->entries[0].from == sample->ip) 944 if (br->entries[0].from == sample->ip)
926 return; 945 goto out;
927 if (br->entries[0].flags.abort) 946 if (br->entries[0].flags.abort)
928 return; 947 goto out;
929 948
930 /* 949 /*
931 * Print final block upto sample 950 * Print final block upto sample
@@ -933,58 +952,61 @@ static void print_sample_brstackinsn(struct perf_sample *sample,
933 start = br->entries[0].to; 952 start = br->entries[0].to;
934 end = sample->ip; 953 end = sample->ip;
935 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true); 954 len = grab_bb(buffer, start, end, machine, thread, &x.is64bit, &x.cpumode, true);
936 print_ip_sym(thread, x.cpumode, x.cpu, start, &lastsym, attr); 955 printed += ip__fprintf_sym(start, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
937 if (len <= 0) { 956 if (len <= 0) {
938 /* Print at least last IP if basic block did not work */ 957 /* Print at least last IP if basic block did not work */
939 len = grab_bb(buffer, sample->ip, sample->ip, 958 len = grab_bb(buffer, sample->ip, sample->ip,
940 machine, thread, &x.is64bit, &x.cpumode, false); 959 machine, thread, &x.is64bit, &x.cpumode, false);
941 if (len <= 0) 960 if (len <= 0)
942 return; 961 goto out;
943 962
944 printf("\t%016" PRIx64 "\t%s\n", sample->ip, 963 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", sample->ip,
945 dump_insn(&x, sample->ip, buffer, len, NULL)); 964 dump_insn(&x, sample->ip, buffer, len, NULL));
946 return; 965 goto out;
947 } 966 }
948 for (off = 0; off <= end - start; off += ilen) { 967 for (off = 0; off <= end - start; off += ilen) {
949 printf("\t%016" PRIx64 "\t%s\n", start + off, 968 printed += fprintf(fp, "\t%016" PRIx64 "\t%s\n", start + off,
950 dump_insn(&x, start + off, buffer + off, len - off, &ilen)); 969 dump_insn(&x, start + off, buffer + off, len - off, &ilen));
951 if (ilen == 0) 970 if (ilen == 0)
952 break; 971 break;
953 } 972 }
973out:
974 return printed;
954} 975}
955 976
956static void print_sample_addr(struct perf_sample *sample, 977static int perf_sample__fprintf_addr(struct perf_sample *sample,
957 struct thread *thread, 978 struct thread *thread,
958 struct perf_event_attr *attr) 979 struct perf_event_attr *attr, FILE *fp)
959{ 980{
960 struct addr_location al; 981 struct addr_location al;
961 982 int printed = fprintf(fp, "%16" PRIx64, sample->addr);
962 printf("%16" PRIx64, sample->addr);
963 983
964 if (!sample_addr_correlates_sym(attr)) 984 if (!sample_addr_correlates_sym(attr))
965 return; 985 goto out;
966 986
967 thread__resolve(thread, &al, sample); 987 thread__resolve(thread, &al, sample);
968 988
969 if (PRINT_FIELD(SYM)) { 989 if (PRINT_FIELD(SYM)) {
970 printf(" "); 990 printed += fprintf(fp, " ");
971 if (PRINT_FIELD(SYMOFFSET)) 991 if (PRINT_FIELD(SYMOFFSET))
972 symbol__fprintf_symname_offs(al.sym, &al, stdout); 992 printed += symbol__fprintf_symname_offs(al.sym, &al, fp);
973 else 993 else
974 symbol__fprintf_symname(al.sym, stdout); 994 printed += symbol__fprintf_symname(al.sym, fp);
975 } 995 }
976 996
977 if (PRINT_FIELD(DSO)) { 997 if (PRINT_FIELD(DSO)) {
978 printf(" ("); 998 printed += fprintf(fp, " (");
979 map__fprintf_dsoname(al.map, stdout); 999 printed += map__fprintf_dsoname(al.map, fp);
980 printf(")"); 1000 printed += fprintf(fp, ")");
981 } 1001 }
1002out:
1003 return printed;
982} 1004}
983 1005
984static void print_sample_callindent(struct perf_sample *sample, 1006static int perf_sample__fprintf_callindent(struct perf_sample *sample,
985 struct perf_evsel *evsel, 1007 struct perf_evsel *evsel,
986 struct thread *thread, 1008 struct thread *thread,
987 struct addr_location *al) 1009 struct addr_location *al, FILE *fp)
988{ 1010{
989 struct perf_event_attr *attr = &evsel->attr; 1011 struct perf_event_attr *attr = &evsel->attr;
990 size_t depth = thread_stack__depth(thread); 1012 size_t depth = thread_stack__depth(thread);
@@ -1019,12 +1041,12 @@ static void print_sample_callindent(struct perf_sample *sample,
1019 } 1041 }
1020 1042
1021 if (name) 1043 if (name)
1022 len = printf("%*s%s", (int)depth * 4, "", name); 1044 len = fprintf(fp, "%*s%s", (int)depth * 4, "", name);
1023 else if (ip) 1045 else if (ip)
1024 len = printf("%*s%16" PRIx64, (int)depth * 4, "", ip); 1046 len = fprintf(fp, "%*s%16" PRIx64, (int)depth * 4, "", ip);
1025 1047
1026 if (len < 0) 1048 if (len < 0)
1027 return; 1049 return len;
1028 1050
1029 /* 1051 /*
1030 * Try to keep the output length from changing frequently so that the 1052 * Try to keep the output length from changing frequently so that the
@@ -1034,39 +1056,46 @@ static void print_sample_callindent(struct perf_sample *sample,
1034 spacing = round_up(len + 4, 32); 1056 spacing = round_up(len + 4, 32);
1035 1057
1036 if (len < spacing) 1058 if (len < spacing)
1037 printf("%*s", spacing - len, ""); 1059 len += fprintf(fp, "%*s", spacing - len, "");
1060
1061 return len;
1038} 1062}
1039 1063
1040static void print_insn(struct perf_sample *sample, 1064static int perf_sample__fprintf_insn(struct perf_sample *sample,
1041 struct perf_event_attr *attr, 1065 struct perf_event_attr *attr,
1042 struct thread *thread, 1066 struct thread *thread,
1043 struct machine *machine) 1067 struct machine *machine, FILE *fp)
1044{ 1068{
1069 int printed = 0;
1070
1045 if (PRINT_FIELD(INSNLEN)) 1071 if (PRINT_FIELD(INSNLEN))
1046 printf(" ilen: %d", sample->insn_len); 1072 printed += fprintf(fp, " ilen: %d", sample->insn_len);
1047 if (PRINT_FIELD(INSN)) { 1073 if (PRINT_FIELD(INSN)) {
1048 int i; 1074 int i;
1049 1075
1050 printf(" insn:"); 1076 printed += fprintf(fp, " insn:");
1051 for (i = 0; i < sample->insn_len; i++) 1077 for (i = 0; i < sample->insn_len; i++)
1052 printf(" %02x", (unsigned char)sample->insn[i]); 1078 printed += fprintf(fp, " %02x", (unsigned char)sample->insn[i]);
1053 } 1079 }
1054 if (PRINT_FIELD(BRSTACKINSN)) 1080 if (PRINT_FIELD(BRSTACKINSN))
1055 print_sample_brstackinsn(sample, thread, attr, machine); 1081 printed += perf_sample__fprintf_brstackinsn(sample, thread, attr, machine, fp);
1082
1083 return printed;
1056} 1084}
1057 1085
1058static void print_sample_bts(struct perf_sample *sample, 1086static int perf_sample__fprintf_bts(struct perf_sample *sample,
1059 struct perf_evsel *evsel, 1087 struct perf_evsel *evsel,
1060 struct thread *thread, 1088 struct thread *thread,
1061 struct addr_location *al, 1089 struct addr_location *al,
1062 struct machine *machine) 1090 struct machine *machine, FILE *fp)
1063{ 1091{
1064 struct perf_event_attr *attr = &evsel->attr; 1092 struct perf_event_attr *attr = &evsel->attr;
1065 unsigned int type = output_type(attr->type); 1093 unsigned int type = output_type(attr->type);
1066 bool print_srcline_last = false; 1094 bool print_srcline_last = false;
1095 int printed = 0;
1067 1096
1068 if (PRINT_FIELD(CALLINDENT)) 1097 if (PRINT_FIELD(CALLINDENT))
1069 print_sample_callindent(sample, evsel, thread, al); 1098 printed += perf_sample__fprintf_callindent(sample, evsel, thread, al, fp);
1070 1099
1071 /* print branch_from information */ 1100 /* print branch_from information */
1072 if (PRINT_FIELD(IP)) { 1101 if (PRINT_FIELD(IP)) {
@@ -1079,31 +1108,30 @@ static void print_sample_bts(struct perf_sample *sample,
1079 cursor = &callchain_cursor; 1108 cursor = &callchain_cursor;
1080 1109
1081 if (cursor == NULL) { 1110 if (cursor == NULL) {
1082 putchar(' '); 1111 printed += fprintf(fp, " ");
1083 if (print_opts & EVSEL__PRINT_SRCLINE) { 1112 if (print_opts & EVSEL__PRINT_SRCLINE) {
1084 print_srcline_last = true; 1113 print_srcline_last = true;
1085 print_opts &= ~EVSEL__PRINT_SRCLINE; 1114 print_opts &= ~EVSEL__PRINT_SRCLINE;
1086 } 1115 }
1087 } else 1116 } else
1088 putchar('\n'); 1117 printed += fprintf(fp, "\n");
1089 1118
1090 sample__fprintf_sym(sample, al, 0, print_opts, cursor, stdout); 1119 printed += sample__fprintf_sym(sample, al, 0, print_opts, cursor, fp);
1091 } 1120 }
1092 1121
1093 /* print branch_to information */ 1122 /* print branch_to information */
1094 if (PRINT_FIELD(ADDR) || 1123 if (PRINT_FIELD(ADDR) ||
1095 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) && 1124 ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
1096 !output[type].user_set)) { 1125 !output[type].user_set)) {
1097 printf(" => "); 1126 printed += fprintf(fp, " => ");
1098 print_sample_addr(sample, thread, attr); 1127 printed += perf_sample__fprintf_addr(sample, thread, attr, fp);
1099 } 1128 }
1100 1129
1101 if (print_srcline_last) 1130 if (print_srcline_last)
1102 map__fprintf_srcline(al->map, al->addr, "\n ", stdout); 1131 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);
1103
1104 print_insn(sample, attr, thread, machine);
1105 1132
1106 printf("\n"); 1133 printed += perf_sample__fprintf_insn(sample, attr, thread, machine, fp);
1134 return printed + fprintf(fp, "\n");
1107} 1135}
1108 1136
1109static struct { 1137static struct {
@@ -1126,7 +1154,7 @@ static struct {
1126 {0, NULL} 1154 {0, NULL}
1127}; 1155};
1128 1156
1129static void print_sample_flags(u32 flags) 1157static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
1130{ 1158{
1131 const char *chars = PERF_IP_FLAG_CHARS; 1159 const char *chars = PERF_IP_FLAG_CHARS;
1132 const int n = strlen(PERF_IP_FLAG_CHARS); 1160 const int n = strlen(PERF_IP_FLAG_CHARS);
@@ -1153,9 +1181,9 @@ static void print_sample_flags(u32 flags)
1153 str[pos] = 0; 1181 str[pos] = 0;
1154 1182
1155 if (name) 1183 if (name)
1156 printf(" %-7s%4s ", name, in_tx ? "(x)" : ""); 1184 return fprintf(fp, " %-7s%4s ", name, in_tx ? "(x)" : "");
1157 else 1185
1158 printf(" %-11s ", str); 1186 return fprintf(fp, " %-11s ", str);
1159} 1187}
1160 1188
1161struct printer_data { 1189struct printer_data {
@@ -1225,138 +1253,136 @@ static int sample__fprintf_bpf_output(enum binary_printer_ops op,
1225 return printed; 1253 return printed;
1226} 1254}
1227 1255
1228static void print_sample_bpf_output(struct perf_sample *sample) 1256static int perf_sample__fprintf_bpf_output(struct perf_sample *sample, FILE *fp)
1229{ 1257{
1230 unsigned int nr_bytes = sample->raw_size; 1258 unsigned int nr_bytes = sample->raw_size;
1231 struct printer_data printer_data = {0, false, true}; 1259 struct printer_data printer_data = {0, false, true};
1232 1260 int printed = binary__fprintf(sample->raw_data, nr_bytes, 8,
1233 print_binary(sample->raw_data, nr_bytes, 8, 1261 sample__fprintf_bpf_output, &printer_data, fp);
1234 sample__fprintf_bpf_output, &printer_data);
1235 1262
1236 if (printer_data.is_printable && printer_data.hit_nul) 1263 if (printer_data.is_printable && printer_data.hit_nul)
1237 printf("%17s \"%s\"\n", "BPF string:", 1264 printed += fprintf(fp, "%17s \"%s\"\n", "BPF string:", (char *)(sample->raw_data));
1238 (char *)(sample->raw_data)); 1265
1266 return printed;
1239} 1267}
1240 1268
1241static void print_sample_spacing(int len, int spacing) 1269static int perf_sample__fprintf_spacing(int len, int spacing, FILE *fp)
1242{ 1270{
1243 if (len > 0 && len < spacing) 1271 if (len > 0 && len < spacing)
1244 printf("%*s", spacing - len, ""); 1272 return fprintf(fp, "%*s", spacing - len, "");
1273
1274 return 0;
1245} 1275}
1246 1276
1247static void print_sample_pt_spacing(int len) 1277static int perf_sample__fprintf_pt_spacing(int len, FILE *fp)
1248{ 1278{
1249 print_sample_spacing(len, 34); 1279 return perf_sample__fprintf_spacing(len, 34, fp);
1250} 1280}
1251 1281
1252static void print_sample_synth_ptwrite(struct perf_sample *sample) 1282static int perf_sample__fprintf_synth_ptwrite(struct perf_sample *sample, FILE *fp)
1253{ 1283{
1254 struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample); 1284 struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample);
1255 int len; 1285 int len;
1256 1286
1257 if (perf_sample__bad_synth_size(sample, *data)) 1287 if (perf_sample__bad_synth_size(sample, *data))
1258 return; 1288 return 0;
1259 1289
1260 len = printf(" IP: %u payload: %#" PRIx64 " ", 1290 len = fprintf(fp, " IP: %u payload: %#" PRIx64 " ",
1261 data->ip, le64_to_cpu(data->payload)); 1291 data->ip, le64_to_cpu(data->payload));
1262 print_sample_pt_spacing(len); 1292 return len + perf_sample__fprintf_pt_spacing(len, fp);
1263} 1293}
1264 1294
1265static void print_sample_synth_mwait(struct perf_sample *sample) 1295static int perf_sample__fprintf_synth_mwait(struct perf_sample *sample, FILE *fp)
1266{ 1296{
1267 struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample); 1297 struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample);
1268 int len; 1298 int len;
1269 1299
1270 if (perf_sample__bad_synth_size(sample, *data)) 1300 if (perf_sample__bad_synth_size(sample, *data))
1271 return; 1301 return 0;
1272 1302
1273 len = printf(" hints: %#x extensions: %#x ", 1303 len = fprintf(fp, " hints: %#x extensions: %#x ",
1274 data->hints, data->extensions); 1304 data->hints, data->extensions);
1275 print_sample_pt_spacing(len); 1305 return len + perf_sample__fprintf_pt_spacing(len, fp);
1276} 1306}
1277 1307
1278static void print_sample_synth_pwre(struct perf_sample *sample) 1308static int perf_sample__fprintf_synth_pwre(struct perf_sample *sample, FILE *fp)
1279{ 1309{
1280 struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample); 1310 struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample);
1281 int len; 1311 int len;
1282 1312
1283 if (perf_sample__bad_synth_size(sample, *data)) 1313 if (perf_sample__bad_synth_size(sample, *data))
1284 return; 1314 return 0;
1285 1315
1286 len = printf(" hw: %u cstate: %u sub-cstate: %u ", 1316 len = fprintf(fp, " hw: %u cstate: %u sub-cstate: %u ",
1287 data->hw, data->cstate, data->subcstate); 1317 data->hw, data->cstate, data->subcstate);
1288 print_sample_pt_spacing(len); 1318 return len + perf_sample__fprintf_pt_spacing(len, fp);
1289} 1319}
1290 1320
1291static void print_sample_synth_exstop(struct perf_sample *sample) 1321static int perf_sample__fprintf_synth_exstop(struct perf_sample *sample, FILE *fp)
1292{ 1322{
1293 struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample); 1323 struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample);
1294 int len; 1324 int len;
1295 1325
1296 if (perf_sample__bad_synth_size(sample, *data)) 1326 if (perf_sample__bad_synth_size(sample, *data))
1297 return; 1327 return 0;
1298 1328
1299 len = printf(" IP: %u ", data->ip); 1329 len = fprintf(fp, " IP: %u ", data->ip);
1300 print_sample_pt_spacing(len); 1330 return len + perf_sample__fprintf_pt_spacing(len, fp);
1301} 1331}
1302 1332
1303static void print_sample_synth_pwrx(struct perf_sample *sample) 1333static int perf_sample__fprintf_synth_pwrx(struct perf_sample *sample, FILE *fp)
1304{ 1334{
1305 struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample); 1335 struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample);
1306 int len; 1336 int len;
1307 1337
1308 if (perf_sample__bad_synth_size(sample, *data)) 1338 if (perf_sample__bad_synth_size(sample, *data))
1309 return; 1339 return 0;
1310 1340
1311 len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ", 1341 len = fprintf(fp, " deepest cstate: %u last cstate: %u wake reason: %#x ",
1312 data->deepest_cstate, data->last_cstate, 1342 data->deepest_cstate, data->last_cstate,
1313 data->wake_reason); 1343 data->wake_reason);
1314 print_sample_pt_spacing(len); 1344 return len + perf_sample__fprintf_pt_spacing(len, fp);
1315} 1345}
1316 1346
1317static void print_sample_synth_cbr(struct perf_sample *sample) 1347static int perf_sample__fprintf_synth_cbr(struct perf_sample *sample, FILE *fp)
1318{ 1348{
1319 struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample); 1349 struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample);
1320 unsigned int percent, freq; 1350 unsigned int percent, freq;
1321 int len; 1351 int len;
1322 1352
1323 if (perf_sample__bad_synth_size(sample, *data)) 1353 if (perf_sample__bad_synth_size(sample, *data))
1324 return; 1354 return 0;
1325 1355
1326 freq = (le32_to_cpu(data->freq) + 500) / 1000; 1356 freq = (le32_to_cpu(data->freq) + 500) / 1000;
1327 len = printf(" cbr: %2u freq: %4u MHz ", data->cbr, freq); 1357 len = fprintf(fp, " cbr: %2u freq: %4u MHz ", data->cbr, freq);
1328 if (data->max_nonturbo) { 1358 if (data->max_nonturbo) {
1329 percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10; 1359 percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10;
1330 len += printf("(%3u%%) ", percent); 1360 len += fprintf(fp, "(%3u%%) ", percent);
1331 } 1361 }
1332 print_sample_pt_spacing(len); 1362 return len + perf_sample__fprintf_pt_spacing(len, fp);
1333} 1363}
1334 1364
1335static void print_sample_synth(struct perf_sample *sample, 1365static int perf_sample__fprintf_synth(struct perf_sample *sample,
1336 struct perf_evsel *evsel) 1366 struct perf_evsel *evsel, FILE *fp)
1337{ 1367{
1338 switch (evsel->attr.config) { 1368 switch (evsel->attr.config) {
1339 case PERF_SYNTH_INTEL_PTWRITE: 1369 case PERF_SYNTH_INTEL_PTWRITE:
1340 print_sample_synth_ptwrite(sample); 1370 return perf_sample__fprintf_synth_ptwrite(sample, fp);
1341 break;
1342 case PERF_SYNTH_INTEL_MWAIT: 1371 case PERF_SYNTH_INTEL_MWAIT:
1343 print_sample_synth_mwait(sample); 1372 return perf_sample__fprintf_synth_mwait(sample, fp);
1344 break;
1345 case PERF_SYNTH_INTEL_PWRE: 1373 case PERF_SYNTH_INTEL_PWRE:
1346 print_sample_synth_pwre(sample); 1374 return perf_sample__fprintf_synth_pwre(sample, fp);
1347 break;
1348 case PERF_SYNTH_INTEL_EXSTOP: 1375 case PERF_SYNTH_INTEL_EXSTOP:
1349 print_sample_synth_exstop(sample); 1376 return perf_sample__fprintf_synth_exstop(sample, fp);
1350 break;
1351 case PERF_SYNTH_INTEL_PWRX: 1377 case PERF_SYNTH_INTEL_PWRX:
1352 print_sample_synth_pwrx(sample); 1378 return perf_sample__fprintf_synth_pwrx(sample, fp);
1353 break;
1354 case PERF_SYNTH_INTEL_CBR: 1379 case PERF_SYNTH_INTEL_CBR:
1355 print_sample_synth_cbr(sample); 1380 return perf_sample__fprintf_synth_cbr(sample, fp);
1356 break;
1357 default: 1381 default:
1358 break; 1382 break;
1359 } 1383 }
1384
1385 return 0;
1360} 1386}
1361 1387
1362struct perf_script { 1388struct perf_script {
@@ -1388,7 +1414,7 @@ static int perf_evlist__max_name_len(struct perf_evlist *evlist)
1388 return max; 1414 return max;
1389} 1415}
1390 1416
1391static size_t data_src__printf(u64 data_src) 1417static int data_src__fprintf(u64 data_src, FILE *fp)
1392{ 1418{
1393 struct mem_info mi = { .data_src.val = data_src }; 1419 struct mem_info mi = { .data_src.val = data_src };
1394 char decode[100]; 1420 char decode[100];
@@ -1402,7 +1428,7 @@ static size_t data_src__printf(u64 data_src)
1402 if (maxlen < len) 1428 if (maxlen < len)
1403 maxlen = len; 1429 maxlen = len;
1404 1430
1405 return printf("%-*s", maxlen, out); 1431 return fprintf(fp, "%-*s", maxlen, out);
1406} 1432}
1407 1433
1408static void process_event(struct perf_script *script, 1434static void process_event(struct perf_script *script,
@@ -1413,11 +1439,12 @@ static void process_event(struct perf_script *script,
1413 struct thread *thread = al->thread; 1439 struct thread *thread = al->thread;
1414 struct perf_event_attr *attr = &evsel->attr; 1440 struct perf_event_attr *attr = &evsel->attr;
1415 unsigned int type = output_type(attr->type); 1441 unsigned int type = output_type(attr->type);
1442 FILE *fp = stdout;
1416 1443
1417 if (output[type].fields == 0) 1444 if (output[type].fields == 0)
1418 return; 1445 return;
1419 1446
1420 print_sample_start(sample, thread, evsel); 1447 perf_sample__fprintf_start(sample, thread, evsel, fp);
1421 1448
1422 if (PRINT_FIELD(PERIOD)) 1449 if (PRINT_FIELD(PERIOD))
1423 printf("%10" PRIu64 " ", sample->period); 1450 printf("%10" PRIu64 " ", sample->period);
@@ -1433,10 +1460,10 @@ static void process_event(struct perf_script *script,
1433 } 1460 }
1434 1461
1435 if (print_flags) 1462 if (print_flags)
1436 print_sample_flags(sample->flags); 1463 perf_sample__fprintf_flags(sample->flags, fp);
1437 1464
1438 if (is_bts_event(attr)) { 1465 if (is_bts_event(attr)) {
1439 print_sample_bts(sample, evsel, thread, al, machine); 1466 perf_sample__fprintf_bts(sample, evsel, thread, al, machine, fp);
1440 return; 1467 return;
1441 } 1468 }
1442 1469
@@ -1445,16 +1472,16 @@ static void process_event(struct perf_script *script,
1445 sample->raw_data, sample->raw_size); 1472 sample->raw_data, sample->raw_size);
1446 1473
1447 if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH)) 1474 if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
1448 print_sample_synth(sample, evsel); 1475 perf_sample__fprintf_synth(sample, evsel, fp);
1449 1476
1450 if (PRINT_FIELD(ADDR)) 1477 if (PRINT_FIELD(ADDR))
1451 print_sample_addr(sample, thread, attr); 1478 perf_sample__fprintf_addr(sample, thread, attr, fp);
1452 1479
1453 if (PRINT_FIELD(DATA_SRC)) 1480 if (PRINT_FIELD(DATA_SRC))
1454 data_src__printf(sample->data_src); 1481 data_src__fprintf(sample->data_src, fp);
1455 1482
1456 if (PRINT_FIELD(WEIGHT)) 1483 if (PRINT_FIELD(WEIGHT))
1457 printf("%16" PRIu64, sample->weight); 1484 fprintf(fp, "%16" PRIu64, sample->weight);
1458 1485
1459 if (PRINT_FIELD(IP)) { 1486 if (PRINT_FIELD(IP)) {
1460 struct callchain_cursor *cursor = NULL; 1487 struct callchain_cursor *cursor = NULL;
@@ -1464,26 +1491,26 @@ static void process_event(struct perf_script *script,
1464 sample, NULL, NULL, scripting_max_stack) == 0) 1491 sample, NULL, NULL, scripting_max_stack) == 0)
1465 cursor = &callchain_cursor; 1492 cursor = &callchain_cursor;
1466 1493
1467 putchar(cursor ? '\n' : ' '); 1494 fputc(cursor ? '\n' : ' ', fp);
1468 sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, stdout); 1495 sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, fp);
1469 } 1496 }
1470 1497
1471 if (PRINT_FIELD(IREGS)) 1498 if (PRINT_FIELD(IREGS))
1472 print_sample_iregs(sample, attr); 1499 perf_sample__fprintf_iregs(sample, attr, fp);
1473 1500
1474 if (PRINT_FIELD(UREGS)) 1501 if (PRINT_FIELD(UREGS))
1475 print_sample_uregs(sample, attr); 1502 perf_sample__fprintf_uregs(sample, attr, fp);
1476 1503
1477 if (PRINT_FIELD(BRSTACK)) 1504 if (PRINT_FIELD(BRSTACK))
1478 print_sample_brstack(sample, thread, attr); 1505 perf_sample__fprintf_brstack(sample, thread, attr, fp);
1479 else if (PRINT_FIELD(BRSTACKSYM)) 1506 else if (PRINT_FIELD(BRSTACKSYM))
1480 print_sample_brstacksym(sample, thread, attr); 1507 perf_sample__fprintf_brstacksym(sample, thread, attr, fp);
1481 else if (PRINT_FIELD(BRSTACKOFF)) 1508 else if (PRINT_FIELD(BRSTACKOFF))
1482 print_sample_brstackoff(sample, thread, attr); 1509 perf_sample__fprintf_brstackoff(sample, thread, attr, fp);
1483 1510
1484 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) 1511 if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
1485 print_sample_bpf_output(sample); 1512 perf_sample__fprintf_bpf_output(sample, fp);
1486 print_insn(sample, attr, thread, machine); 1513 perf_sample__fprintf_insn(sample, attr, thread, machine, fp);
1487 1514
1488 if (PRINT_FIELD(PHYS_ADDR)) 1515 if (PRINT_FIELD(PHYS_ADDR))
1489 printf("%16" PRIx64, sample->phys_addr); 1516 printf("%16" PRIx64, sample->phys_addr);
@@ -1661,7 +1688,7 @@ static int process_comm_event(struct perf_tool *tool,
1661 sample->tid = event->comm.tid; 1688 sample->tid = event->comm.tid;
1662 sample->pid = event->comm.pid; 1689 sample->pid = event->comm.pid;
1663 } 1690 }
1664 print_sample_start(sample, thread, evsel); 1691 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1665 perf_event__fprintf(event, stdout); 1692 perf_event__fprintf(event, stdout);
1666 ret = 0; 1693 ret = 0;
1667out: 1694out:
@@ -1696,7 +1723,7 @@ static int process_namespaces_event(struct perf_tool *tool,
1696 sample->tid = event->namespaces.tid; 1723 sample->tid = event->namespaces.tid;
1697 sample->pid = event->namespaces.pid; 1724 sample->pid = event->namespaces.pid;
1698 } 1725 }
1699 print_sample_start(sample, thread, evsel); 1726 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1700 perf_event__fprintf(event, stdout); 1727 perf_event__fprintf(event, stdout);
1701 ret = 0; 1728 ret = 0;
1702out: 1729out:
@@ -1729,7 +1756,7 @@ static int process_fork_event(struct perf_tool *tool,
1729 sample->tid = event->fork.tid; 1756 sample->tid = event->fork.tid;
1730 sample->pid = event->fork.pid; 1757 sample->pid = event->fork.pid;
1731 } 1758 }
1732 print_sample_start(sample, thread, evsel); 1759 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1733 perf_event__fprintf(event, stdout); 1760 perf_event__fprintf(event, stdout);
1734 thread__put(thread); 1761 thread__put(thread);
1735 1762
@@ -1758,7 +1785,7 @@ static int process_exit_event(struct perf_tool *tool,
1758 sample->tid = event->fork.tid; 1785 sample->tid = event->fork.tid;
1759 sample->pid = event->fork.pid; 1786 sample->pid = event->fork.pid;
1760 } 1787 }
1761 print_sample_start(sample, thread, evsel); 1788 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1762 perf_event__fprintf(event, stdout); 1789 perf_event__fprintf(event, stdout);
1763 1790
1764 if (perf_event__process_exit(tool, event, sample, machine) < 0) 1791 if (perf_event__process_exit(tool, event, sample, machine) < 0)
@@ -1793,7 +1820,7 @@ static int process_mmap_event(struct perf_tool *tool,
1793 sample->tid = event->mmap.tid; 1820 sample->tid = event->mmap.tid;
1794 sample->pid = event->mmap.pid; 1821 sample->pid = event->mmap.pid;
1795 } 1822 }
1796 print_sample_start(sample, thread, evsel); 1823 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1797 perf_event__fprintf(event, stdout); 1824 perf_event__fprintf(event, stdout);
1798 thread__put(thread); 1825 thread__put(thread);
1799 return 0; 1826 return 0;
@@ -1824,7 +1851,7 @@ static int process_mmap2_event(struct perf_tool *tool,
1824 sample->tid = event->mmap2.tid; 1851 sample->tid = event->mmap2.tid;
1825 sample->pid = event->mmap2.pid; 1852 sample->pid = event->mmap2.pid;
1826 } 1853 }
1827 print_sample_start(sample, thread, evsel); 1854 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1828 perf_event__fprintf(event, stdout); 1855 perf_event__fprintf(event, stdout);
1829 thread__put(thread); 1856 thread__put(thread);
1830 return 0; 1857 return 0;
@@ -1850,7 +1877,7 @@ static int process_switch_event(struct perf_tool *tool,
1850 return -1; 1877 return -1;
1851 } 1878 }
1852 1879
1853 print_sample_start(sample, thread, evsel); 1880 perf_sample__fprintf_start(sample, thread, evsel, stdout);
1854 perf_event__fprintf(event, stdout); 1881 perf_event__fprintf(event, stdout);
1855 thread__put(thread); 1882 thread__put(thread);
1856 return 0; 1883 return 0;