3 * Core profiling functions. Have to exist before basically anything.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Get system resource usage of current request context.
26 * Invokes the getrusage(2) system call, requesting RUSAGE_SELF if on PHP5
27 * or RUSAGE_THREAD if on HHVM. Returns false if getrusage is not available.
30 * @return array|bool Resource usage data or false if no data available.
32 function wfGetRusage() {
33 if ( !function_exists( 'getrusage' ) ) {
35 } elseif ( defined ( 'HHVM_VERSION' ) ) {
36 return getrusage( 2 /* RUSAGE_THREAD */ );
38 return getrusage( 0 /* RUSAGE_SELF */ );
43 * Begin profiling of a function
44 * @param string $functionname Name of the function we will profile
46 function wfProfileIn( $functionname ) {
47 // Use Profiler member variable directly to reduce overhead
48 if ( Profiler
::$__instance === null ) {
51 if ( !( Profiler
::$__instance instanceof ProfilerStub
) ) {
52 Profiler
::$__instance->profileIn( $functionname );
57 * Stop profiling of a function
58 * @param string $functionname Name of the function we have profiled
60 function wfProfileOut( $functionname = 'missing' ) {
61 // Use Profiler member variable directly to reduce overhead
62 if ( Profiler
::$__instance === null ) {
65 if ( !( Profiler
::$__instance instanceof ProfilerStub
) ) {
66 Profiler
::$__instance->profileOut( $functionname );