-
Notifications
You must be signed in to change notification settings - Fork 6
/
wp-xhprof.php
59 lines (44 loc) · 1.48 KB
/
wp-xhprof.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
<?php
/*
Plugin Name: WP XHProf
Description: Allows profiling WordPress using Facebook's XHProf Profiler extension.
Version: 0.1
Author: Stefan Fisk
Author URI: http://stefanfisk.com
License: MIT
*/
class SF_XHProfProfiler {
private $loader = null;
private $namespace = 'oliverocheva';
function __construct()
{
global $sf_xhprof_loader;
if (isset($sf_xhprof_loader)) $this->loader = $sf_xhprof_loader;
if (!$this->is_started()) return;
add_action('shutdown', array($this, 'stop_profiling'));
}
function is_started()
{
return $this->loader && $this->loader->is_started();
}
function profile_url($run_id, $namespace = null)
{
if (!$namespace) $namespace = $this->namespace;
$relative_url = sprintf('xhprof/xhprof_html/index.php?run=%s&source=%s', urlencode($run_id), urlencode($namespace));
return plugins_url($relative_url , __FILE__ );
}
function stop_profiling()
{
include_once('xhprof/xhprof_lib/utils/xhprof_lib.php');
include_once('xhprof/xhprof_lib/utils/xhprof_runs.php');
$xhprof_data = $this->loader->stop();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $this->namespace);
?>
<div style="padding: 1em;">
<a href="<?php echo esc_attr($this->profile_url($run_id)); ?>" target="_blank">Profiler output</a>
</div>
<?php
}
}
new SF_XHProfProfiler();