header( 'X-Content-Type-Options: nosniff' );
$wgRequestTime = microtime( true );
-# getrusage() does not exist on the Microsoft Windows platforms, catching this
-$wgRUstart = function_exists( 'getrusage' ) ? getrusage() : array();
unset( $IP );
# Valid web server entry point, enable includes.
$IP = realpath( '.' ) ?: dirname( __DIR__ );
}
-# Start the autoloader, so that extensions can derive classes from core files
-require_once "$IP/includes/AutoLoader.php";
-
# Load the profiler
require_once "$IP/includes/profiler/Profiler.php";
+$wgRUstart = wfGetRusage() ?: array();
+
+# Start the autoloader, so that extensions can derive classes from core files
+require_once "$IP/includes/AutoLoader.php";
# Load up some global defines.
require_once "$IP/includes/Defines.php";
if ( !$clock || $clock === 'wall' ) {
$ret['wall'] = microtime( true );
}
- if ( ( !$clock || $clock === 'cpu' ) && function_exists( 'getrusage' ) ) {
- $ru = getrusage();
- $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
- $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+ if ( !$clock || $clock === 'cpu' ) {
+ $ru = wfGetRusage();
+ if ( $ru ) {
+ $ret['cpu'] = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
+ $ret['cpu'] += $ru['ru_stime.tv_sec'] + $ru['ru_stime.tv_usec'] / 1e6;
+ }
}
return $ret;
}
* @file
* @ingroup Profiler
* @defgroup Profiler Profiler
- * This file is only included if profiling is enabled
*/
+/**
+ * Get system resource usage of current request context.
+ * Invokes the getrusage(2) system call, requesting RUSAGE_SELF if on PHP5
+ * or RUSAGE_THREAD if on HHVM. Returns false if getrusage is not available.
+ *
+ * @since 1.24
+ * @return array|bool Resource usage data or false if no data available.
+ */
+function wfGetRusage() {
+ if ( !function_exists( 'getrusage' ) ) {
+ return false;
+ } elseif ( defined ( 'HHVM_VERSION' ) ) {
+ return getrusage( 2 /* RUSAGE_THREAD */ );
+ } else {
+ return getrusage( 0 /* RUSAGE_SELF */ );
+ }
+}
+
/**
* Begin profiling of a function
* @param string $functionname Name of the function we will profile
*/
protected function getTime( $metric = 'wall' ) {
if ( $metric === 'cpu' || $metric === 'user' ) {
- if ( !function_exists( 'getrusage' ) ) {
+ $ru = wfGetRusage();
+ if ( !$ru ) {
return 0;
}
- $ru = getrusage();
$time = $ru['ru_utime.tv_sec'] + $ru['ru_utime.tv_usec'] / 1e6;
if ( $metric === 'cpu' ) {
# This is the time of system calls, added to the user time