-
Notifications
You must be signed in to change notification settings - Fork 6
/
xhprof-loader.php
60 lines (48 loc) · 1.19 KB
/
xhprof-loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class SF_XHProfLoader {
private $started = false;
function xhprof_is_enabled()
{
return extension_loaded('xhprof');
}
function should_profile_current_request()
{
return $this->xhprof_is_enabled();
}
function flags()
{
return XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY;
}
function options()
{
return array(
'ignored_functions' => array(
'call_user_func',
'call_user_func_array',
'preg_replace_callback',
'do_action',
'apply_filters',
)
);
}
function start($flags = SFHXPROF_FLAGS)
{
if (!$this->xhprof_is_enabled())
{
error_log('Failed to start profiling, the xhprof is not loaded.');
return;
}
xhprof_enable($this->flags(), $this->options());
$this->started = true;
}
function is_started()
{
return $this->started;
}
function stop()
{
return xhprof_disable();
}
}
$sf_xhprof_loader = new SF_XHProfLoader();
if ($sf_xhprof_loader->should_profile_current_request()) $sf_xhprof_loader->start();