├── classes ├── QM_Collector_IncludedFiles.class.php └── QM_Output_IncludedFiles.class.php ├── composer.json ├── query-monitor-included-files.php └── readme.txt /classes/QM_Collector_IncludedFiles.class.php: -------------------------------------------------------------------------------- 1 | data['total_filesize'] = 0; 22 | $this->data['total_opcache_filesize'] = 0; 23 | 24 | //Calculate stats 25 | $this->data['stats'] = array(); 26 | $this->data['stats_raw'] = array(); 27 | foreach($included_files as $included_file) 28 | { 29 | $component = QM_Util::get_file_component($included_file)->name; 30 | $included_files_component[] = $component; 31 | 32 | //Create component array if it does not exist 33 | if(!isset($this->data['stats'][$component])) 34 | $this->data['stats'][$component] = array(); 35 | 36 | //Create size array if it does not exist 37 | if(!isset($this->data['stats'][$component]['size'])) 38 | $this->data['stats'][$component]['size'] = 0; 39 | 40 | //Create number of files array if it does not exist 41 | if(!isset($this->data['stats'][$component]['number_of_files'])) 42 | $this->data['stats'][$component]['number_of_files'] = 0; 43 | 44 | //Create opcode array if it does not exist 45 | if($opcache_enabled) { 46 | if(!isset($this->data['stats'][$component]['opcache_size'])) 47 | $this->data['stats'][$component]['opcache_size'] = 0; 48 | } 49 | 50 | //Record total filesize, opcode size and number of files 51 | $filesize = filesize($included_file); 52 | $this->data['stats'][$component]['size'] += $filesize; 53 | $this->data['total_filesize'] += $filesize; 54 | $this->data['stats'][$component]['number_of_files']++; 55 | 56 | if($opcache_enabled && isset($this->data['stats'][$component]['opcache_size'])) { 57 | $this->data['stats'][$component]['opcache_size'] += $included_files_opcode_stats['scripts'][$included_file]['memory_consumption']; 58 | $this->data['total_opcache_filesize'] += $included_files_opcode_stats['scripts'][$included_file]['memory_consumption']; 59 | } 60 | } 61 | 62 | //Order data array by number of files 63 | $counts = array(); 64 | foreach ($this->data['stats'] as $component => $values) { 65 | $counts[$component] = $values['size']; 66 | } 67 | 68 | array_multisort($counts, SORT_DESC, $this->data['stats']); 69 | 70 | //Convert file sizes to KB 71 | foreach($this->data['stats'] as $component => $values) { 72 | $this->data['stats'][$component]['size_kb'] = $this->format_bytes_to_kb($this->data['stats'][$component]['size'], 2); 73 | 74 | if($opcache_enabled && isset($this->data['stats'][$component])) { 75 | $this->data['stats'][$component]['opcache_size_kb'] = $this->format_bytes_to_kb($this->data['stats'][$component]['opcache_size'], 2); 76 | } 77 | } 78 | 79 | //Convert totals 80 | $this->data['total_filesize_kb'] = $this->format_bytes_to_kb($this->data['total_filesize'], 2); 81 | $this->data['total_opcache_filesize_kb'] = $this->format_bytes_to_kb($this->data['total_opcache_filesize'], 2); 82 | 83 | //Misc stats 84 | $this->data['included_files_component'] = $included_files_component; 85 | $this->data['included_files_number'] = sizeof($included_files); 86 | $this->data['included_files'] = $included_files; 87 | } 88 | 89 | /** 90 | * Adapted from: 91 | * http://stackoverflow.com/a/2510459 92 | */ 93 | private function format_bytes_to_kb($bytes, $precision = 2) { 94 | 95 | $bytes = max($bytes, 0); 96 | $bytes /= pow(1000, 1); 97 | 98 | return round($bytes, $precision); 99 | } 100 | } -------------------------------------------------------------------------------- /classes/QM_Output_IncludedFiles.class.php: -------------------------------------------------------------------------------- 1 | collector->get_data(); 21 | $opcache_enabled = function_exists('opcache_get_status'); 22 | ?> 23 | 24 |
25 | 26 | 27 | 28 | 29 | 32 | 35 | 38 | 39 | 40 | 41 | 42 | 45 | 48 | 56 | 57 | 58 |
30 | 31 | 33 | 34 | 36 | 37 |
43 | 44 | 46 | KB 47 | 49 | 55 |
59 | 60 | 61 | 62 | 63 | 64 | 67 | 70 | 73 | 76 | 77 | 78 | 79 | $component_stats) : ?> 80 | 81 | 84 | 87 | 90 | 98 | 99 | 100 | 101 |
65 | 66 | 68 | 69 | 71 | 72 | 74 | 75 |
82 | 83 | 85 | 86 | 88 | KB 89 | 91 | 97 |
102 | 103 | 104 | 105 | 106 | 107 | 110 | 113 | 114 | 115 | 116 | $file) : ?> 117 | 118 | 121 | 124 | 125 | 126 | 127 |
108 | 109 | 111 | 112 |
119 | 120 | 122 | 123 |
128 |
129 | collector->get_data(); 141 | 142 | $title[] = sprintf( 143 | _x( '%sF', 'number of included files', 'query-monitor' ), 144 | $data['included_files_number'] 145 | ); 146 | 147 | return $title; 148 | } 149 | 150 | /** 151 | * @param array $class 152 | * 153 | * @return array 154 | */ 155 | public function admin_class( array $class ) { 156 | $class[] = 'qm-included_files'; 157 | return $class; 158 | } 159 | 160 | public function admin_menu( array $menu ) { 161 | 162 | $data = $this->collector->get_data(); 163 | 164 | $menu[] = $this->menu( array( 165 | 'id' => 'qm-included_files', 166 | 'href' => '#qm-included_files', 167 | 'title' => sprintf( __( 'Included files (%s)', 'query-monitor' ), $data['included_files_number'] ) 168 | )); 169 | 170 | return $menu; 171 | } 172 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "khromov/query-monitor-included-files", 3 | "description": "Shows number of included files in admin bar and in the footer of each page load. Requires Query Monitor.", 4 | "keywords": ["wordpress", "debug"], 5 | "license": "GPL2", 6 | "type": "wordpress-plugin", 7 | "require": { 8 | "composer/installers": "~1.0" 9 | } 10 | } -------------------------------------------------------------------------------- /query-monitor-included-files.php: -------------------------------------------------------------------------------- 1 |