PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.7.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.7.4
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 1.6.8 All 40 releases
← All changes | lib/class-report.php +44 -30 1.6.41.7.4 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'); }
@@ -35,9 +35,9 @@
35 35 private $tmp_iostats;
36 36 private $tmp_summary;
37 37 private $tmp_diskio;
38 38 private $tmp_connections;
39 - private $tmp_ticks;
39 + private $tmp_calls;
40 40
41 41
42 42 /**
43 43 * Initialize
@@ -47,10 +47,10 @@
47 47 $this->tmp_summary = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
48 48 CODE_PROFILER_TMP_SUMMARY_LOG;
49 49 $this->tmp_iostats = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
50 50 CODE_PROFILER_TMP_IOSTATS_LOG;
51 - $this->tmp_ticks = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
52 - CODE_PROFILER_TMP_TICKS_LOG;
51 + $this->tmp_calls = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
52 + CODE_PROFILER_TMP_CALLS_LOG;
53 53 $this->tmp_diskio = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
54 54 CODE_PROFILER_TMP_DISKIO_LOG;
55 55 $this->tmp_connections = CODE_PROFILER_UPLOAD_DIR ."/$microtime." .
56 56 CODE_PROFILER_TMP_CONNECTIONS_LOG;
@@ -57,29 +57,26 @@
57 57 // Used for naming, not metrics
58 58 $this->microtime = $microtime;
59 59
60 60 // Make sure all files are there
61 - if (! file_exists( $this->tmp_ticks ) ) {
62 - $cp_error = 1;
61 + if (! file_exists( $this->tmp_calls ) ) {
62 + $cp_error = 'calls';
63 63 } elseif (! file_exists( $this->tmp_iostats ) ) {
64 - $cp_error = 2;
64 + $cp_error = 'iostats';
65 65 }
66 66 if (! empty( $cp_error ) ) {
67 67 $error = sprintf(
68 - esc_html__('Cannot create the report: the profiler did not '.
69 - 'generate a data file (#%s). Make sure the following directory '.
70 - 'is writable: %s. If you are using a caching plugin or an '.
71 - 'opcode cache, try to disable it. You may also find more '.
72 - 'details about the error in the "Log" tab.', 'code-profiler'),
73 - $cp_error,
74 - CODE_PROFILER_UPLOAD_DIR .'/'
75 - );
68 + esc_html__('Cannot create the report: the profiler did not generate a data file (%s). '.
69 + 'You may find more details about this error in the "Log" tab or your PHP error log.',
70 + 'code-profiler'),
71 + $cp_error
72 + );
76 73 $this->return_error( $error );
77 74 }
78 75
79 76 // Total data analyzed
80 77 $this->parsed_data += filesize( $this->tmp_iostats );
81 - $this->parsed_data += filesize( $this->tmp_ticks );
78 + $this->parsed_data += filesize( $this->tmp_calls );
82 79
83 80 $this->profile_name = $profile_name;
84 81 $this->plugins_dir = preg_quote( realpath( WP_PLUGIN_DIR ) );
85 82 $this->themes_dir = preg_quote( realpath( WP_CONTENT_DIR .'/themes') );
@@ -91,9 +88,9 @@
91 88 * Filter and save the profiler's data
92 89 */
93 90 public function prepare_report() {
94 91
95 - $this->parse_ticks();
92 + $this->parse_calls();
96 93 $this->get_plugins_theme_name();
97 94 $this->save_iostats();
98 95 $this->save_connections();
99 96 $this->save_data();
@@ -192,22 +189,25 @@
192 189 // Summary
193 190 $s = json_decode( file_get_contents( $this->tmp_summary ), true );
194 191 unlink( $this->tmp_summary );
195 192 if ( empty( $s['memory'] ) ) {
196 - $this->summary_list['memory'] = '-';
193 + $this->summary_list['memory'] = 0;
197 194 } else {
198 195 $this->summary_list['memory'] = $s['memory'] / 1024 / 1024;
199 196 }
200 197 if ( empty( $s['queries'] ) ) {
201 - $this->summary_list['queries']= '-';
198 + $this->summary_list['queries']= 0;
202 199 } else {
203 200 $this->summary_list['queries']= $s['queries'];
204 201 }
205 202 if ( empty( $this->total_io ) ) {
206 - $this->summary_list['io'] = '-';
203 + $this->summary_list['io'] = 0;
207 204 } else {
208 205 $this->summary_list['io'] = $this->total_io;
209 206 }
207 + if (! empty( $s['precision'] ) ) {
208 + $this->summary_list['precision'] = $s['precision'];
209 + }
210 210 $this->summary_list['items'] = $this->total_plugins + 1; // Add the theme
211 211 $this->summary_list['time'] = $this->convert_2_seconds( $this->summary_list['time'] );
212 212 $this->summary_list['time'] = number_format( $this->summary_list['time'], 4 );
213 213
@@ -315,15 +315,15 @@
315 315
316 316 /**
317 317 * Parse, filter and sort the data
318 318 */
319 - private function parse_ticks() {
319 + private function parse_calls() {
320 320
321 - $fh = fopen( $this->tmp_ticks, 'rb');
321 + $fh = fopen( $this->tmp_calls, 'rb');
322 322 if ( $fh === false ) {
323 323 $error = sprintf(
324 324 esc_html__('Cannot open file for reading: %s', 'code-profiler'),
325 - $this->tmp_ticks
325 + $this->tmp_calls
326 326 );
327 327 $this->return_error( $error );
328 328 }
329 329 while(! feof( $fh ) ) {
@@ -426,9 +426,9 @@
426 426 }
427 427 }
428 428
429 429 fclose( $fh );
430 - unlink( $this->tmp_ticks );
430 + unlink( $this->tmp_calls );
431 431 }
432 432
433 433 /********************************************************************
434 434 * Save IO stats
@@ -507,13 +507,15 @@
507 507 return;
508 508 }
509 509
510 510 foreach( $connections as $connection => $array ) {
511 - $found = 0;
511 + $found_call = 0;
512 + $found_caller = 0;
512 513
513 514 foreach( $array['bt'] as $k =>$v ) {
514 515 if ( isset( $v['file'] ) && isset( $v['function'] ) && isset( $v['line'] ) ) {
515 - if ( ! $found &&
516 +
517 + if (! $found_caller && ( $found_call ||
516 518 in_array( $v['function'], [
517 519 'wp_remote_get',
518 520 'wp_safe_remote_get',
519 521 'wp_remote_post',
@@ -518,19 +520,31 @@
518 520 'wp_safe_remote_get',
519 521 'wp_remote_post',
520 522 'wp_safe_remote_post'
521 523 ] )
522 - ) {
523 - $found = 1;
524 + ) ) {
524 525
526 + $found_call = 1;
527 +
525 528 $type = $this->plugin_or_theme( $v['file'] );
529 +
526 530 if (! empty( $type['theme'] ) ) {
527 531 // Save it for later use
528 - $this->cx_buffer['theme'][ $type['theme'] ] = $array['stop'] - $connection;
532 + if ( isset( $this->cx_buffer['theme'][ $type['theme'] ] ) ) {
533 + $this->cx_buffer['theme'][ $type['theme'] ] += $array['stop'] - $connection;
534 + } else {
535 + $this->cx_buffer['theme'][ $type['theme'] ] = $array['stop'] - $connection;
536 + }
537 + $found_caller = 1;
529 538
530 539 } elseif (! empty( $type['plugin'] ) ) {
531 540 // Save it for later use
532 - $this->cx_buffer['plugin'][ $type['plugin'] ] = $array['stop'] - $connection;
541 + if ( isset( $this->cx_buffer['plugin'][ $type['plugin'] ] ) ) {
542 + $this->cx_buffer['plugin'][ $type['plugin'] ] += $array['stop'] - $connection;
543 + } else {
544 + $this->cx_buffer['plugin'][ $type['plugin'] ] = $array['stop'] - $connection;
545 + }
546 + $found_caller = 1;
533 547 }
534 548 }
535 549 }
536 550 }