[svn] / trunk / xvidcore / examples / bench.pl Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/examples/bench.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1614 - (view) (download) (as text)

1 : Skal 1614 #!/usr/bin/perl
2 :    
3 :     ###############################################################################
4 :     #
5 :     # XVID MPEG-4 VIDEO CODEC
6 :     # - Unit tests and benches -
7 :     #
8 :     # Copyright(C) 2005 Pascal Massimino <skal@planet-d.net>
9 :     #
10 :     # This program is free software; you can redistribute it and/or modify
11 :     # it under the terms of the GNU General Public License as published by
12 :     # the Free Software Foundation; either version 2 of the License, or
13 :     # (at your option) any later version.
14 :     #
15 :     # This program is distributed in the hope that it will be useful,
16 :     # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     # GNU General Public License for more details.
19 :     #
20 :     # You should have received a copy of the GNU General Public License
21 :     # along with this program; if not, write to the Free Software
22 :     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     #
24 :     # ***************************************************************************/
25 :     #
26 :     # Automated bench script.
27 :     #
28 :     # 1st draft: Skal / April 24th 2005
29 :     #
30 :     ######################################################
31 :    
32 :     $enc_bin = "xvid_encraw";
33 :     $dec_bin = "xvid_decraw";
34 :     $bench_bin = "xvid_bench";
35 :    
36 :     if (-r "BENCH_CONF.pl") {
37 :     require "BENCH_CONF.pl";
38 :     }
39 :     else
40 :     {
41 :     $bin_dir = ".";
42 :     $log_dir = ".";
43 :     $data_dir = ".";
44 :     $bench_list = "./bench_list.pl";
45 :     }
46 :    
47 :     require $bench_list;
48 :    
49 :     #########################################
50 :    
51 :     $arch = "";
52 :     $verbose = 0;
53 :     $use_valgrind = 0;
54 :     $output_command_only = 0;
55 :     $extra_arg = "";
56 :    
57 :     #$log_name;
58 :     #$log_file;
59 :     #$input_dir;
60 :     #$bin;
61 :     #$bitstream;
62 :     #$refstream;
63 :     #@raw_options;
64 :     #@ToDo;
65 :     #$filter
66 :    
67 :     #########################################
68 :     # helper funcs
69 :     #########################################
70 :    
71 :     sub check_bin
72 :     {
73 :     if (!exists $bin_made{$_[0]}) {
74 :     my_system( "make $_[0]" );
75 :     $bin_made{$_[0]} = 1;
76 :     }
77 :     }
78 :     sub check_file
79 :     {
80 :     if (-r $_[0]) {
81 :     my_system( "mv $_[0] $_[0]\_OLD" );
82 :     my_system( "touch $_[0]" );
83 :     }
84 :     }
85 :    
86 :     sub setup
87 :     {
88 :     my $action = $_[0];
89 :     $log_name = $_[1];
90 :     $log_file = "$log_dir/$log_name";
91 :     $input_dir = "$data_dir/$_[2]";
92 :     $bin = $_[3];
93 :    
94 :     check_bin $bin;
95 :     check_file $log_file;
96 :    
97 :     printf "\nBench ...... $action\n";
98 :     printf "Binary ..... $bin $extra_arg\n";
99 :     printf "Log ........ $log_name\n";
100 :     printf "Data dir ... $input_dir\n\n";
101 :    
102 :     $bin = "$bin_dir/$bin $extra_arg";
103 :     if ($use_valgrind)
104 :     {
105 :     $bin = "valgrind --tool=memcheck $bin";
106 :     $arch = "";
107 :     }
108 :     if (not $arch eq "") { $bin .= "-$arch"; }
109 :     }
110 :    
111 :     sub parse_bench
112 :     {
113 :     @raw_options = split;
114 :    
115 :     $bitstream = $raw_options[0];
116 :     if (defined($bench_filter) && !($bitstream =~ /(.*)$bench_filter(.*)/))
117 :     {
118 :     printf "Filtering out bitstream [$bitstream]\n" if ($verbose>1);
119 :     return 0;
120 :     }
121 :     shift @raw_options;
122 :    
123 :     printf "Checking bitstream: $bitstream [@raw_options]\n" if ($verbose>0);
124 :    
125 :     return 1;
126 :     }
127 :    
128 :     #########################################
129 :     # debug
130 :     #########################################
131 :    
132 :     sub my_system
133 :     {
134 :     if ($output_command_only) { printf "system: $_[0]\n"; }
135 :     else { system($_[0]); }
136 :     return ($? >> 8);
137 :     }
138 :    
139 :     #########################################
140 :     ## decoding benches
141 :     #########################################
142 :    
143 :     sub Do_Dec_Benches
144 :     {
145 :     setup( "decoding", "DEC_LOG", "./data_dec", $bench_bin );
146 :     my $n = 0, $Err = 0;
147 :     foreach (@Dec_Benches)
148 :     {
149 :     if (parse_bench($_, 0))
150 :     {
151 :     $n++;
152 :     my $launch = "$bin 9 $input_dir/$bitstream @raw_options";
153 :     my $output = `$launch`;
154 :     if (open( LOG_FILE, ">$log_file" )) {
155 :     print LOG_FILE $output;
156 :     close LOG_FILE;
157 :     }
158 :     else { printf "can't open core bench log file '$log_file'\n"; };
159 :     if ($output =~ /ERROR/) {
160 :     print "ERROR detected in ouput:\n $output\n";
161 :     $Err++;
162 :     next;
163 :     }
164 :     if ($output =~ /FPS:(.*) Checksum*/) { print "[$bitstream]: $1 fps\n"; }
165 :     }
166 :     }
167 :     die "*** $Err error(s) detected!!\n" if $Err;
168 :     }
169 :    
170 :     #########################################
171 :     ## Core benches
172 :     #########################################
173 :    
174 :     sub Do_Core_Benches
175 :     {
176 :     setup( "Core benches", "CORE_BENCH_LOG", ".", $bench_bin );
177 :     my $output = `$bin`;
178 :     if (open( LOG_FILE, ">$log_file" )) {
179 :     print LOG_FILE $output;
180 :     close LOG_FILE;
181 :     }
182 :     else { printf "can't open core bench log file '$log_file'\n"; };
183 :    
184 :    
185 :     my $warning = 0;
186 :     foreach (split('\n', $output))
187 :     {
188 :     if (/ERROR/) {
189 :     print "ERROR detected in ouput: [$_]\n";
190 :     if (/quant_mpeg/) {
191 :     if (!$warning) {
192 :     print "\n";
193 :     print "NB: MMX mpeg4 quantization is known to have very small errors (+/-1 magnitude)\n";
194 :     print "for 1 or 2 coefficients a block. This is mainly caused by the fact the unit\n";
195 :     print "test goes far behind the usual limits of real encoding. Please do not report\n";
196 :     print "this error to the developers.\n";
197 :     print "\n";
198 :     $warning = 1;
199 :     }
200 :     }
201 :     }
202 :     }
203 :     }
204 :    
205 :     #########################################
206 :     ## Help
207 :     #########################################
208 :    
209 :     sub Do_Help
210 :     {
211 :     printf "\n -= Options =-\n\n";
212 :     printf "-h ................... this help\n";
213 :     printf "-v ................... Verbose++\n";
214 :     printf "-n ................... Check 'system' commands (no action performed)\n";
215 :     printf "-vlg ................. Use valgrind\n";
216 :     printf "-dec ................. perform decoding benches.\n";
217 :     printf "-core ................ perform core benches (using 'xvid_bench').\n";
218 :     printf "-all ................. perform all benches\n";
219 :     printf "-cpu <CPU> ........... CPU to select (one of [c|mmx|mmxext|sse2|3dnow|3dnowe|altivec]).\n";
220 :     printf "-extra <arg> ......... Append extra argument 'arg' to binary commands.\n";
221 :     printf "\n";
222 :     exit;
223 :     }
224 :    
225 :     #########################################
226 :     ## main ##
227 :     #########################################
228 :    
229 :     while(@ARGV)
230 :     {
231 :     my $command = shift @ARGV;
232 :     if ($command eq "-h") { Do_Help; }
233 :     elsif ($command eq "-v") { $verbose++; }
234 :     elsif ($command eq "-n") { $output_command_only = 1; }
235 :     elsif ($command eq "-vlg") { $use_valgrind = 1; }
236 :     elsif ($command eq "-dec") { push @ToDo, $command; }
237 :     elsif ($command eq "-core") { push @ToDo, $command; }
238 :     elsif ($command eq "-all") { push @ToDo, ("-dec", "-core"); }
239 :     elsif ($command eq "-cpu")
240 :     {
241 :     die "missing argument after $option\n" if (!defined($ARGV[0]));
242 :     if ($ARGV[0] eq "c" || $ARGV[0] eq "mmx" || $ARGV[0] eq "mmxext" || $ARGV[0] eq "sse2" || $ARGV[0] eq "3dnow"
243 :     || $ARGV[0] eq "3dnowe" || $ARGV[0] eq "altivec")
244 :     {
245 :     $arch = shift @ARGV;
246 :     }
247 :     else {
248 :     die "Unrecognized cpu option '$ARGV[0]'.\n";
249 :     }
250 :     }
251 :     elsif ($command eq "-extra")
252 :     {
253 :     die "missing argument after $option\n" if (!defined($ARGV[0]));
254 :     $extra_arg = "$extra_arg $ARGV[0]";
255 :     shift @ARGV;
256 :     }
257 :     elsif ($command =~ /^\-/)
258 :     {
259 :     printf "Unrecognized option [$command]\n";
260 :     Do_Help;
261 :     }
262 :     else { $bench_filter = $command; }
263 :     }
264 :    
265 :     if (@ToDo==0) { push @ToDo, "help"; }
266 :    
267 :     printf "Filtering bench name with [$bench_filter]\n" if ($verbose>2 && defined($bench_filter));
268 :    
269 :     foreach (@ToDo) {
270 :     if ($_ eq "help" ) { Do_Help; }
271 :     elsif ($_ eq "-dec") { Do_Dec_Benches; }
272 :     elsif ($_ eq "-core") { Do_Core_Benches; }
273 :     }
274 :    
275 :     #########################################

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4