Merge "Schema is not PostgreSQL connection parameter"
[lhc/web/wiklou.git] / includes / profiler / ProfilerFunctions.php
1 <?php
2 /**
3 * Core profiling functions. Have to exist before basically anything.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Profiler
22 */
23
24 /**
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.
28 *
29 * @since 1.24
30 * @return array|bool Resource usage data or false if no data available.
31 */
32 function wfGetRusage() {
33 if ( !function_exists( 'getrusage' ) ) {
34 return false;
35 } elseif ( defined ( 'HHVM_VERSION' ) ) {
36 return getrusage( 2 /* RUSAGE_THREAD */ );
37 } else {
38 return getrusage( 0 /* RUSAGE_SELF */ );
39 }
40 }
41
42 /**
43 * Begin profiling of a function
44 * @param string $functionname Name of the function we will profile
45 */
46 function wfProfileIn( $functionname ) {
47 // Use Profiler member variable directly to reduce overhead
48 if ( Profiler::$__instance === null ) {
49 Profiler::instance();
50 }
51 if ( !( Profiler::$__instance instanceof ProfilerStub ) ) {
52 Profiler::$__instance->profileIn( $functionname );
53 }
54 }
55
56 /**
57 * Stop profiling of a function
58 * @param string $functionname Name of the function we have profiled
59 */
60 function wfProfileOut( $functionname = 'missing' ) {
61 // Use Profiler member variable directly to reduce overhead
62 if ( Profiler::$__instance === null ) {
63 Profiler::instance();
64 }
65 if ( !( Profiler::$__instance instanceof ProfilerStub ) ) {
66 Profiler::$__instance->profileOut( $functionname );
67 }
68 }