compressors = $compressors; $this->system_load_monitor = $system_load_monitor; $this->core_counter = $core_counter; $this->preload_mode_manager = $preload_mode_manager; } /** * Adds a new Solid Performance section to site health data. * * @since 0.1.0 * * @filter debug_information * * @param array $info The array of site health data. * * @return array */ public function add_summary_to_telemetry( array $info ): array { $page_cache = swpsp_config_get( 'page_cache' ); $page_cache_status = $page_cache['enabled'] ? esc_html__( 'Enabled', 'LION' ) : esc_html__( 'Disabled', 'LION' ); $cache_dir_writeable = swpsp_direct_filesystem()->is_writable( $page_cache['cache_dir'] ) ? esc_html__( 'Writable', 'LION' ) : esc_html__( 'Not Writable', 'LION' ); $debug_mode_status = $page_cache['debug'] ? esc_html__( 'Enabled', 'LION' ) : esc_html__( 'Disabled', 'LION' ); $exclusion_count = count( $page_cache['exclusions'] ); $enabled_compressors = implode( ', ', array_filter( array_map( static fn( Compressible $c ): string => $c->encoding(), $this->compressors->enabled() ) ) ); try { $system_load = []; $system_load_debug = []; $load_averages = $this->system_load_monitor->load()->all(); foreach ( $load_averages as $label => $load_average ) { $new_label = sprintf( /* translators: %s: The system load time, e.g. 1, 5, or 15. */ _n( '%s min', '%s mins', $label, 'LION' ), $label ); $formatted_average = number_format( $load_average, 2 ); $system_load[ $new_label ] = $formatted_average; $system_load_debug[ $label ] = $formatted_average; } } catch ( RuntimeException $e ) { $system_load = $e->getMessage(); $system_load_debug = $e->getMessage(); } $core_count = $this->core_counter->core_count(); $info['solid-performance'] = [ 'label' => esc_html__( 'Solid Performance', 'LION' ), 'fields' => [ 'page_cache_status' => [ 'label' => esc_html__( 'Page cache', 'LION' ), 'value' => $page_cache_status, 'debug' => strtolower( $page_cache_status ), ], 'cache_directory' => [ 'label' => esc_html__( 'Cache directory', 'LION' ), 'value' => $page_cache['cache_dir'], 'debug' => $page_cache['cache_dir'], ], 'cache_directory_writable' => [ 'label' => esc_html__( 'Cache directory permissions', 'LION' ), 'value' => $cache_dir_writeable, 'debug' => strtolower( $cache_dir_writeable ), ], 'debug_mode' => [ 'label' => esc_html__( 'Debug mode', 'LION' ), 'value' => $debug_mode_status, 'debug' => strtolower( $debug_mode_status ), ], 'exclusion_count' => [ 'label' => esc_html__( 'Number of custom exclusions', 'LION' ), 'value' => $exclusion_count, ], 'compression' => [ 'label' => esc_html__( 'Supported compression algorithms', 'LION' ), 'value' => $enabled_compressors, 'debug' => $enabled_compressors, ], 'system_load' => [ 'label' => esc_html__( 'System load average', 'LION' ), 'value' => $system_load, 'debug' => $system_load_debug, ], 'core_count' => [ 'label' => esc_html__( 'System CPU core count', 'LION' ), 'value' => $core_count, ], 'high_performance_mode' => [ 'label' => esc_html__( 'High performance mode', 'LION' ), 'value' => $this->preload_mode_manager->is_high_performance_mode() ? esc_html__( 'Enabled', 'LION' ) : esc_html__( 'Disabled', 'LION' ), 'debug' => $this->preload_mode_manager->is_high_performance_mode(), ], ], ]; return $info; } }