PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
1.9.6 1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 All 41 releases
← All changes | lib/class-profiler.php +58 -3 1.6.61.9.6 View file →
@@ -6,9 +6,9 @@
6 6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 9 | |
10 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
10 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
11 11 +=====================================================================+
12 12 */
13 13
14 14 if (! defined('ABSPATH') ) { die('Forbidden'); }
@@ -22,12 +22,15 @@
22 22 static $metrics;
23 23 static $fh;
24 24 static $connections_list = [];
25 25 static $connections_start;
26 + static $exclusions = [];
26 27 private $tmp_iostats;
27 28 private $tmp_summary;
28 29 private $tmp_diskio;
29 30 private $tmp_calls;
31 + private $tmp_connections;
32 + private $tmp_rerun;
30 33
31 34 /**
32 35 * Initialize
33 36 */
@@ -44,8 +47,10 @@
44 47 $this->tmp_diskio = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
45 48 CODE_PROFILER_TMP_DISKIO_LOG;
46 49 $this->tmp_connections = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
47 50 CODE_PROFILER_TMP_CONNECTIONS_LOG;
51 + $this->tmp_rerun = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
52 + CODE_PROFILER_TMP_RERUN_LOG;
48 53
49 54 if ( function_exists('hrtime') ) {
50 55 // PHP >=7.3
51 56 self::$metrics = 'hrtime';
@@ -52,8 +57,45 @@
52 57 } else {
53 58 self::$metrics = 'microtime';
54 59 }
55 60
61 + // Select theme (stylesheet::template)
62 + if (! empty( $_SERVER['HTTP_THEME'] ) ) {
63 +
64 + $theme = explode('::', $_SERVER['HTTP_THEME'] );
65 + if (! empty( $theme[1] ) ) {
66 + define('CODE_PROFILER_STYLESHEET', sanitize_file_name( $theme[0] ) );
67 + define('CODE_PROFILER_TEMPLATE', sanitize_file_name( $theme[1] ) );
68 +
69 + if ( is_file( WP_CONTENT_DIR .'/themes/'. CODE_PROFILER_STYLESHEET .'/style.css' ) ) {
70 +
71 + add_filter('pre_option_template', function () {
72 + return CODE_PROFILER_TEMPLATE;
73 + }, 1000 );
74 +
75 + add_filter('pre_option_stylesheet', function () {
76 + return CODE_PROFILER_STYLESHEET;
77 + }, 1000 );
78 +
79 + code_profiler_log_debug(
80 + sprintf(
81 + // We cannot load translation here.
82 + 'Setting theme to %s',
83 + CODE_PROFILER_STYLESHEET
84 + )
85 + );
86 + } else {
87 + code_profiler_log_error(
88 + sprintf(
89 + // We cannot load translation here.
90 + 'Unable to switch theme, %s not found',
91 + CODE_PROFILER_STYLESHEET
92 + )
93 + );
94 + }
95 + }
96 + }
97 +
56 98 $cp_options = get_option('code-profiler');
57 99 if ( empty( $cp_options['accuracy'] ) ) {
58 100 define('CODE_PROFILER_TICKS', 1 );
59 101 } else {
@@ -70,18 +112,25 @@
70 112 self::$buffer = $cp_options['buffer'] * 1000000;
71 113 }
72 114 code_profiler_log_debug(
73 115 sprintf(
74 - esc_html__('Setting size of memory buffer to %sMB', 'code-profiler'),
116 + // We cannot load translation here.
117 + 'Setting size of memory buffer to %sMB',
75 118 self::$buffer / 1000000
76 119 )
77 120 );
78 121
122 + // File & folder exclusions
123 + if ( isset( $cp_options['exclusions'] ) ) {
124 + self::$exclusions = json_decode( $cp_options['exclusions'] );
125 + }
126 +
79 127 add_filter('pre_http_request', [ $this, 'pre_http_request'], 10000, 3 );
80 128 add_action('http_api_debug', [ $this, 'http_api_debug'], 10000, 5 );
81 129 register_shutdown_function( [ $this, 'code_profiler_shutdown'] );
82 130 code_profiler_log_debug(
83 - esc_html__('Starting profiler', 'code-profiler')
131 + // We cannot load translation here.
132 + 'Starting profiler'
84 133 );
85 134 require 'class-stream.php';
86 135
87 136 // Clear the temporary log because the buffer will be appended to it
@@ -102,8 +151,14 @@
102 151 CodeProfiler_Stream::stop();
103 152
104 153 fclose( self::$fh );
105 154
155 + // Summary file (metadata)
156 + $summary = [];
157 + if ( is_file( $this->tmp_rerun ) ) {
158 + $summary['rerun'] = json_decode( file_get_contents( $this->tmp_rerun ), true );
159 + unlink( $this->tmp_rerun );
160 + }
106 161 $summary['memory'] = memory_get_peak_usage();
107 162 $summary['queries'] = get_num_queries() - 2;
108 163 $summary['precision'] = CODE_PROFILER_TICKS;
109 164 file_put_contents( $this->tmp_summary, json_encode( $summary ) );