/** *** get_performance_info() pairs up with init_performance_info() *** loaded in setup.php. Returns an array with 'html' and 'txt' *** values ready for use, and each of the individual stats provided *** separately as well. *** **/ function get_performance_info() { global $CFG, $PERF, $rcache; $info = array(); $info['html'] = ''; // holds userfriendly HTML representation $info['txt'] = me() . ' '; // holds log-friendly representation $info['realtime'] = microtime_diff($PERF->starttime, microtime()); $info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> '; $info['txt'] .= 'time: ' . $info['realtime'] . 's '; if (function_exists('memory_get_usage')) { $info['memory_total'] = memory_get_usage(); $info['memory_growth'] = memory_get_usage() - $PERF->startmemory; $info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> '; $info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') '; } if (function_exists('memory_get_peak_usage')) { $info['memory_peak'] = memory_get_peak_usage(); $info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> '; $info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') '; } $inc = get_included_files(); //error_log(print_r($inc,1)); $info['includecount'] = count($inc); $info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> '; $info['txt'] .= 'includecount: ' . $info['includecount'] . ' '; if (!empty($PERF->dbqueries)) { $info['dbqueries'] = $PERF->dbqueries; $info['html'] .= '<span class="dbqueries">DB queries ' . $info['dbqueries'] . '</span> '; $info['txt'] .= 'dbqueries: ' . $info['dbqueries'] . ' '; } if (!empty($PERF->logwrites)) { $info['logwrites'] = $PERF->logwrites; $info['html'] .= '<span class="logwrites">Log writes ' . $info['logwrites'] . '</span> '; $info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' '; } if (!empty($PERF->profiling) && $PERF->profiling) { require_once $CFG->dirroot . '/lib/profilerlib.php'; $info['html'] .= '<span class="profilinginfo">' . Profiler::get_profiling(array('-R')) . '</span>'; } if (function_exists('posix_times')) { $ptimes = posix_times(); if (is_array($ptimes)) { foreach ($ptimes as $key => $val) { $info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key]; } $info['html'] .= "<span class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</span> "; $info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} "; } } // Grab the load average for the last minute // /proc will only work under some linux configurations // while uptime is there under MacOSX/Darwin and other unices if (is_readable('/proc/loadavg') && ($loadavg = @file('/proc/loadavg'))) { list($server_load) = explode(' ', $loadavg[0]); unset($loadavg); } else { if (function_exists('is_executable') && is_executable('/usr/bin/uptime') && ($loadavg = `/usr/bin/uptime`)) { if (preg_match('/load averages?: (\\d+[\\.,:]\\d+)/', $loadavg, $matches)) { $server_load = $matches[1]; } else { trigger_error('Could not parse uptime output!'); } } } if (!empty($server_load)) { $info['serverload'] = $server_load; $info['html'] .= '<span class="serverload">Load average: ' . $info['serverload'] . '</span> '; $info['txt'] .= "serverload: {$info['serverload']} "; } if (isset($rcache->hits) && isset($rcache->misses)) { $info['rcachehits'] = $rcache->hits; $info['rcachemisses'] = $rcache->misses; $info['html'] .= '<span class="rcache">Record cache hit/miss ratio : ' . "{$rcache->hits}/{$rcache->misses}</span> "; $info['txt'] .= 'rcache: ' . "{$rcache->hits}/{$rcache->misses} "; } $info['html'] = '<div class="performanceinfo">' . $info['html'] . '</div>'; return $info; }
/** * get_performance_info() pairs up with init_performance_info() * loaded in setup.php. Returns an array with 'html' and 'txt' * values ready for use, and each of the individual stats provided * separately as well. * * @global object * @global object * @global object * @return array */ function get_performance_info() { global $CFG, $PERF, $DB, $PAGE; $info = array(); $info['html'] = ''; // holds userfriendly HTML representation $info['txt'] = me() . ' '; // holds log-friendly representation $info['realtime'] = microtime_diff($PERF->starttime, microtime()); $info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> '; $info['txt'] .= 'time: ' . $info['realtime'] . 's '; if (function_exists('memory_get_usage')) { $info['memory_total'] = memory_get_usage(); $info['memory_growth'] = memory_get_usage() - $PERF->startmemory; $info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> '; $info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') '; } if (function_exists('memory_get_peak_usage')) { $info['memory_peak'] = memory_get_peak_usage(); $info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> '; $info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') '; } $inc = get_included_files(); //error_log(print_r($inc,1)); $info['includecount'] = count($inc); $info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> '; $info['txt'] .= 'includecount: ' . $info['includecount'] . ' '; $filtermanager = filter_manager::instance(); if (method_exists($filtermanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $filtermanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $stringmanager = get_string_manager(); if (method_exists($stringmanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $stringmanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $jsmodules = $PAGE->requires->get_loaded_modules(); if ($jsmodules) { $yuicount = 0; $othercount = 0; $details = ''; foreach ($jsmodules as $module => $backtraces) { if (strpos($module, 'yui') === 0) { $yuicount += 1; } else { $othercount += 1; } $details .= "<div class='yui-module'><p>{$module}</p>"; foreach ($backtraces as $backtrace) { $details .= "<div class='backtrace'>{$backtrace}</div>"; } $details .= '</div>'; } $info['html'] .= "<span class='includedyuimodules'>Included YUI modules: {$yuicount}</span> "; $info['txt'] .= "includedyuimodules: {$yuicount} "; $info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: {$othercount}</span> "; $info['txt'] .= "includedjsmodules: {$othercount} "; // Slightly odd to output the details in a display: none div. The point // Is that it takes a lot of space, and if you care you can reveal it // using firebug. $info['html'] .= '<div id="yui-module-debug" class="notifytiny">' . $details . '</div>'; } if (!empty($PERF->logwrites)) { $info['logwrites'] = $PERF->logwrites; $info['html'] .= '<span class="logwrites">Log DB writes ' . $info['logwrites'] . '</span> '; $info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' '; } $info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites); $info['html'] .= '<span class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</span> '; $info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' '; if (!empty($PERF->profiling) && $PERF->profiling) { require_once $CFG->dirroot . '/lib/profilerlib.php'; $info['html'] .= '<span class="profilinginfo">' . Profiler::get_profiling(array('-R')) . '</span>'; } if (function_exists('posix_times')) { $ptimes = posix_times(); if (is_array($ptimes)) { foreach ($ptimes as $key => $val) { $info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key]; } $info['html'] .= "<span class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</span> "; $info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} "; } } // Grab the load average for the last minute // /proc will only work under some linux configurations // while uptime is there under MacOSX/Darwin and other unices if (is_readable('/proc/loadavg') && ($loadavg = @file('/proc/loadavg'))) { list($server_load) = explode(' ', $loadavg[0]); unset($loadavg); } else { if (function_exists('is_executable') && is_executable('/usr/bin/uptime') && ($loadavg = `/usr/bin/uptime`)) { if (preg_match('/load averages?: (\\d+[\\.,:]\\d+)/', $loadavg, $matches)) { $server_load = $matches[1]; } else { trigger_error('Could not parse uptime output!'); } } } if (!empty($server_load)) { $info['serverload'] = $server_load; $info['html'] .= '<span class="serverload">Load average: ' . $info['serverload'] . '</span> '; $info['txt'] .= "serverload: {$info['serverload']} "; } // Display size of session if session started if (session_id()) { $info['sessionsize'] = display_size(strlen(session_encode())); $info['html'] .= '<span class="sessionsize">Session: ' . $info['sessionsize'] . '</span> '; $info['txt'] .= "Session: {$info['sessionsize']} "; } /* if (isset($rcache->hits) && isset($rcache->misses)) { $info['rcachehits'] = $rcache->hits; $info['rcachemisses'] = $rcache->misses; $info['html'] .= '<span class="rcache">Record cache hit/miss ratio : '. "{$rcache->hits}/{$rcache->misses}</span> "; $info['txt'] .= 'rcache: '. "{$rcache->hits}/{$rcache->misses} "; }*/ $info['html'] = '<div class="performanceinfo siteinfo">' . $info['html'] . '</div>'; return $info; }