Patch apc.php-img-data-patch for APC Bug #66954
Patch version 2014-03-25 14:44 UTC
Return to Bug #66954 |
Download this patch
Patch Revisions:
Developer: ngreimel@gmail.com
--- apc.php 2014-03-24 15:37:59.000000000 -0500
+++ apc.php 2014-03-24 17:15:59.000000000 -0500
@@ -333,8 +333,8 @@
switch ($MYREQUEST['IMG']) {
case 1:
- $s=$mem['num_seg']*$mem['seg_size'];
- $a=$mem['avail_mem'];
+ $s=$_REQUEST['num_seg']*$_REQUEST['seg_size'];
+ $a=$_REQUEST['avail_mem'];
$x=$y=$size/2;
$fuzz = 0.000001;
@@ -342,9 +342,9 @@
// would expect because we try to visualize any memory fragmentation as well.
$angle_from = 0;
$string_placement=array();
- for($i=0; $i<$mem['num_seg']; $i++) {
+ for($i=0; $i<$_REQUEST['num_seg']; $i++) {
$ptr = 0;
- $free = $mem['block_lists'][$i];
+ $free = $_REQUEST['block_lists'][$i];
uasort($free, 'block_sort');
foreach($free as $block) {
if($block['offset']!=$ptr) { // Used block
@@ -369,8 +369,8 @@
$angle_from = $angle_to;
$ptr = $block['offset']+$block['size'];
}
- if ($ptr < $mem['seg_size']) { // memory at the end
- $angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
+ if ($ptr < $_REQUEST['seg_size']) { // memory at the end
+ $angle_to = $angle_from + ($_REQUEST['seg_size'] - $ptr)/$s;
if(($angle_to+$fuzz)>1) $angle_to = 1;
fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
if (($angle_to-$angle_from)>0.05) {
@@ -384,25 +384,25 @@
break;
case 2:
- $s=$cache['num_hits']+$cache['num_misses'];
- $a=$cache['num_hits'];
+ $s=$_REQUEST['num_hits']+$_REQUEST['num_misses'];
+ $a=$_REQUEST['num_hits'];
- fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$cache['num_hits']*100/$s));
- fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$cache['num_misses']*100/$s));
+ fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$_REQUEST['num_hits']*100/$s));
+ fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$_REQUEST['num_misses']*100/$s));
break;
case 3:
- $s=$mem['num_seg']*$mem['seg_size'];
- $a=$mem['avail_mem'];
+ $s=$_REQUEST['num_seg']*$_REQUEST['seg_size'];
+ $a=$_REQUEST['avail_mem'];
$x=130;
$y=1;
$j=1;
// This block of code creates the bar chart. It is a lot more complex than you
// would expect because we try to visualize any memory fragmentation as well.
- for($i=0; $i<$mem['num_seg']; $i++) {
+ for($i=0; $i<$_REQUEST['num_seg']; $i++) {
$ptr = 0;
- $free = $mem['block_lists'][$i];
+ $free = $_REQUEST['block_lists'][$i];
uasort($free, 'block_sort');
foreach($free as $block) {
if($block['offset']!=$ptr) { // Used block
@@ -423,20 +423,20 @@
$y+=$h;
$ptr = $block['offset']+$block['size'];
}
- if ($ptr < $mem['seg_size']) { // memory at the end
- $h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
+ if ($ptr < $_REQUEST['seg_size']) { // memory at the end
+ $h = (GRAPH_SIZE-5) * ($_REQUEST['seg_size'] - $ptr) / $s;
if ($h > 0) {
- fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
+ fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($_REQUEST['seg_size']-$ptr),$j++);
}
}
}
break;
case 4:
- $s=$cache['num_hits']+$cache['num_misses'];
- $a=$cache['num_hits'];
+ $s=$_REQUEST['num_hits']+$_REQUEST['num_misses'];
+ $a=$_REQUEST['num_hits'];
- fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$cache['num_hits']*100/$s));
- fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$cache['num_misses']*100/$s));
+ fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$_REQUEST['num_hits']*100/$s));
+ fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$_REQUEST['num_misses']*100/$s));
break;
}
@@ -867,11 +867,37 @@
</tr>
EOB;
+ function image_url($path, $type, $time, $mem, $cache) {
+ $url_template = '%s?IMG=%s&%s';
+ $url = sprintf($url_template, $path, $type, $time);
+ switch ($type) {
+ case 1:
+ case 3:
+ $block_list_template = '&block_lists[%s][%s][offset]=%s&block_lists[%s][%s][size]=%s';
+ $url .= '&num_seg=' . $mem['num_seg'];
+ $url .= '&seg_size=' . $mem['seg_size'];
+ $url .= '&avail_mem=' . $mem['avail_mem'];
+ for ($i = 0; $i < $mem['num_seg']; $i++) {
+ $free = $mem['block_lists'][$i];
+ uasort($free, 'block_sort');
+ foreach ($free as $j => $block) {
+ $url .= sprintf($block_list_template, $i, $j, $block['offset'], $i, $j, $block['size']);
+ }
+ }
+ break;
+ case 2:
+ case 4:
+ $url .= '&num_hist=' . $cache['num_hits'];
+ $url .= '&num_misses=' . $cache['num_misses'];
+ }
+ return $url;
+ }
+
echo
graphics_avail() ?
'<tr>'.
- "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF?IMG=1&$time\"></td>".
- "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
+ "<td class=td-0><img alt=\"\" $size src=\"" . image_url($PHP_SELF, 1, $time, $mem, $cache) . "\"></td>".
+ "<td class=td-1><img alt=\"\" $size src=\"" . image_url($PHP_SELF, 2, $time, $mem, $cache) . "\"></td></tr>\n"
: "",
'<tr>',
'<td class=td-0><span class="green box"> </span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
@@ -915,8 +941,9 @@
if (graphics_avail()) {
$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
+ $url = image_url($PHP_SELF, 3, $time, $mem, $cache);
echo <<<EOB
- <img alt="" $size src="$PHP_SELF?IMG=3&$time">
+ <img alt="" $size src="$url">
EOB;
}
echo <<<EOB
|