Ejemplo n.º 1
0
 public static function doFragmentationTable($mem, $title)
 {
     global $wgLang;
     $s = APCUtils::tableHeader(wfMsg('viewapc-memoryfragmentation'), 'mw-apc-img-table');
     $s .= Xml::openElement('tr') . Xml::openElement('td');
     // Fragementation: (freeseg - 1) / total_seg
     $nseg = $freeseg = $fragsize = $freetotal = 0;
     for ($i = 0; $i < $mem['num_seg']; $i++) {
         $ptr = 0;
         foreach ($mem['block_lists'][$i] as $block) {
             if ($block['offset'] != $ptr) {
                 ++$nseg;
             }
             $ptr = $block['offset'] + $block['size'];
             /* Only consider blocks <5M for the fragmentation % */
             if ($block['size'] < 5 * 1024 * 1024) {
                 $fragsize += $block['size'];
             }
             $freetotal += $block['size'];
         }
         $freeseg += count($mem['block_lists'][$i]);
     }
     if (APCImages::graphics_avail()) {
         $attribs = array('alt' => '', 'width' => 2 * APCImages::GRAPH_SIZE + 150, 'height' => APCImages::GRAPH_SIZE + 10, 'src' => $title->getLocalURL('image=' . APCImages::IMG_FRAGMENTATION));
         $s .= Xml::element('img', $attribs);
     }
     if ($freeseg > 1) {
         $fragPercent = sprintf('%.2f%%', $fragsize / $freetotal * 100);
         $s .= wfMsgExt('viewapc-fragmentation-info', 'parse', $wgLang->formatNum($fragPercent, true), $wgLang->formatSize($fragsize), $wgLang->formatSize($freetotal), $wgLang->formatNum($freeseg));
     } else {
         $s .= wfMsgExt('viewapc-fragmentation-none', 'parse');
     }
     $s .= Xml::closeElement('td') . Xml::closeElement('tr');
     if (isset($mem['adist'])) {
         foreach ($mem['adist'] as $i => $v) {
             $cur = pow(2, $i);
             $nxt = pow(2, $i + 1) - 1;
             if ($i == 0) {
                 $range = "1";
             } else {
                 $range = "{$cur} - {$nxt}";
             }
             $s .= Xml::tags('tr', null, Xml::tags('th', array('align' => 'right'), $range) . Xml::tags('td', array('align' => 'right'), $v));
         }
     }
     $s .= APCUtils::tableFooter();
     return $s;
 }