Changeset 120 in tests
- Timestamp:
- 12/05/2007 06:52:09 AM (19 years ago)
- File:
-
- 1 edited
-
wp-testlib/wp-profiler.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-testlib/wp-profiler.php
r87 r120 42 42 } 43 43 $wpdb->queries = array(); 44 45 global $wp_object_cache; 44 46 45 47 $this->stack[] = array( 46 48 'start' => $time, 47 49 'name' => $name, 50 'cache_cold_hits' => $wp_object_cache->cold_cache_hits, 51 'cache_warm_hits' => $wp_object_cache->warm_cache_hits, 52 'cache_misses' => $wp_object_cache->cache_misses, 53 'cache_dirty_objects' => $this->_dirty_objects_count($wp_object_cache->dirty_objects), 48 54 'actions' => array(), 49 55 'filters' => array(), … … 60 66 global $wpdb; 61 67 $item['queries'] = $wpdb->queries; 68 global $wp_object_cache; 69 70 $cache_dirty_count = $this->_dirty_objects_count($wp_object_cache->dirty_objects); 71 $cache_dirty_delta = $this->array_sub($cache_dirty_count, $item['cache_dirty_objects']); 62 72 63 73 if (isset($this->profile[$name])) { 64 74 $this->profile[$name]['time'] += $time; 65 $this->profile[$name]['actions'] = array_merge( $this->profile[$name]['actions'], $item['actions'] ); 66 $this->profile[$name]['filters'] = array_merge( $this->profile[$name]['filters'], $item['filters'] ); 67 #$this->profile[$name]['queries'] = array_merge( $this->profile[$name]['queries'], $item['queries'] ); 68 $this->_query_summary($item['queries'], $this->profile[$name]['queries']); 75 $this->profile[$name]['calls'] ++; 76 $this->profile[$name]['cache_cold_hits'] += ($wp_object_cache->cold_cache_hits - $item['cache_cold_hits']); 77 $this->profile[$name]['cache_warm_hits'] += ($wp_object_cache->warm_cache_hits - $item['cache_warm_hits']); 78 $this->profile[$name]['cache_misses'] += ($wp_object_cache->cache_misses - $item['cache_misses']); 79 $this->profile[$name]['cache_dirty_objects'] = array_add( $this->profile[$name]['cache_dirty_objects'], $cache_dirty_delta) ; 80 $this->profile[$name]['actions'] = array_add( $this->profile[$name]['actions'], $item['actions'] ); 81 $this->profile[$name]['filters'] = array_add( $this->profile[$name]['filters'], $item['filters'] ); 82 $this->profile[$name]['queries'] = array_add( $this->profile[$name]['queries'], $item['queries'] ); 83 #$this->_query_summary($item['queries'], $this->profile[$name]['queries']); 69 84 70 85 } … … 74 89 $this->profile[$name] = array( 75 90 'time' => $time, 91 'calls' => 1, 92 'cache_cold_hits' => ($wp_object_cache->cold_cache_hits - $item['cache_cold_hits']), 93 'cache_warm_hits' => ($wp_object_cache->warm_cache_hits - $item['cache_warm_hits']), 94 'cache_misses' => ($wp_object_cache->cache_misses - $item['cache_misses']), 95 'cache_dirty_objects' => $cache_dirty_delta, 76 96 'actions' => $item['actions'], 77 97 'filters' => $item['filters'], … … 126 146 asort($out); 127 147 return; 128 129 148 } 149 150 function _query_count($queries) { 130 151 // this requires the savequeries patch at http://trac.wordpress.org/ticket/5218 131 152 $out = array(); … … 138 159 return $out; 139 160 } 140 141 function print_results() { 161 162 function _dirty_objects_count($dirty_objects) { 163 $out = array(); 164 foreach (array_keys($dirty_objects) as $group) 165 $out[$group] = count($dirty_objects[$group]); 166 return $out; 167 } 168 169 function array_add($a, $b) { 170 $out = $a; 171 foreach (array_keys($b) as $key) 172 if (array_key_exists($key, $out)) 173 $out[$key] += $b[$key]; 174 else 175 $out[$key] = $b[$key]; 176 return $out; 177 } 178 179 function array_sub($a, $b) { 180 $out = $a; 181 foreach (array_keys($b) as $key) 182 if (array_key_exists($key, $b)) 183 $out[$key] -= $b[$key]; 184 return $out; 185 } 186 187 function print_summary() { 188 $results = $this->results(); 189 190 printf("\nname calls time action filter warm cold misses dirty\n"); 191 foreach ($results as $name=>$stats) { 192 printf("%24.24s %6d %6.4f %6d %6d %6d %6d %6d %6d\n", $name, $stats['calls'], $stats['time'], array_sum($stats['actions']), array_sum($stats['filters']), $stats['cache_warm_hits'], $stats['cache_cold_hits'], $stats['cache_misses'], array_sum($stats['cache_dirty_objects'])); 193 } 142 194 } 143 195 } … … 158 210 } 159 211 212 function wppf_print_summary() { 213 $GLOBALS['wppf']->print_summary(); 214 } 215 160 216 ?>
Note: See TracChangeset
for help on using the changeset viewer.