Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Afterburner panel to QM #827

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions inc/afterburner/class-qm-collector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Altis Afterburner data collector for the Query Monitor plugin.
*/

namespace Altis\Cloud\Afterburner;

/**
* Altis Config Qm Collector.
*/
class QM_Collector extends \QM_Collector {

/**
* Collector ID.
*
* @var string
*/
public $id = 'afterburner';

}
82 changes: 82 additions & 0 deletions inc/afterburner/class-qm-output-html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Altis Afterburner data output for HTML pages in the Query Monitor plugin.
*
* @package altis/dev-tools
*/

namespace Altis\Cloud\Afterburner;

use Afterburner;
use QM_Collector;

/**
* Altis Afterburner QM Panel Class.
*
* @package altis/dev-tools
*/
class QM_Output_Html extends \QM_Output_Html {

/**
* Altis Config QM Panel Constructor.
*
* @param QM_Collector $collector Collector object.
*/
public function __construct( QM_Collector $collector ) {
parent::__construct( $collector );
add_filter( 'qm/output/menus', [ $this, 'admin_menu' ] );
}

/**
* Panel name.
*
* @return string
*/
public function name() {
return esc_html_x( 'Afterburner', 'Menu item name for the Query Monitor plugin', 'altis' );
}

/**
* Panel content.
*
* @return void
*/
public function output() {
$stats = Afterburner\ObjectCache\getStats();
?>
<?php $this->before_tabular_output(); ?>

<tbody>
<tr>
<td><?php echo esc_html__( 'Afterburner connection string', 'altis' ); ?></td>
<td><code><?php echo esc_html( ini_get( 'afterburner.redis_server_info' ) ) ?></code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'redis_skip_server_check', 'altis' ); ?></td>
<td><code><?php echo esc_html( ini_get( 'afterburner.redis_skip_server_check' ) ) ?></code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'Max items in LRU cache', 'altis' ); ?></td>
<td><code><?php echo esc_html( ini_get( 'afterburner.lru_cache_max_items' ) ) ?></code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'Items in LRU cache for this PHP worker', 'altis' ); ?></td>
<td><code><?php echo esc_html( $stats->lru_cache_items ) ?></code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'Total memory used in LRU cache for this PHP worker', 'altis' ); ?></td>
<td><code><?php echo esc_html( size_format( $stats->lru_cache_size ) ) ?></code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'Redis total time (ms) for this PHP worker', 'altis' ); ?></td>
<td><code><?php echo esc_html( round( $stats->redis_total_time / 1000 ) ) ?>ms</code></td>
</tr>
<tr>
<td><?php echo esc_html__( 'All stats for this PHP worker', 'altis' ); ?></td>
<td><pre><?php echo esc_html( print_r( $stats, true ) ) // phpcs:ignore ?></pre></td>
</tbody>

<?php
$this->after_tabular_output();
}
}
28 changes: 28 additions & 0 deletions inc/afterburner/namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Altis Afterburner namespace bootstrap file.
*/

namespace Altis\Cloud\Afterburner;

/**
* Bootstrap function.
*/
function bootstrap() : void {
add_filter( 'qm/outputter/html', __NAMESPACE__ . '\\register_qm_output_html' );
}

/**
* Register the HTML outputter for the Xray panel
*
* @param array $output The HTML output for the collector
* @return array
*/
function register_qm_output_html( array $output ) : array {
require_once __DIR__ . '/class-qm-output-html.php';
require_once __DIR__ . '/class-qm-collector.php';

$output['afterburner'] = new QM_Output_Html( new QM_Collector() );

return $output;
}
5 changes: 5 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ function bootstrap() {
if ( is_cloud() ) {
define( 'DISALLOW_FILE_MODS', true );
}

if ( extension_loaded( 'afterburner' ) ) {
require_once __DIR__ . '/afterburner/namespace.php';
Afterburner\bootstrap();
}
}

/**
Expand Down
Loading