3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # This script is a bunch of utilities for computing statistics about the textruns
8 # created during a Gecko run.
11 # 1) Uncomment #define DUMP_TEXT_RUNS in gfxAtsuiFonts.cpp
13 # 3) Run over some test set, redirecting stdout to a file
14 # 4) Pipe that file through this script
16 # --exclude-spaces-only: ignore all textruns that consistent of zero or more
18 my $exclude_spaces = grep(/^--exclude-spaces-only$/, @ARGV);
20 # --dump-runs: process textruns into a format that can be used by
21 # gfxTextRunPerfTest, print that on standard output, and do nothing else
22 my $dump_runs = grep(/^--dump-runs$/, @ARGV);
24 # --obfuscate: ROTL13 the textrun text
25 my $obfuscate = grep(/^--obfuscate$/, @ARGV);
30 if (/^0x(\w+)\((.*)\) TEXTRUN "(.*)" ENDTEXTRUN$/) {
31 my %tr = ( fontgroup
=> $1,
34 push(@textruns, \
%tr);
35 } elsif (/^0x(\w+)\((.*)\) TEXTRUN "(.*)$/) {
36 my %tr = ( fontgroup
=> $1,
40 if (/^(.*)" ENDTEXTRUN$/) {
47 push(@textruns, \
%tr);
51 my %quote = ( "\\" => 1, "\"" => 1 );
55 my @chars = split(//, $text);
57 foreach my $c (@chars) {
58 if (ord($c) >= 0x80) {
59 $c = "\\x".sprintf("%x",ord($c)).'""';
60 } elsif ($quote{$c}) {
62 } elsif ($c eq "\n") {
67 return '"'.join("", @strs).'"';
71 foreach my $tr (@textruns) {
72 print "{ ", "e_str
($tr->{families
}), ",\n";
73 my $text = $tr->{text
};
75 $text =~ tr/a-mA-Mn-zN-Z/n-zN-Za-mA-M/;
77 print " ", "e_str
($text), " },\n";
83 my %trs_by_text_and_fontgroup = ();
84 my %trs_by_trimmed_text_and_fontgroup = ();
87 $trs_by_text{" "} = [];
88 $trs_by_text{""} = [];
97 my $total_textruns = 0;
99 foreach my $tr (@textruns) {
100 if ($exclude_spaces && $tr->{text
} =~ /^ *$/) {
104 push(@
{$trs_by_text{$tr->{text
}}}, $tr);
105 push(@
{$trs_by_text_and_fontgroup{$tr->{fontgroup
}.$tr->{text
}}}, $tr);
106 push(@
{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup
}.&trim
($tr->{text
})}}, $tr);
107 if (1 < scalar(@
{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup
}.&trim
($tr->{text
})}})) {
108 $tr_lengths[length($tr->{text
})]++;
112 print "Number of textruns:\t$total_textruns\n";
113 print "Number of textruns which are one space:\t", scalar(@
{$trs_by_text{" "}}), "\n";
114 print "Number of textruns which are empty:\t", scalar(@
{$trs_by_text{""}}), "\n";
117 foreach my $k (keys(%trs_by_text)) {
119 $count += @
{$trs_by_text{$k}};
122 print "Number of textruns which are zero or more spaces:\t$count\n";
124 print "Number of unique textruns by text and fontgroup:\t", scalar(keys(%trs_by_text_and_fontgroup)), "\n";
125 print "Number of unique textruns by trimmed text and fontgroup:\t", scalar(keys(%trs_by_trimmed_text_and_fontgroup)), "\n";
128 my $weighted_sum = 0;
130 print "Textrun length distribution:\n";
131 for my $i (0..(scalar(@tr_lengths)-1)) {
132 my $amount = defined($tr_lengths[$i])?
$tr_lengths[$i]:0;
134 $weighted_sum += $i*$amount;
135 print "$i\t$sum\t$weighted_sum\n";