Skip to content

Commit

Permalink
Merge pull request #861 from humanmade/backport-827-to-v17-branch
Browse files Browse the repository at this point in the history
[Backport v17] Add Afterburner panel to QM
  • Loading branch information
mikelittle authored Mar 29, 2024
2 parents 6ca01f9 + 7b7c4c8 commit 858a314
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
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

0 comments on commit 858a314

Please sign in to comment.