Ticket #613: database.patch

File database.patch, 2.4 kB (added by charlie, 6 months ago)

simple method for benchmarking 'special' database operations

  • config/database.php

     
    4141        'table_prefix'  => '', 
    4242        'object'        => TRUE, 
    4343        'cache'         => FALSE, 
    44         'escape'        => TRUE 
     44        'escape'        => TRUE, 
     45        'profile_all'   => FALSE 
    4546); 
     47 No newline at end of file 
  • libraries/Database.php

     
    1313 
    1414        // Global benchmark 
    1515        public static $benchmarks = array(); 
     16         
     17        private static $profile_all = FALSE; 
    1618 
    1719        // Configuration 
    1820        protected $config = array 
     
    101103 
    102104                // Merge the default config with the passed config 
    103105                $this->config = array_merge($this->config, $config); 
     106                 
     107                // Set the profile_all flag 
     108                if(isset($this->config['profile_all'])) 
     109                { 
     110                        $this->profile_all = $this->config['profile_all']; 
     111                } 
    104112 
    105113                if (is_string($this->config['connection'])) 
    106114                { 
     
    10641072 
    10651073                $this->reset_select(); 
    10661074 
    1067                 return $this->driver->list_tables(); 
     1075                $start = microtime(true); 
     1076 
     1077                $result = $this->driver->list_tables(); 
     1078                 
     1079                $stop = microtime(true); 
     1080                 
     1081                if($this->profile_all) 
     1082                { 
     1083                        self::$benchmarks[] = array('query' => 'Database::list_tables()', 'time' => $stop - $start, 'rows' => count($result)); 
     1084                } 
     1085                 
     1086                return $result; 
    10681087        } 
    10691088 
    10701089        /** 
     
    11171136        { 
    11181137                $this->link or $this->connect(); 
    11191138 
    1120                 return $this->driver->field_data($this->config['table_prefix'].$table); 
     1139                $start = microtime(true); 
     1140 
     1141                $result = $this->driver->field_data($this->config['table_prefix'].$table); 
     1142                 
     1143                $stop = microtime(true); 
     1144                 
     1145                if($this->profile_all) 
     1146                { 
     1147                        self::$benchmarks[] = array('query' => 'Database::field_data(\'' . $table . '\')', 'time' => $stop - $start, 'rows' => count($result)); 
     1148                } 
     1149                 
     1150                return $result; 
    11211151        } 
    11221152 
    11231153        /** 
     
    11301160        { 
    11311161                $this->link or $this->connect(); 
    11321162 
    1133                 return $this->driver->list_fields($this->config['table_prefix'].$table); 
     1163                $start = microtime(true); 
     1164 
     1165                $result = $this->driver->list_fields($this->config['table_prefix'].$table); 
     1166                 
     1167                $stop = microtime(true); 
     1168                 
     1169                if($this->profile_all) 
     1170                { 
     1171                        self::$benchmarks[] = array('query' => 'Database::list_fields(\'' . $table . '\')', 'time' => $stop - $start, 'rows' => count($result)); 
     1172                } 
     1173                 
     1174                return $result; 
    11341175        } 
    11351176 
    11361177        /**