/** * This method gets called by self::filter() */ public static function doLog($method, array $values, &$output) { switch ($method) { case 'apache': foreach ($values as $varName => $value) { /// @todo should remove any " or space chars in the value for proper parsing by updateperfstats.php apache_note($varName, $value); } break; case 'piwik': $text = ''; foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) { $text .= "\npiwikTracker.setCustomVariable( {$i}, \"{$var}\", \"{$values[$var]}\", \"page\" );"; } $text .= "\npiwikTracker.trackPageView();"; $output = preg_replace('/piwikTracker\\.trackPageView\\( *\\);?/', $text, $output); break; case 'googleanalytics': $text = ''; foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) { $text .= "\n_gaq.push([{$i}, '{$var}', '{$values[$var]}', 3]);"; } $text .= "\n_gaq.push(['_trackPageview']);"; $output = preg_replace("/_gaq.push\\( *[ *['\"]_trackPageview['\"] *] *\\);?/", $text, $output); break; case 'logfile': case 'syslog': /// same format as Apache "combined" by default $size = self::$outputSize; if ($size == 0) { $size = '-'; } $text = eZPerfLoggerApacheLogger::apacheLogLine('combined', $size, self::$returnCode) . ' '; foreach ($values as $value) { // do same as apache does: replace nulls with "-" if ((string) $value === '') { $text .= "- "; } else { /// @todo should remove any " or space chars in the value for proper parsing by updateperfstats.php $text .= $value . " "; } } if ($method == 'logfile') { $text .= "\n"; file_put_contents(eZPerfLoggerINI::variable('logfileSettings', 'FileName'), $text, FILE_APPEND); } else { // syslog: we use apache log format for lack of a better idea... openlog("eZPerfLog", LOG_PID, LOG_USER); syslog(LOG_INFO, $text); } break; case 'headers': $prefix = eZPerfLoggerINI::variable('HeadersSettings', 'HeaderPrefix'); foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $i => $var) { header($prefix . str_replace(array('(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', "\t"), '-', $var) . ': ' . $values[$var]); } break; case 'database': case 'csv': case 'storage': if ($method == 'csv') { $storageClass = 'eZPerfLoggerCSVStorage'; } else { if ($method == 'database') { $storageClass = 'eZPerfLoggerDBStorage'; } else { $storageClass = eZPerfLoggerINI::variable('ParsingSettings', 'StorageClass'); } } /// @todo log error if storage class does not implement correct interface // when we deprecate php 5.2, we will be able to use $storageClass::insertStats... call_user_func(array($storageClass, 'insertStats'), array(array('url' => isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : $_SERVER["PHP_SELF"], 'ip' => is_callable('eZSys::clientIP') ? eZSys::clientIP() : eZSys::serverVariable('REMOTE_ADDR'), 'time' => time(), 'response_status' => self::$returnCode, 'response_size' => self::$outputSize, 'counters' => $values))); break; /// @todo !important log a warning for default case (unhandled log format) } }
unset($params[$k]); } } ////echo "<html>"; ////echo "<head><title>XHProf: Hierarchical Profiler Report</title>"; ////xhprof_include_js_css(); ////echo "</head>"; ////echo "<body>"; $vbar = ' class="vbar"'; $vwbar = ' class="vwbar"'; $vwlbar = ' class="vwlbar"'; $vbbar = ' class="vbbar"'; $vrbar = ' class="vrbar"'; $vgbar = ' class="vgbar"'; $xhprof_runs_impl = new XHProfRuns_Default(eZXHProfLogger::logDir()); displayXHProfReport($xhprof_runs_impl, $params, $GLOBALS['source'], $GLOBALS['run'], $GLOBALS['wts'], $GLOBALS['symbol'], $GLOBALS['sort'], $GLOBALS['run1'], $GLOBALS['run2']); ////echo "</body>"; ////echo "</html>"; $body = ob_get_clean(); $info = false; $infoFile = eZXHProfLogger::logDir() . "/{$GLOBALS['run']}.info"; if (file_exists($infoFile)) { $info = eZPerfLoggerApacheLogger::parseLogLine(file_get_contents($infoFile)); } $tpl = eZTemplate::factory(); $tpl->setVariable('body', $body); $tpl->setVariable('error', $error); $tpl->setVariable('run', $GLOBALS['run']); $tpl->setVariable('info', $info); $Result['content'] = $tpl->fetch('design:xhprof/view.tpl'); $Result['path'] = array(array('text' => 'XHProf', 'url' => 'xhprof/list'), array('text' => 'Run: ' . $GLOBALS['run'], 'url' => 'xhprof/view?run=' . $GLOBALS['run']));
/** * Returns list of saved runs * @return array * 'list' => array( '<runkey>' => array( 'time' => <run timestamp>, ... ) ) * 'count' => total available runs */ public static function savedRuns($offset = 0, $limit = 0) { $runsList = array(); $count = 0; if (!is_dir(self::logDir())) { return array($runsList, $count); } // nb: PHP_SCANDIR_SORT_DESCENDING === 1, but only defined since php 5.4.0 foreach (scandir(self::logDir(), 1) as $file) { $fullfile = self::logDir() . "/" . $file; if (is_file($fullfile) && substr($file, -7) == '.xhprof') { $count++; if ($count >= $offset && ($limit <= 0 || count($runsList) <= $limit)) { $run = substr($file, 0, -7); $runsList[$run] = array('time' => filemtime($fullfile)); if (is_file($infoFile = self::logDir() . "/{$run}.info")) { if (is_array($info = eZPerfLoggerApacheLogger::parseLogLine(file_get_contents($infoFile)))) { $runsList[$run] = $info; } } } } } return array($runsList, $count); }