cvs: php-benchmarks /benchcli/misc smapsparser.php

From: Date: Tue, 30 Jun 2009 18:13:03 +0000
Subject: cvs: php-benchmarks /benchcli/misc smapsparser.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-65152@lists.php.net to get a copy of this message
hjalle Tue Jun 30 18:13:03 2009 UTC Modified files: /php-benchmarks/benchcli/misc smapsparser.php Log: Changes to lower memory usage in the benchmark script and sort depending on private RSS instead of total VM size. http://cvs.php.net/viewvc.cgi/php-benchmarks/benchcli/misc/smapsparser.php?r1=1.2&r2=1.3&diff_format=u Index: php-benchmarks/benchcli/misc/smapsparser.php diff -u php-benchmarks/benchcli/misc/smapsparser.php:1.2 php-benchmarks/benchcli/misc/smapsparser.php:1.3 --- php-benchmarks/benchcli/misc/smapsparser.php:1.2 Wed Jun 24 00:56:19 2009 +++ php-benchmarks/benchcli/misc/smapsparser.php Tue Jun 30 18:13:03 2009 @@ -8,12 +8,9 @@ var $results; var $usage; var $peak; - function Smapsparser() - { - $usage = array(); - } function parseSmapsData($data) { + $this->usage = array(); $lines = explode("\n",$data); $i = 0; $last = array(); @@ -38,7 +35,11 @@ } $result["objects"][] = $last; $this->usage[] = $result; + if (isset($this->peak)) { + $this->usage[] = $this->peak; + } $this->peak = $this->usage[$this->getPeak()]; + unset($this->usage); $this->sortMemUsage($this->peak["objects"]); } function getUsage() @@ -58,7 +59,7 @@ } /** * Get element index of peak memory usage - * + * * @return int The index of $this->used's peak */ function getPeak() @@ -66,12 +67,12 @@ $maxi = 0; $maxval = 0; $i = 0; - + foreach ($this->usage as $mem_array) { - if ($maxval < $mem_array["Size"]) { + $val = $mem_array["Private_Dirty"] + $mem_array["Private_Clean"]; + if ($maxval < $val) { $maxi = $i; - $maxval = $mem_array["Size"]; - + $maxval = $val; } $i++; } @@ -82,30 +83,31 @@ */ function clear() { - unset($results); - unset($usage); + unset($this->results); + unset($this->usage); + unset($this->peak); } /** - * Prints the top n memory consuming files based on Dirty Private RSS, + * Prints the top n memory consuming files based on Dirty Private RSS, * for the maximum peak of memory consumption. * * @param int $n The number of files to be printed * @param string $resource If specified, it will append to this file instead - * of stdout - * + * of stdout + * * @return void */ function printMaxUsage($n,$resource = "php://stdout") { - + $i = 0; if ($resource == "php://stdout") { $fh = fopen($resource, "w"); } else { $fh = fopen($resource, "a+"); } - fprintf($fh, "VM Size total: %10skB\n", $this->peak['Size']); - fprintf($fh, "RSS : %10skB Total\n", $this->peak['Rss']); + fprintf($fh, "RSS private : %10skB Total\n", $this->peak['Private_Clean'] + $this->peak['Private_Dirty']); + fprintf($fh, "VM Size : %10skB\n", $this->peak['Size']); fprintf($fh, " : %10skB Shared total\n", $this->peak['Shared_Dirty'] + $this->peak["Shared_Clean"]); fprintf($fh, " %10skB Private Clean\n", $this->peak['Private_Clean']); fprintf($fh, " %10skB Private Dirty\n", $this->peak['Private_Dirty']); @@ -125,27 +127,27 @@ } fprintf($fh, "%s", "\n"); } -/** - * Prints the summary of the memory usage. + /** + * Prints the summary of the memory usage. * * @param string $resource If specified, it will append to this file instead - * of stdout - * + * of stdout + * * @return void */ function printSumUsage($resource = "php://stdout") { - + $i = 0; if ($resource == "php://stdout") { $fh = fopen($resource, "w"); } else { $fh = fopen($resource, "a+"); } - + fprintf($fh, "%'-59s\n", "-"); - fprintf($fh, "VM Size total: %10skB\n", $this->peak['Size']); - fprintf($fh, "RSS : %10skB Total\n", $this->peak['Rss']); + fprintf($fh, "RSS private : %10smB Total\n", round(($this->peak['Private_Clean'] + $this->peak['Private_Dirty'])/1024,1)); + fprintf($fh, "VM Size : %10smB\n", round(($this->peak['Size']/1024),1)); fprintf($fh, " : %10skB Shared total\n", $this->peak['Shared_Dirty'] + $this->peak["Shared_Clean"]); fprintf($fh, " %10skB Private Clean\n", $this->peak['Private_Clean']); fprintf($fh, " %10skB Private Dirty\n", $this->peak['Private_Dirty']); @@ -156,7 +158,7 @@ * Sorts the memory usage from the array * * @param &array &$array The parsed smaps results to be sorted - * + * * @return void */ function sortMemUsage(&$array)

« previous php.qa (#65152) next »