Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts: get_abi.pl: show progress

As parsing the sysfs entries can take a long time, add
progress information.

The progress logic will update the stats on every second,
or on 1% steps of the progress.

When STDERR is a console, it will use a single line, using
a VT-100 command to erase the line before rewriting it.
Otherwise, it will put one message on a separate line.
That would help to identify what parts of sysfs checking
that it is taking more time to process.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/4e581dcbec21ad8a60fff883498018f96f13dd1c.1632823172.git.mchehab+huawei@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mauro Carvalho Chehab and committed by
Greg Kroah-Hartman
28331a01 2833e30a

+113 -60
+113 -60
scripts/get_abi.pl
··· 9 9 use Pod::Usage qw(pod2usage); 10 10 use Getopt::Long; 11 11 use File::Find; 12 + use IO::Handle; 12 13 use Fcntl ':mode'; 13 14 use Cwd 'abs_path'; 14 15 use Data::Dumper; ··· 703 702 return $leave; 704 703 } 705 704 706 - sub check_undefined_symbols { 707 - foreach my $file_ref (sort @files) { 708 - my @names = @{$$file_ref{"__name"}}; 709 - my $file = $names[0]; 705 + my @not_found; 710 706 711 - my $exact = 0; 712 - my $found_string; 707 + sub check_file($$) 708 + { 709 + my $file_ref = shift; 710 + my $names_ref = shift; 711 + my @names = @{$names_ref}; 712 + my $file = $names[0]; 713 713 714 - my $leave = get_leave($file); 715 - if (!defined($leaf{$leave})) { 716 - $leave = "others"; 717 - } 718 - my @expr = @{$leaf{$leave}->{expr}}; 719 - die ("missing rules for $leave") if (!defined($leaf{$leave})); 714 + my $found_string; 720 715 721 - my $path = $file; 722 - $path =~ s,(.*/).*,$1,; 716 + my $leave = get_leave($file); 717 + if (!defined($leaf{$leave})) { 718 + $leave = "others"; 719 + } 720 + my @expr = @{$leaf{$leave}->{expr}}; 721 + die ("\rmissing rules for $leave") if (!defined($leaf{$leave})); 723 722 724 - if ($search_string) { 725 - next if (!($file =~ m#$search_string#)); 726 - $found_string = 1; 727 - } 723 + my $path = $file; 724 + $path =~ s,(.*/).*,$1,; 728 725 729 - for (my $i = 0; $i < @names; $i++) { 730 - if ($found_string && $hint) { 731 - if (!$i) { 732 - print STDERR "--> $names[$i]\n"; 733 - } else { 734 - print STDERR " $names[$i]\n"; 735 - } 736 - } 737 - foreach my $re (@expr) { 738 - print "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); 739 - if ($names[$i] =~ $re) { 740 - $exact = 1; 741 - last; 742 - } 743 - } 744 - last if ($exact); 745 - } 746 - next if ($exact); 726 + if ($search_string) { 727 + return if (!($file =~ m#$search_string#)); 728 + $found_string = 1; 729 + } 747 730 748 - if ($leave ne "others") { 749 - my @expr = @{$leaf{$leave}->{expr}}; 750 - for (my $i = 0; $i < @names; $i++) { 751 - foreach my $re (@expr) { 752 - print "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); 753 - if ($names[$i] =~ $re) { 754 - $exact = 1; 755 - last; 756 - } 757 - } 758 - last if ($exact); 759 - } 760 - last if ($exact); 761 - } 762 - next if ($exact); 763 - 764 - print "$file not found.\n" if (!$search_string || $found_string); 765 - 766 - if ($hint && (!$search_string || $found_string)) { 767 - my $what = $leaf{$leave}->{what}; 768 - $what =~ s/\xac/\n\t/g; 769 - if ($leave ne "others") { 770 - print STDERR " more likely regexes:\n\t$what\n"; 731 + for (my $i = 0; $i < @names; $i++) { 732 + if ($found_string && $hint) { 733 + if (!$i) { 734 + print STDERR "--> $names[$i]\n"; 771 735 } else { 772 - print STDERR " tested regexes:\n\t$what\n"; 736 + print STDERR " $names[$i]\n"; 773 737 } 738 + } 739 + foreach my $re (@expr) { 740 + print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); 741 + if ($names[$i] =~ $re) { 742 + return; 743 + } 744 + } 745 + } 746 + 747 + if ($leave ne "others") { 748 + my @expr = @{$leaf{$leave}->{expr}}; 749 + for (my $i = 0; $i < @names; $i++) { 750 + foreach my $re (@expr) { 751 + print STDERR "$names[$i] =~ /^$re\$/\n" if ($debug && $dbg_undefined); 752 + if ($names[$i] =~ $re) { 753 + return; 754 + } 755 + } 756 + } 757 + } 758 + 759 + push @not_found, $file if (!$search_string || $found_string); 760 + 761 + if ($hint && (!$search_string || $found_string)) { 762 + my $what = $leaf{$leave}->{what}; 763 + $what =~ s/\xac/\n\t/g; 764 + if ($leave ne "others") { 765 + print STDERR "\r more likely regexes:\n\t$what\n"; 766 + } else { 767 + print STDERR "\r tested regexes:\n\t$what\n"; 774 768 } 775 769 } 776 770 } 777 771 772 + sub check_undefined_symbols { 773 + my $num_files = scalar @files; 774 + my $next_i = 0; 775 + my $start_time = times; 776 + 777 + my $last_time = $start_time; 778 + 779 + # When either debug or hint is enabled, there's no sense showing 780 + # progress, as the progress will be overriden. 781 + if ($hint || ($debug && $dbg_undefined)) { 782 + $next_i = $num_files; 783 + } 784 + 785 + my $is_console; 786 + $is_console = 1 if (-t STDERR); 787 + 788 + for (my $i = 0; $i < $num_files; $i++) { 789 + my $file_ref = $files[$i]; 790 + my @names = @{$$file_ref{"__name"}}; 791 + 792 + check_file($file_ref, \@names); 793 + 794 + my $cur_time = times; 795 + 796 + if ($i == $next_i || $cur_time > $last_time + 1) { 797 + my $percent = $i * 100 / $num_files; 798 + 799 + my $tm = $cur_time - $start_time; 800 + my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm)); 801 + 802 + printf STDERR "\33[2K\r", if ($is_console); 803 + printf STDERR "%s: processing sysfs files... %i%%: $names[0]", $time, $percent; 804 + printf STDERR "\n", if (!$is_console); 805 + STDERR->flush(); 806 + 807 + $next_i = int (($percent + 1) * $num_files / 100); 808 + $last_time = $cur_time; 809 + } 810 + } 811 + 812 + my $cur_time = times; 813 + my $tm = $cur_time - $start_time; 814 + my $time = sprintf "%d:%02d", int($tm), 60 * ($tm - int($tm)); 815 + 816 + printf STDERR "\33[2K\r", if ($is_console); 817 + printf STDERR "%s: processing sysfs files... done\n", $time; 818 + 819 + foreach my $file (@not_found) { 820 + print "$file not found.\n"; 821 + } 822 + } 823 + 778 824 sub undefined_symbols { 825 + print STDERR "Reading $sysfs_prefix directory contents..."; 779 826 find({ 780 827 wanted =>\&parse_existing_sysfs, 781 828 preprocess =>\&dont_parse_special_attributes, 782 829 no_chdir => 1 783 830 }, $sysfs_prefix); 831 + print STDERR "done.\n"; 784 832 785 833 $leaf{"others"}->{what} = ""; 786 834 835 + print STDERR "Converting ABI What fields into regexes..."; 787 836 foreach my $w (sort keys %data) { 788 837 foreach my $what (split /\xac/,$w) { 789 838 next if (!($what =~ m/^$sysfs_prefix/)); ··· 922 871 my $abs_file = $aliases{$link}; 923 872 graph_add_link($abs_file, $link); 924 873 } 874 + print STDERR "done.\n"; 875 + 925 876 check_undefined_symbols; 926 877 } 927 878