collector->get_data(); if ( empty( $data->timing ) && empty( $data->warning ) ) { $this->before_non_tabular_output(); $notice = sprintf( /* translators: %s: Link to help article */ __( 'No data logged. Read about timing and profiling in Query Monitor.', 'query-monitor' ), 'https://querymonitor.com/blog/2018/07/profiling-and-logging/' ); echo $this->build_notice( $notice ); // WPCS: XSS ok. $this->after_non_tabular_output(); return; } $this->before_tabular_output(); echo ''; echo ''; echo '' . esc_html__( 'Tracked Function', 'query-monitor' ) . ''; echo '' . esc_html__( 'Started', 'query-monitor' ) . ''; echo '' . esc_html__( 'Stopped', 'query-monitor' ) . ''; echo '' . esc_html__( 'Time', 'query-monitor' ) . ''; echo '' . esc_html__( 'Memory', 'query-monitor' ) . ''; echo '' . esc_html__( 'Component', 'query-monitor' ) . ''; echo ''; echo ''; echo ''; if ( ! empty( $data->timing ) ) { foreach ( $data->timing as $row ) { $component = $row['component']; $trace = $row['filtered_trace']; $file = self::output_filename( $row['function'], $trace[0]['file'], $trace[0]['line'] ); echo ''; if ( self::has_clickable_links() ) { echo ''; echo $file; // WPCS: XSS ok. echo ''; } else { echo ''; echo self::build_toggler(); // WPCS: XSS ok; echo '
    '; echo '
  1. '; echo $file; // WPCS: XSS ok. echo '
  2. '; echo '
'; } printf( '%s', esc_html( number_format_i18n( $row['start_time'], 4 ) ) ); printf( '%s', esc_html( number_format_i18n( $row['end_time'], 4 ) ) ); printf( '%s', esc_html( number_format_i18n( $row['function_time'], 4 ) ) ); $mem = sprintf( /* translators: %s: Approximate memory used in kilobytes */ __( '~%s kB', 'query-monitor' ), number_format_i18n( $row['function_memory'] / 1024 ) ); printf( '%s', esc_html( $mem ) ); printf( '%s', esc_html( $component->name ) ); echo ''; if ( ! empty( $row['laps'] ) ) { foreach ( $row['laps'] as $lap_id => $lap ) { echo ''; echo '— '; echo esc_html( $row['function'] . ': ' . $lap_id ); echo ''; echo ''; echo ''; printf( '%s', esc_html( number_format_i18n( $lap['time_used'], 4 ) ) ); $mem = sprintf( /* translators: %s: Approximate memory used in kilobytes */ __( '~%s kB', 'query-monitor' ), number_format_i18n( $lap['memory_used'] / 1024 ) ); printf( '%s', esc_html( $mem ) ); echo ''; echo ''; } } } } if ( ! empty( $data->warning ) ) { foreach ( $data->warning as $row ) { $component = $row['component']; $trace = $row['filtered_trace']; $file = self::output_filename( $row['function'], $trace[0]['file'], $trace[0]['line'] ); echo ''; if ( self::has_clickable_links() ) { echo ''; echo $file; // WPCS: XSS ok. echo ''; } else { echo ''; echo self::build_toggler(); // WPCS: XSS ok; echo '
    '; echo '
  1. '; echo $file; // WPCS: XSS ok. echo '
  2. '; echo '
'; } printf( '%1$s%2$s', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped QueryMonitor::icon( 'warning' ), esc_html( $row['message'] ) ); printf( '%s', esc_html( $component->name ) ); } } echo ''; $this->after_tabular_output(); } /** * @param array $menu * @return array */ public function admin_menu( array $menu ) { /** @var QM_Data_Timing $data */ $data = $this->collector->get_data(); $count = 0; if ( ! empty( $data->timing ) || ! empty( $data->warning ) ) { if ( ! empty( $data->timing ) ) { $count += count( $data->timing ); } if ( ! empty( $data->warning ) ) { $count += count( $data->warning ); } /* translators: %s: Number of function timing results that are available */ $label = __( 'Timings (%s)', 'query-monitor' ); } else { $label = __( 'Timings', 'query-monitor' ); } $menu[ $this->collector->id() ] = $this->menu( array( 'title' => esc_html( sprintf( $label, number_format_i18n( $count ) ) ), ) ); return $menu; } } /** * @param array $output * @param QM_Collectors $collectors * @return array */ function register_qm_output_html_timing( array $output, QM_Collectors $collectors ) { $collector = QM_Collectors::get( 'timing' ); if ( $collector ) { $output['timing'] = new QM_Output_Html_Timing( $collector ); } return $output; } add_filter( 'qm/outputter/html', 'register_qm_output_html_timing', 15, 2 );