Make WordPress Core

Changeset 120 in tests


Ignore:
Timestamp:
12/05/2007 06:52:09 AM (19 years ago)
Author:
tellyworth
Message:

profiler: record cache info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testlib/wp-profiler.php

    r87 r120  
    4242        }
    4343        $wpdb->queries = array();
     44       
     45        global $wp_object_cache;
    4446
    4547        $this->stack[] = array(
    4648            'start' => $time,
    4749            '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),
    4854            'actions' => array(),
    4955            'filters' => array(),
     
    6066        global $wpdb;
    6167        $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']);
    6272
    6373        if (isset($this->profile[$name])) {
    6474            $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']);
    6984
    7085        }
     
    7489            $this->profile[$name] = array(
    7590                '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,
    7696                'actions' => $item['actions'],
    7797                'filters' => $item['filters'],
     
    126146        asort($out);
    127147        return;
    128 
    129 
     148    }
     149
     150    function _query_count($queries) {
    130151        // this requires the savequeries patch at http://trac.wordpress.org/ticket/5218
    131152        $out = array();
     
    138159        return $out;
    139160    }
    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        }
    142194    }
    143195}
     
    158210}
    159211
     212function wppf_print_summary() {
     213    $GLOBALS['wppf']->print_summary();
     214}
     215
    160216?>
Note: See TracChangeset for help on using the changeset viewer.