|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
4
|
|
|
* it under the terms of the GNU General Public License as published by |
|
5
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
6
|
|
|
* (at your option) any later version. |
|
7
|
|
|
* |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11
|
|
|
* GNU General Public License for more details. |
|
12
|
|
|
* |
|
13
|
|
|
* You should have received a copy of the GNU General Public License along |
|
14
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
15
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
|
17
|
|
|
* |
|
18
|
|
|
* @file |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Convenience class for working with XHProf |
|
23
|
|
|
* <https://github.com/phacility/xhprof>. XHProf can be installed as a PECL |
|
24
|
|
|
* package for use with PHP5 (Zend PHP) and is built-in to HHVM 3.3.0. |
|
25
|
|
|
* |
|
26
|
|
|
* @since 1.28 |
|
27
|
|
|
*/ |
|
28
|
|
|
class Xhprof { |
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool $enabled Whether XHProf is currently running. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected static $enabled; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Start xhprof profiler |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function isEnabled() { |
|
38
|
|
|
return self::$enabled; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Start xhprof profiler |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function enable( $flags = 0, $options = [] ) { |
|
45
|
|
|
if ( self::isEnabled() ) { |
|
46
|
|
|
throw new Exception( 'Xhprof profiling is already enabled.' ); |
|
47
|
|
|
} |
|
48
|
|
|
self::$enabled = true; |
|
49
|
|
|
xhprof_enable( $flags, $options ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Stop xhprof profiler |
|
54
|
|
|
* |
|
55
|
|
|
* @return array|null xhprof data from the run, or null if xhprof was not running. |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function disable() { |
|
58
|
|
|
if ( self::isEnabled() ) { |
|
59
|
|
|
self::$enabled = false; |
|
60
|
|
|
return xhprof_disable(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|