-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdebug-profiling.php
More file actions
60 lines (58 loc) · 1.58 KB
/
debug-profiling.php
File metadata and controls
60 lines (58 loc) · 1.58 KB
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
/*
* Plugin Name: Profiling (DBG)
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*/
// Output time and memory usage.
array_map(
static function ($hook) {
add_action(
$hook,
static function () use ($hook) {
if (
php_sapi_name() === 'cli'
|| wp_doing_cron()
|| wp_doing_ajax()
|| wp_is_json_request()
|| is_admin()
) {
return;
}
$time = timer_float();
$mem = round(memory_get_usage(false) / 1048576, 0);
add_action(
'shutdown',
static function () use ($hook, $time, $mem) {
if (is_robots() || wp_doing_ajax()) {
return;
}
printf(
'%c<!-- Profiling: [%.03f] %s - mem %d MB -->',
10,
$time,
$hook,
$mem
);
},
11,
0
);
},
PHP_INT_MAX,
0
);
},
[
'plugins_loaded',
'setup_theme',
'after_setup_theme',
'init',
'wp_loaded',
'send_headers',
'template_redirect',
'wp_head',
'loop_start',
'loop_end',
'wp_footer',
]
);