3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is Mozilla Corportation code.
18 # The Initial Developer of the Original Code is Mozilla Corporation.
19 # Portions created by the Initial Developer are Copyright (C) 2007
20 # the Initial Developer. All Rights Reserved.
23 # Robert O'Callahan <robert@ocallahan.org>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 # This script is a bunch of utilities for computing statistics about the textruns
40 # created during a Gecko run.
43 # 1) Uncomment #define DUMP_TEXT_RUNS in gfxAtsuiFonts.cpp
45 # 3) Run over some test set, redirecting stdout to a file
46 # 4) Pipe that file through this script
48 # --exclude-spaces-only: ignore all textruns that consistent of zero or more
50 my $exclude_spaces = grep(/^--exclude-spaces-only$/, @ARGV);
52 # --dump-runs: process textruns into a format that can be used by
53 # gfxTextRunPerfTest, print that on standard output, and do nothing else
54 my $dump_runs = grep(/^--dump-runs$/, @ARGV);
56 # --obfuscate: ROTL13 the textrun text
57 my $obfuscate = grep(/^--obfuscate$/, @ARGV);
62 if (/^0x(\w+)\((.*)\) TEXTRUN "(.*)" ENDTEXTRUN$/) {
63 my %tr = ( fontgroup
=> $1,
66 push(@textruns, \
%tr);
67 } elsif (/^0x(\w+)\((.*)\) TEXTRUN "(.*)$/) {
68 my %tr = ( fontgroup
=> $1,
72 if (/^(.*)" ENDTEXTRUN$/) {
79 push(@textruns, \
%tr);
83 my %quote = ( "\\" => 1, "\"" => 1 );
87 my @chars = split(//, $text);
89 foreach my $c (@chars) {
90 if (ord($c) >= 0x80) {
91 $c = "\\x".sprintf("%x",ord($c)).'""';
92 } elsif ($quote{$c}) {
94 } elsif ($c eq "\n") {
99 return '"'.join("", @strs).'"';
103 foreach my $tr (@textruns) {
104 print "{ ", "e_str
($tr->{families
}), ",\n";
105 my $text = $tr->{text
};
107 $text =~ tr/a-mA-Mn-zN-Z/n-zN-Za-mA-M/;
109 print " ", "e_str
($text), " },\n";
114 my %trs_by_text = ();
115 my %trs_by_text_and_fontgroup = ();
116 my %trs_by_trimmed_text_and_fontgroup = ();
119 $trs_by_text{" "} = [];
120 $trs_by_text{""} = [];
129 my $total_textruns = 0;
131 foreach my $tr (@textruns) {
132 if ($exclude_spaces && $tr->{text
} =~ /^ *$/) {
136 push(@
{$trs_by_text{$tr->{text
}}}, $tr);
137 push(@
{$trs_by_text_and_fontgroup{$tr->{fontgroup
}.$tr->{text
}}}, $tr);
138 push(@
{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup
}.&trim
($tr->{text
})}}, $tr);
139 if (1 < scalar(@
{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup
}.&trim
($tr->{text
})}})) {
140 $tr_lengths[length($tr->{text
})]++;
144 print "Number of textruns:\t$total_textruns\n";
145 print "Number of textruns which are one space:\t", scalar(@
{$trs_by_text{" "}}), "\n";
146 print "Number of textruns which are empty:\t", scalar(@
{$trs_by_text{""}}), "\n";
149 foreach my $k (keys(%trs_by_text)) {
151 $count += @
{$trs_by_text{$k}};
154 print "Number of textruns which are zero or more spaces:\t$count\n";
156 print "Number of unique textruns by text and fontgroup:\t", scalar(keys(%trs_by_text_and_fontgroup)), "\n";
157 print "Number of unique textruns by trimmed text and fontgroup:\t", scalar(keys(%trs_by_trimmed_text_and_fontgroup)), "\n";
160 my $weighted_sum = 0;
162 print "Textrun length distribution:\n";
163 for my $i (0..(scalar(@tr_lengths)-1)) {
164 my $amount = defined($tr_lengths[$i])?
$tr_lengths[$i]:0;
166 $weighted_sum += $i*$amount;
167 print "$i\t$sum\t$weighted_sum\n";