mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-18 23:38:37 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Data collector class
|
||||
*/
|
||||
class QM_Collector_IncludedFiles extends QM_Collector {
|
||||
|
||||
public $id = 'included_files';
|
||||
|
||||
public function name() {
|
||||
return __( 'Included files', 'query-monitor' );
|
||||
}
|
||||
|
||||
public function process() {
|
||||
$included_files = get_included_files();
|
||||
|
||||
$opcache_enabled = function_exists('opcache_get_status');
|
||||
$included_files_opcode_stats = $opcache_enabled ? opcache_get_status( true ) : null;
|
||||
|
||||
$included_files_component = array();
|
||||
|
||||
$this->data['total_filesize'] = 0;
|
||||
$this->data['total_opcache_filesize'] = 0;
|
||||
|
||||
//Calculate stats
|
||||
$this->data['stats'] = array();
|
||||
$this->data['stats_raw'] = array();
|
||||
foreach($included_files as $included_file)
|
||||
{
|
||||
$component = QM_Util::get_file_component($included_file)->name;
|
||||
$included_files_component[] = $component;
|
||||
|
||||
//Create component array if it does not exist
|
||||
if(!isset($this->data['stats'][$component]))
|
||||
$this->data['stats'][$component] = array();
|
||||
|
||||
//Create size array if it does not exist
|
||||
if(!isset($this->data['stats'][$component]['size']))
|
||||
$this->data['stats'][$component]['size'] = 0;
|
||||
|
||||
//Create number of files array if it does not exist
|
||||
if(!isset($this->data['stats'][$component]['number_of_files']))
|
||||
$this->data['stats'][$component]['number_of_files'] = 0;
|
||||
|
||||
//Create opcode array if it does not exist
|
||||
if($opcache_enabled) {
|
||||
if(!isset($this->data['stats'][$component]['opcache_size']))
|
||||
$this->data['stats'][$component]['opcache_size'] = 0;
|
||||
}
|
||||
|
||||
//Record total filesize, opcode size and number of files
|
||||
$filesize = filesize($included_file);
|
||||
$this->data['stats'][$component]['size'] += $filesize;
|
||||
$this->data['total_filesize'] += $filesize;
|
||||
$this->data['stats'][$component]['number_of_files']++;
|
||||
|
||||
if($opcache_enabled) {
|
||||
$this->data['stats'][$component]['opcache_size'] += $included_files_opcode_stats['scripts'][$included_file]['memory_consumption'];
|
||||
$this->data['total_opcache_filesize'] += $included_files_opcode_stats['scripts'][$included_file]['memory_consumption'];
|
||||
}
|
||||
}
|
||||
|
||||
//Order data array by number of files
|
||||
$counts = array();
|
||||
foreach ($this->data['stats'] as $component => $values) {
|
||||
$counts[$component] = $values['size'];
|
||||
}
|
||||
|
||||
array_multisort($counts, SORT_DESC, $this->data['stats']);
|
||||
|
||||
//Convert file sizes to KB
|
||||
foreach($this->data['stats'] as $component => $values) {
|
||||
$this->data['stats'][$component]['size_kb'] = $this->format_bytes_to_kb($this->data['stats'][$component]['size'], 2);
|
||||
|
||||
if($opcache_enabled)
|
||||
$this->data['stats'][$component]['opcache_size_kb'] = $this->format_bytes_to_kb($this->data['stats'][$component]['opcache_size'], 2);
|
||||
}
|
||||
|
||||
//Convert totals
|
||||
$this->data['total_filesize_kb'] = $this->format_bytes_to_kb($this->data['total_filesize'], 2);
|
||||
$this->data['total_opcache_filesize_kb'] = $this->format_bytes_to_kb($this->data['total_opcache_filesize'], 2);
|
||||
|
||||
//Misc stats
|
||||
$this->data['included_files_component'] = $included_files_component;
|
||||
$this->data['included_files_number'] = sizeof($included_files);
|
||||
$this->data['included_files'] = $included_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapted from:
|
||||
* http://stackoverflow.com/a/2510459
|
||||
*/
|
||||
private function format_bytes_to_kb($bytes, $precision = 2) {
|
||||
|
||||
$bytes = max($bytes, 0);
|
||||
$bytes /= pow(1000, 1);
|
||||
|
||||
return round($bytes, $precision);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* Output class
|
||||
*
|
||||
* Class QM_Output_IncludedFiles
|
||||
*/
|
||||
class QM_Output_IncludedFiles extends QM_Output_Html {
|
||||
|
||||
public function __construct( QM_Collector $collector ) {
|
||||
parent::__construct( $collector );
|
||||
add_filter( 'qm/output/menus', array( $this, 'admin_menu' ), 101 );
|
||||
add_filter( 'qm/output/title', array( $this, 'admin_title' ), 101 );
|
||||
add_filter( 'qm/output/menu_class', array( $this, 'admin_class' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs data in the footer
|
||||
*/
|
||||
public function output() {
|
||||
$data = $this->collector->get_data();
|
||||
$opcache_enabled = function_exists('opcache_get_status');
|
||||
?>
|
||||
<!-- Print total stats for included files -->
|
||||
<div class="qm" id="<?php echo esc_attr($this->collector->id())?>">
|
||||
<table cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<?php echo __('Total number of included files','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Total file size','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Total OPCache memory consumption','query-monitor'); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="qm-ltr">
|
||||
<?php echo $data['included_files_number']; ?>
|
||||
</td>
|
||||
<td class="qm-ltr">
|
||||
<?php echo $data['total_filesize_kb']; ?> KB
|
||||
</td>
|
||||
<td class="qm-nowrap">
|
||||
<?php
|
||||
if($opcache_enabled)
|
||||
echo $data['total_opcache_filesize_kb'] . " KB";
|
||||
else
|
||||
echo "N/A";
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Print stats for included files -->
|
||||
<div class="qm" id="<?php echo esc_attr($this->collector->id())?>-aggregated">
|
||||
<table cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<?php echo __('Included files by component','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Number of included files','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Total file size','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Zend OPCache memory consumption','query-monitor'); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($data['stats'] as $component => $component_stats) : ?>
|
||||
<tr>
|
||||
<td class="qm-ltr">
|
||||
<?php echo esc_html($component); ?>
|
||||
</td>
|
||||
<td class="qm-ltr">
|
||||
<?php echo esc_html($component_stats['number_of_files']); ?>
|
||||
</td>
|
||||
<td class="qm-nowrap">
|
||||
<?php echo $component_stats['size_kb'] ?> KB
|
||||
</td>
|
||||
<td class="qm-nowrap">
|
||||
<?php
|
||||
if($opcache_enabled)
|
||||
echo $component_stats['opcache_size_kb'] . " KB";
|
||||
else
|
||||
echo "N/A";
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Print detailed included files info -->
|
||||
<div class="qm" id="<?php echo esc_attr($this->collector->id())?>-full">
|
||||
<table cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<?php echo __('Included files','query-monitor'); ?>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<?php echo __('Component','query-monitor'); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($data['included_files'] as $key => $file) : ?>
|
||||
<tr>
|
||||
<td class="qm-ltr">
|
||||
<?php echo esc_html($file); ?>
|
||||
</td>
|
||||
<td class="qm-nowrap">
|
||||
<?php echo $data['included_files_component'][$key]; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds data to top admin bar
|
||||
*
|
||||
* @param array $title
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function admin_title( array $title ) {
|
||||
$data = $this->collector->get_data();
|
||||
|
||||
$title[] = sprintf(
|
||||
_x( '%s<small>F</small>', 'number of included files', 'query-monitor' ),
|
||||
$data['included_files_number']
|
||||
);
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function admin_class( array $class ) {
|
||||
$class[] = 'qm-included_files';
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function admin_menu( array $menu ) {
|
||||
|
||||
$data = $this->collector->get_data();
|
||||
|
||||
$menu[] = $this->menu( array(
|
||||
'id' => 'qm-included_files',
|
||||
'href' => '#qm-included_files',
|
||||
'title' => sprintf( __( 'Included files (%s)', 'query-monitor' ), $data['included_files_number'] )
|
||||
));
|
||||
|
||||
return $menu;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user