Exemple #1
0
/**
 * @todo document
 */
function wfLogProfilingData()
{
    global $wgDebugLogGroups, $wgDebugRawPage;
    $context = RequestContext::getMain();
    $request = $context->getRequest();
    $profiler = Profiler::instance();
    $profiler->setContext($context);
    $profiler->logData();
    $config = $context->getConfig();
    if ($config->get('StatsdServer')) {
        $statsdServer = explode(':', $config->get('StatsdServer'));
        $statsdHost = $statsdServer[0];
        $statsdPort = isset($statsdServer[1]) ? $statsdServer[1] : 8125;
        $statsdSender = new SocketSender($statsdHost, $statsdPort);
        $statsdClient = new StatsdClient($statsdSender);
        $statsdClient->send($context->getStats()->getBuffer());
    }
    # Profiling must actually be enabled...
    if ($profiler instanceof ProfilerStub) {
        return;
    }
    if (isset($wgDebugLogGroups['profileoutput']) && $wgDebugLogGroups['profileoutput'] === false) {
        // Explicitly disabled
        return;
    }
    if (!$wgDebugRawPage && wfIsDebugRawPage()) {
        return;
    }
    $ctx = array('elapsed' => $request->getElapsedTime());
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ctx['forwarded_for'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ctx['client_ip'] = $_SERVER['HTTP_CLIENT_IP'];
    }
    if (!empty($_SERVER['HTTP_FROM'])) {
        $ctx['from'] = $_SERVER['HTTP_FROM'];
    }
    if (isset($ctx['forwarded_for']) || isset($ctx['client_ip']) || isset($ctx['from'])) {
        $ctx['proxy'] = $_SERVER['REMOTE_ADDR'];
    }
    // Don't load $wgUser at this late stage just for statistics purposes
    // @todo FIXME: We can detect some anons even if it is not loaded.
    // See User::getId()
    $user = $context->getUser();
    $ctx['anon'] = $user->isItemLoaded('id') && $user->isAnon();
    // Command line script uses a FauxRequest object which does not have
    // any knowledge about an URL and throw an exception instead.
    try {
        $ctx['url'] = urldecode($request->getRequestURL());
    } catch (Exception $ignored) {
        // no-op
    }
    $ctx['output'] = $profiler->getOutput();
    $log = LoggerFactory::getInstance('profileoutput');
    $log->info("Elapsed: {elapsed}; URL: <{url}>\n{output}", $ctx);
}
/**
 * @todo document
 */
function wfLogProfilingData()
{
    global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
    global $wgProfileLimit, $wgUser;
    $profiler = Profiler::instance();
    # Profiling must actually be enabled...
    if ($profiler->isStub()) {
        return;
    }
    // Get total page request time and only show pages that longer than
    // $wgProfileLimit time (default is 0)
    $now = wfTime();
    $elapsed = $now - $wgRequestTime;
    if ($elapsed <= $wgProfileLimit) {
        return;
    }
    $profiler->logData();
    // Check whether this should be logged in the debug file.
    if ($wgDebugLogFile == '' || !$wgDebugRawPage && wfIsDebugRawPage()) {
        return;
    }
    $forward = '';
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
    }
    if (!empty($_SERVER['HTTP_FROM'])) {
        $forward .= ' from ' . $_SERVER['HTTP_FROM'];
    }
    if ($forward) {
        $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
    }
    // Don't load $wgUser at this late stage just for statistics purposes
    // @todo FIXME: We can detect some anons even if it is not loaded. See User::getId()
    if ($wgUser->isItemLoaded('id') && $wgUser->isAnon()) {
        $forward .= ' anon';
    }
    $log = sprintf("%s\t%04.3f\t%s\n", gmdate('YmdHis'), $elapsed, urldecode($wgRequest->getRequestURL() . $forward));
    wfErrorLog($log . $profiler->getOutput(), $wgDebugLogFile);
}
Exemple #3
0
/**
 * @todo document
 */
function wfLogProfilingData()
{
    global $wgRequestTime, $wgDebugLogFile, $wgDebugLogGroups, $wgDebugRawPage;
    global $wgProfileLimit, $wgUser, $wgRequest;
    StatCounter::singleton()->flush();
    $profiler = Profiler::instance();
    # Profiling must actually be enabled...
    if ($profiler->isStub()) {
        return;
    }
    // Get total page request time and only show pages that longer than
    // $wgProfileLimit time (default is 0)
    $elapsed = microtime(true) - $wgRequestTime;
    if ($elapsed <= $wgProfileLimit) {
        return;
    }
    $profiler->logData();
    // Check whether this should be logged in the debug file.
    if (isset($wgDebugLogGroups['profileoutput']) && $wgDebugLogGroups['profileoutput'] === false) {
        // Explicitely disabled
        return;
    }
    if (!isset($wgDebugLogGroups['profileoutput']) && $wgDebugLogFile == '') {
        // Logging not enabled; no point going further
        return;
    }
    if (!$wgDebugRawPage && wfIsDebugRawPage()) {
        return;
    }
    $forward = '';
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
    }
    if (!empty($_SERVER['HTTP_FROM'])) {
        $forward .= ' from ' . $_SERVER['HTTP_FROM'];
    }
    if ($forward) {
        $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
    }
    // Don't load $wgUser at this late stage just for statistics purposes
    // @todo FIXME: We can detect some anons even if it is not loaded. See User::getId()
    if ($wgUser->isItemLoaded('id') && $wgUser->isAnon()) {
        $forward .= ' anon';
    }
    // Command line script uses a FauxRequest object which does not have
    // any knowledge about an URL and throw an exception instead.
    try {
        $requestUrl = $wgRequest->getRequestURL();
    } catch (MWException $e) {
        $requestUrl = 'n/a';
    }
    $log = sprintf("%s\t%04.3f\t%s\n", gmdate('YmdHis'), $elapsed, urldecode($requestUrl . $forward));
    wfDebugLog('profileoutput', $log . $profiler->getOutput());
}
/**
 * @todo document
 */
function wfLogProfilingData()
{
    global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
    global $wgProfileLimit, $wgUser, $wgProfilingDataLogged;
    $wgProfilingDataLogged = true;
    $profiler = Profiler::instance();
    # Profiling must actually be enabled...
    if ($profiler->isStub()) {
        return;
    }
    // Get total page request time and only show pages that longer than
    // $wgProfileLimit time (default is 0)
    $elapsed = microtime(true) - $wgRequestTime;
    if ($elapsed <= $wgProfileLimit) {
        return;
    }
    $profiler->logData();
    // Check whether this should be logged in the debug file.
    if ($wgDebugLogFile == '' || !$wgDebugRawPage && wfIsDebugRawPage()) {
        return;
    }
    $forward = '';
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
    }
    if (!empty($_SERVER['HTTP_FROM'])) {
        $forward .= ' from ' . $_SERVER['HTTP_FROM'];
    }
    if ($forward) {
        $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
    }
    // Don't load $wgUser at this late stage just for statistics purposes
    // @todo FIXME: We can detect some anons even if it is not loaded. See User::getId()
    if ($wgUser->isItemLoaded('id') && $wgUser->isAnon()) {
        $forward .= ' anon';
    }
    // Wikia change - begin - FauxRequest::getRequestURL() is not implemented and throws exception
    // in maintenance scripts
    try {
        $log = sprintf("%s\t%04.3f\t%s\n", gmdate('YmdHis'), $elapsed, urldecode($wgRequest->getRequestURL() . $forward));
        wfErrorLog($log . $profiler->getOutput(), $wgDebugLogFile);
    } catch (MWException $e) {
        // double-check it is the case
        if ($e->getMessage() !== "FauxRequest::getRequestURL() not implemented") {
            throw $e;
        }
    }
    // Wikia change - end
}