public function execute($parameters) { global $wgOut, $wgUser; $this->setHeaders(); $this->setup(); if (!function_exists('apc_cache_info')) { $wgOut->addWikiMsg('viewapc-apc-not-available'); return; } if ($this->opts->getValue('image')) { $wgOut->disable(); header('Content-type: image/png'); echo APCImages::generateImage($this->opts->getValue('image')); return; } if ($this->opts->getValue('mode') !== self::MODE_STATS) { if (!$wgUser->isAllowed('apc')) { $wgOut->permissionRequired('apc'); return; } } // clear cache if ($this->opts->getValue('clearcache')) { $this->opts->setValue('clearcache', ''); // TODO: reset if (!$wgUser->isAllowed('apc')) { $wgOut->permissionRequired('apc'); return; } $usermode = $this->opts->getValue('mode') === self::MODE_USER_CACHE; $mode = $usermode ? 'user' : 'opcode'; apc_clear_cache($mode); if ($usermode) { $wgOut->addWikiMsg('viewapc-filecache-cleared'); } else { $wgOut->addWikiMsg('viewapc-usercache-cleared'); } } $delete = $this->opts->getValue('delete'); if ($delete) { $this->opts->setValue('delete', ''); // TODO: reset if (!$wgUser->isAllowed('apc')) { $wgOut->permissionRequired('apc'); return; } $result = apc_delete($delete); if ($result) { $wgOut->addWikiMsg('viewapc-delete-ok', $delete); } else { $wgOut->addWikiMsg('viewapc-delete-failed', $delete); } } $wgOut->addModuleStyles('ext.apc'); $this->getLogo(); $this->mainMenu(); $this->doPage(); }
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; }