-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlrpc-memory-usage.php
More file actions
55 lines (46 loc) · 1.3 KB
/
xmlrpc-memory-usage.php
File metadata and controls
55 lines (46 loc) · 1.3 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
<?php
/*
* Plugin Name: XML-RPC Memory Usage
* Description: Logs memory usage during XML-RPC handling.
* Version: 1.0
* Author: Max Cutler
* Author URI: http://www.maxcutler.com
*
*/
if ( defined( 'XMLRPC_REQUEST' ) ) {
function xmu_log_usage( $label, $peak = false ) {
$usage = $peak ? memory_get_peak_usage() : memory_get_usage();
$usage_mb = round($usage / 1048576, 2);
error_log( '[' . $label . ']: ' . $usage . ' (' .$usage_mb . ' MiB)' );
}
function xmu_start() {
xmu_log_usage( 'XML-RPC Loaded' );
}
function xmu_xmlrpc_call( $method_name ) {
xmu_log_usage( 'XML-RPC Call, ' . $method_name );
}
function xmu_prepare( $val ) {
$filter = current_filter();
xmu_log_usage( 'XML-RPC Filter, ' . $filter );
return $val;
}
function xmu_shutdown() {
xmu_log_usage( 'XML-RPC Shutdown' );
xmu_log_usage( 'XML-RPC Peak', true );
}
add_action( 'plugins_loaded', 'xmu_start', 1 );
add_action( 'xmlrpc_call', 'xmu_xmlrpc_call', 10, 1 );
add_action( 'shutdown', 'xmu_shutdown' );
$prepare_filters = array(
'xmlrpc_prepare_taxonomy',
'xmlrpc_prepare_term',
'xmlrpc_prepare_post',
'xmlrpc_prepare_post_type',
'xmlrpc_prepare_media_item',
'xmlrpc_prepare_page',
'xmlrpc_prepare_comment'
);
foreach ( $prepare_filters as $filter ) {
add_filter( $filter, 'xmu_prepare', 100, 1 );
}
}