Commit 4e7d5f190afcbcfa44cc0d019cbf7d3b4496522b
1 parent
ceeb25f3
Include memory usage in performance test output
Showing
2 changed files
with
55 additions
and
4 deletions
manual/release-notes.rst
| @@ -253,6 +253,14 @@ For a detailed list of changes, please see the file | @@ -253,6 +253,14 @@ For a detailed list of changes, please see the file | ||
| 253 | some additional caching to reduce the overhead of repeatedly | 253 | some additional caching to reduce the overhead of repeatedly |
| 254 | reading environment variables at runtime. | 254 | reading environment variables at runtime. |
| 255 | 255 | ||
| 256 | + - The test files used by the ``performance_check`` script at the | ||
| 257 | + top of the repository are now available in the | ||
| 258 | + `qpdf/performance-test-files github repository | ||
| 259 | + <https://github.com/qpdf/performance-test-files>`__. In addition | ||
| 260 | + to running time, memory usage is also included in performance | ||
| 261 | + test results. The ``performance_check`` tool has only been | ||
| 262 | + tested on Linux. | ||
| 263 | + | ||
| 256 | - Lots of code cleanup and refactoring work was contributed in | 264 | - Lots of code cleanup and refactoring work was contributed in |
| 257 | multiple pull requests by M. Holger. | 265 | multiple pull requests by M. Holger. |
| 258 | 266 |
performance_check
| @@ -5,6 +5,8 @@ use strict; | @@ -5,6 +5,8 @@ use strict; | ||
| 5 | use File::Basename; | 5 | use File::Basename; |
| 6 | use Time::HiRes qw(gettimeofday tv_interval); | 6 | use Time::HiRes qw(gettimeofday tv_interval); |
| 7 | use File::Path qw(make_path); | 7 | use File::Path qw(make_path); |
| 8 | +use IPC::Open3; | ||
| 9 | +use IO::Pipe; | ||
| 8 | 10 | ||
| 9 | my $whoami = basename($0); | 11 | my $whoami = basename($0); |
| 10 | $| = 1; | 12 | $| = 1; |
| @@ -29,6 +31,7 @@ my %arg_compat = ( | @@ -29,6 +31,7 @@ my %arg_compat = ( | ||
| 29 | '--remove-unreferenced-resources=no' => '--preserve-unreferenced-resources', | 31 | '--remove-unreferenced-resources=no' => '--preserve-unreferenced-resources', |
| 30 | '--remove-unreferenced-resources=yes' => '', | 32 | '--remove-unreferenced-resources=yes' => '', |
| 31 | '--remove-unreferenced-resources=auto' => undef, | 33 | '--remove-unreferenced-resources=auto' => undef, |
| 34 | + '--report-memory-usage' => '', | ||
| 32 | ); | 35 | ); |
| 33 | 36 | ||
| 34 | my $executable = undef; | 37 | my $executable = undef; |
| @@ -172,6 +175,20 @@ Repository URL: https://github.com/qpdf/performance-test-files | @@ -172,6 +175,20 @@ Repository URL: https://github.com/qpdf/performance-test-files | ||
| 172 | } | 175 | } |
| 173 | } | 176 | } |
| 174 | 177 | ||
| 178 | +my $report_mem = filter_args(["--report-memory-usage"]); | ||
| 179 | +{ | ||
| 180 | + my ($r, $mem) = run_cmd($executable, @$report_mem, | ||
| 181 | + "--empty", File::Spec->devnull()); | ||
| 182 | + if ($r != 0) | ||
| 183 | + { | ||
| 184 | + die "$whoami: $executable doesn't seem to work\n"; | ||
| 185 | + } | ||
| 186 | + if ($mem == 0) | ||
| 187 | + { | ||
| 188 | + print "** Note: memory information is not available **\n"; | ||
| 189 | + } | ||
| 190 | +} | ||
| 191 | + | ||
| 175 | run_tests(); | 192 | run_tests(); |
| 176 | print "\n"; | 193 | print "\n"; |
| 177 | 194 | ||
| @@ -211,6 +228,7 @@ sub run_tests | @@ -211,6 +228,7 @@ sub run_tests | ||
| 211 | 228 | ||
| 212 | chomp(my $commit = `git describe @`); | 229 | chomp(my $commit = `git describe @`); |
| 213 | print "commit: $commit\n"; | 230 | print "commit: $commit\n"; |
| 231 | + print "Format: time-in-seconds RAM-in-MiB filename\n"; | ||
| 214 | make_path($workdir); | 232 | make_path($workdir); |
| 215 | foreach my $test (@tests) | 233 | foreach my $test (@tests) |
| 216 | { | 234 | { |
| @@ -259,16 +277,17 @@ sub run_test | @@ -259,16 +277,17 @@ sub run_test | ||
| 259 | last; | 277 | last; |
| 260 | } | 278 | } |
| 261 | } | 279 | } |
| 262 | - my @cmd = ($executable, @$args, $file, "$workdir/$outfile"); | 280 | + my @cmd = ($executable, @$args, @$report_mem, $file, "$workdir/$outfile"); |
| 263 | # Run once and discard to update caches | 281 | # Run once and discard to update caches |
| 264 | system("sync"); | 282 | system("sync"); |
| 265 | - system(@cmd); | 283 | + run_cmd(@cmd); |
| 266 | my $i = 0; | 284 | my $i = 0; |
| 267 | my $total = 0; | 285 | my $total = 0; |
| 286 | + my $max_mem = 0; | ||
| 268 | while ($i < $iterations) | 287 | while ($i < $iterations) |
| 269 | { | 288 | { |
| 270 | my $start = [gettimeofday]; | 289 | my $start = [gettimeofday]; |
| 271 | - my $r = system(@cmd); | 290 | + my ($r, $mem) = run_cmd(@cmd); |
| 272 | if ($r == 2) | 291 | if ($r == 2) |
| 273 | { | 292 | { |
| 274 | # interrupt | 293 | # interrupt |
| @@ -280,6 +299,7 @@ sub run_test | @@ -280,6 +299,7 @@ sub run_test | ||
| 280 | print " command failed; ignoring results\n"; | 299 | print " command failed; ignoring results\n"; |
| 281 | return undef; | 300 | return undef; |
| 282 | } | 301 | } |
| 302 | + $max_mem = $mem > $max_mem ? $mem : $max_mem; | ||
| 283 | my $elapsed = tv_interval($start, $end); | 303 | my $elapsed = tv_interval($start, $end); |
| 284 | $total += $elapsed; | 304 | $total += $elapsed; |
| 285 | ++$i; | 305 | ++$i; |
| @@ -289,5 +309,28 @@ sub run_test | @@ -289,5 +309,28 @@ sub run_test | ||
| 289 | last; | 309 | last; |
| 290 | } | 310 | } |
| 291 | } | 311 | } |
| 292 | - return sprintf("%0.4f", $total / $i); | 312 | + return sprintf("%8.4f %8.4f", $total / $i, $max_mem / 1048576); |
| 313 | +} | ||
| 314 | + | ||
| 315 | +sub run_cmd | ||
| 316 | +{ | ||
| 317 | + my @cmd = @_; | ||
| 318 | + my $pipe = IO::Pipe->new(); | ||
| 319 | + my $pid = open3(my $child_in, '>&STDOUT', $pipe->writer(), @cmd); | ||
| 320 | + $child_in->close(); | ||
| 321 | + waitpid($pid, 0); | ||
| 322 | + my $r = $?; | ||
| 323 | + my $mem = 0; | ||
| 324 | + while (<$pipe>) | ||
| 325 | + { | ||
| 326 | + if (m/qpdf-max-memory-usage (\d+)/) | ||
| 327 | + { | ||
| 328 | + $mem = $1; | ||
| 329 | + } | ||
| 330 | + else | ||
| 331 | + { | ||
| 332 | + warn $_; | ||
| 333 | + } | ||
| 334 | + } | ||
| 335 | + ($r, $mem); | ||
| 293 | } | 336 | } |