예제 #1
0
 protected function displayObject($object)
 {
     global $wgLang;
     $cache = apc_cache_info($this->userMode ? 'user' : 'opcode');
     $s = Xml::openElement('div', array('class' => 'mw-apc-listing')) . Xml::openElement('table') . Xml::openElement('tbody') . Xml::openElement('tr') . Xml::element('th', null, wfMsg('viewapc-display-attribute')) . Xml::element('th', null, wfMsg('viewapc-display-value')) . Xml::closeElement('tr');
     $r = 1;
     foreach ($this->scopes as $list) {
         foreach ($cache[$list] as $entry) {
             if (md5($entry[$this->fieldKey]) !== $object) {
                 continue;
             }
             $size = 0;
             foreach ($entry as $key => $value) {
                 switch ($key) {
                     case 'num_hits':
                         $value = $wgLang->formatNum($value) . $wgLang->formatNum(sprintf(" (%.2f%%)", $value * 100 / $cache['num_hits']));
                         break;
                     case 'deletion_time':
                         $value = $this->formatValue($key, $value);
                         if (!$value) {
                             $value = wfMsg('viewapc-display-no-delete');
                             break;
                         }
                     case 'mem_size':
                         $size = $value;
                     default:
                         $value = $this->formatValue($key, $value);
                 }
                 $s .= APCUtils::tableRow($r = 1 - $r, wfMsgHtml('viewapc-display-' . $key), htmlspecialchars($value));
             }
             if ($this->userMode) {
                 if ($size > 1024 * 1024) {
                     $s .= APCUtils::tableRow($r = 1 - $r, wfMsgHtml('viewapc-display-stored-value'), wfMsgExt('viewapc-display-too-big', 'parseinline'));
                 } else {
                     $value = var_export(apc_fetch($entry[$this->fieldKey]), true);
                     $s .= APCUtils::tableRow($r = 1 - $r, wfMsgHtml('viewapc-display-stored-value'), Xml::element('pre', null, $value));
                 }
             }
         }
     }
     $s .= '</tbody></table></div>';
     return $s;
 }
예제 #2
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;
 }