[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 1618 - (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 : Skal 1618 # force re-build of binary (better safe than sorry)
74 :     my_system( "rm -f $_[0]" );
75 :     my_system( "make $_[0]" );
76 : Skal 1614 }
77 :     sub check_file
78 :     {
79 :     if (-r $_[0]) {
80 :     my_system( "mv $_[0] $_[0]\_OLD" );
81 :     my_system( "touch $_[0]" );
82 :     }
83 :     }
84 :    
85 :     sub setup
86 :     {
87 :     my $action = $_[0];
88 :     $log_name = $_[1];
89 :     $log_file = "$log_dir/$log_name";
90 :     $input_dir = "$data_dir/$_[2]";
91 :     $bin = $_[3];
92 :    
93 :     check_bin $bin;
94 :     check_file $log_file;
95 :    
96 :     printf "\nBench ...... $action\n";
97 :     printf "Binary ..... $bin $extra_arg\n";
98 :     printf "Log ........ $log_name\n";
99 :     printf "Data dir ... $input_dir\n\n";
100 :    
101 :     $bin = "$bin_dir/$bin $extra_arg";
102 :     if ($use_valgrind)
103 :     {
104 :     $bin = "valgrind --tool=memcheck $bin";
105 :     $arch = "";
106 :     }
107 :     if (not $arch eq "") { $bin .= "-$arch"; }
108 :     }
109 :    
110 :     sub parse_bench
111 :     {
112 :     @raw_options = split;
113 :    
114 :     $bitstream = $raw_options[0];
115 :     if (defined($bench_filter) && !($bitstream =~ /(.*)$bench_filter(.*)/))
116 :     {
117 :     printf "Filtering out bitstream [$bitstream]\n" if ($verbose>1);
118 :     return 0;
119 :     }
120 :     shift @raw_options;
121 :    
122 :     printf "Checking bitstream: $bitstream [@raw_options]\n" if ($verbose>0);
123 :    
124 :     return 1;
125 :     }
126 :    
127 :     #########################################
128 :     # debug
129 :     #########################################
130 :    
131 :     sub my_system
132 :     {
133 :     if ($output_command_only) { printf "system: $_[0]\n"; }
134 :     else { system($_[0]); }
135 :     return ($? >> 8);
136 :     }
137 :    
138 :     #########################################
139 :     ## decoding benches
140 :     #########################################
141 :    
142 :     sub Do_Dec_Benches
143 :     {
144 :     setup( "decoding", "DEC_LOG", "./data_dec", $bench_bin );
145 :     my $n = 0, $Err = 0;
146 :     foreach (@Dec_Benches)
147 :     {
148 :     if (parse_bench($_, 0))
149 :     {
150 :     $n++;
151 :     my $launch = "$bin 9 $input_dir/$bitstream @raw_options";
152 :     my $output = `$launch`;
153 :     if (open( LOG_FILE, ">$log_file" )) {
154 :     print LOG_FILE $output;
155 :     close LOG_FILE;
156 :     }
157 :     else { printf "can't open core bench log file '$log_file'\n"; };
158 :     if ($output =~ /ERROR/) {
159 : Skal 1618 print "ERROR detected in ouput, while decoding [$bitstream]:\n $output\n";
160 : Skal 1614 $Err++;
161 :     next;
162 :     }
163 :     if ($output =~ /FPS:(.*) Checksum*/) { print "[$bitstream]: $1 fps\n"; }
164 :     }
165 :     }
166 :     die "*** $Err error(s) detected!!\n" if $Err;
167 :     }
168 :    
169 :     #########################################
170 :     ## Core benches
171 :     #########################################
172 :    
173 :     sub Do_Core_Benches
174 :     {
175 :     setup( "Core benches", "CORE_BENCH_LOG", ".", $bench_bin );
176 :     my $output = `$bin`;
177 :     if (open( LOG_FILE, ">$log_file" )) {
178 :     print LOG_FILE $output;
179 :     close LOG_FILE;
180 :     }
181 :     else { printf "can't open core bench log file '$log_file'\n"; };
182 :    
183 :    
184 :     my $warning = 0;
185 :     foreach (split('\n', $output))
186 :     {
187 :     if (/ERROR/) {
188 :     print "ERROR detected in ouput: [$_]\n";
189 :     if (/quant_mpeg/) {
190 :     if (!$warning) {
191 :     print "\n";
192 :     print "NB: MMX mpeg4 quantization is known to have very small errors (+/-1 magnitude)\n";
193 :     print "for 1 or 2 coefficients a block. This is mainly caused by the fact the unit\n";
194 :     print "test goes far behind the usual limits of real encoding. Please do not report\n";
195 :     print "this error to the developers.\n";
196 :     print "\n";
197 :     $warning = 1;
198 :     }
199 :     }
200 :     }
201 :     }
202 :     }
203 :    
204 :     #########################################
205 :     ## Help
206 :     #########################################
207 :    
208 :     sub Do_Help
209 :     {
210 :     printf "\n -= Options =-\n\n";
211 :     printf "-h ................... this help\n";
212 :     printf "-v ................... Verbose++\n";
213 :     printf "-n ................... Check 'system' commands (no action performed)\n";
214 :     printf "-vlg ................. Use valgrind\n";
215 :     printf "-dec ................. perform decoding benches.\n";
216 :     printf "-core ................ perform core benches (using 'xvid_bench').\n";
217 :     printf "-all ................. perform all benches\n";
218 :     printf "-cpu <CPU> ........... CPU to select (one of [c|mmx|mmxext|sse2|3dnow|3dnowe|altivec]).\n";
219 :     printf "-extra <arg> ......... Append extra argument 'arg' to binary commands.\n";
220 :     printf "\n";
221 :     exit;
222 :     }
223 :    
224 :     #########################################
225 :     ## main ##
226 :     #########################################
227 :    
228 :     while(@ARGV)
229 :     {
230 :     my $command = shift @ARGV;
231 :     if ($command eq "-h") { Do_Help; }
232 :     elsif ($command eq "-v") { $verbose++; }
233 :     elsif ($command eq "-n") { $output_command_only = 1; }
234 :     elsif ($command eq "-vlg") { $use_valgrind = 1; }
235 :     elsif ($command eq "-dec") { push @ToDo, $command; }
236 :     elsif ($command eq "-core") { push @ToDo, $command; }
237 :     elsif ($command eq "-all") { push @ToDo, ("-dec", "-core"); }
238 :     elsif ($command eq "-cpu")
239 :     {
240 :     die "missing argument after $option\n" if (!defined($ARGV[0]));
241 :     if ($ARGV[0] eq "c" || $ARGV[0] eq "mmx" || $ARGV[0] eq "mmxext" || $ARGV[0] eq "sse2" || $ARGV[0] eq "3dnow"
242 :     || $ARGV[0] eq "3dnowe" || $ARGV[0] eq "altivec")
243 :     {
244 :     $arch = shift @ARGV;
245 :     }
246 :     else {
247 :     die "Unrecognized cpu option '$ARGV[0]'.\n";
248 :     }
249 :     }
250 :     elsif ($command eq "-extra")
251 :     {
252 :     die "missing argument after $option\n" if (!defined($ARGV[0]));
253 :     $extra_arg = "$extra_arg $ARGV[0]";
254 :     shift @ARGV;
255 :     }
256 :     elsif ($command =~ /^\-/)
257 :     {
258 :     printf "Unrecognized option [$command]\n";
259 :     Do_Help;
260 :     }
261 :     else { $bench_filter = $command; }
262 :     }
263 :    
264 :     if (@ToDo==0) { push @ToDo, "help"; }
265 :    
266 :     printf "Filtering bench name with [$bench_filter]\n" if ($verbose>2 && defined($bench_filter));
267 :    
268 :     foreach (@ToDo) {
269 :     if ($_ eq "help" ) { Do_Help; }
270 :     elsif ($_ eq "-dec") { Do_Dec_Benches; }
271 :     elsif ($_ eq "-core") { Do_Core_Benches; }
272 :     }
273 :    
274 :     #########################################

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