Varien_Profiler Class Reference

List of all members.

Static Public Member Functions

static enable ()
static disable ()
static reset ($timerName)
static resume ($timerName)
static start ($timerName)
static pause ($timerName)
static stop ($timerName)
static fetch ($timerName, $key='sum')
static getTimers ()
static getSqlProfiler ($res)


Detailed Description

Definition at line 28 of file Profiler.php.


Member Function Documentation

static disable (  )  [static]

Definition at line 46 of file Profiler.php.

00047     {
00048         self::$_enabled = false;
00049     }

static enable (  )  [static]

Definition at line 40 of file Profiler.php.

00041     {
00042         self::$_enabled = true;
00043         self::$_memory_get_usage = function_exists('memory_get_usage');
00044     }

static fetch ( timerName,
key = 'sum' 
) [static]

Definition at line 108 of file Profiler.php.

00109     {
00110         if (empty(self::$_timers[$timerName])) {
00111             return false;
00112         } elseif (empty($key)) {
00113             return self::$_timers[$timerName];
00114         }
00115         switch ($key) {
00116             case 'sum':
00117                 $sum = self::$_timers[$timerName]['sum'];
00118                 if (self::$_timers[$timerName]['start']!==false) {
00119                     $sum += microtime(true)-self::$_timers[$timerName]['start'];
00120                 }
00121                 return $sum;
00122 
00123             case 'count':
00124                 $count = self::$_timers[$timerName]['count'];
00125                 return $count;
00126 
00127             case 'realmem':
00128                 if (!isset(self::$_timers[$timerName]['realmem'])) {
00129                     self::$_timers[$timerName]['realmem'] = -1;
00130                 }
00131                 return self::$_timers[$timerName]['realmem'];
00132 
00133             case 'emalloc':
00134                 if (!isset(self::$_timers[$timerName]['emalloc'])) {
00135                     self::$_timers[$timerName]['emalloc'] = -1;
00136                 }
00137                 return self::$_timers[$timerName]['emalloc'];
00138 
00139             default:
00140                 if (!empty(self::$_timers[$timerName][$key])) {
00141                     return self::$_timers[$timerName][$key];
00142                 }
00143         }
00144         return false;
00145     }

static getSqlProfiler ( res  )  [static]

Output SQl Zend_Db_Profiler

Definition at line 156 of file Profiler.php.

00156                                                 {
00157         if(!$res){
00158             return '';
00159         }
00160         $out = '';
00161         $profiler = $res->getProfiler();
00162         if($profiler->getEnabled()) {
00163             $totalTime    = $profiler->getTotalElapsedSecs();
00164             $queryCount   = $profiler->getTotalNumQueries();
00165             $longestTime  = 0;
00166             $longestQuery = null;
00167 
00168             foreach ($profiler->getQueryProfiles() as $query) {
00169                 if ($query->getElapsedSecs() > $longestTime) {
00170                     $longestTime  = $query->getElapsedSecs();
00171                     $longestQuery = $query->getQuery();
00172                 }
00173             }
00174 
00175             $out .= 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "<br>";
00176             $out .= 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "<br>";
00177             $out .= 'Queries per second: ' . $queryCount / $totalTime . "<br>";
00178             $out .= 'Longest query length: ' . $longestTime . "<br>";
00179             $out .= 'Longest query: <br>' . $longestQuery . "<hr>";
00180         }
00181         return $out;
00182     }

static getTimers (  )  [static]

Definition at line 147 of file Profiler.php.

00148     {
00149         return self::$_timers;
00150     }

static pause ( timerName  )  [static]

Definition at line 84 of file Profiler.php.

00085     {
00086         if (!self::$_enabled) {
00087             return;
00088         }
00089 
00090         if (empty(self::$_timers[$timerName])) {
00091             self::reset($timerName);
00092         }
00093         if (false!==self::$_timers[$timerName]['start']) {
00094             self::$_timers[$timerName]['sum'] += microtime(true)-self::$_timers[$timerName]['start'];
00095             self::$_timers[$timerName]['start'] = false;
00096             if (self::$_memory_get_usage) {
00097                 self::$_timers[$timerName]['realmem'] += memory_get_usage(true)-self::$_timers[$timerName]['realmem_start'];
00098                 self::$_timers[$timerName]['emalloc'] += memory_get_usage()-self::$_timers[$timerName]['emalloc_start'];
00099             }
00100         }
00101     }

static reset ( timerName  )  [static]

Definition at line 51 of file Profiler.php.

00052     {
00053         self::$_timers[$timerName] = array(
00054             'start'=>false,
00055             'count'=>0,
00056             'sum'=>0,
00057             'realmem'=>0,
00058             'emalloc'=>0,
00059         );
00060     }

static resume ( timerName  )  [static]

Definition at line 62 of file Profiler.php.

00063     {
00064         if (!self::$_enabled) {
00065             return;
00066         }
00067 
00068         if (empty(self::$_timers[$timerName])) {
00069             self::reset($timerName);
00070         }
00071         if (self::$_memory_get_usage) {
00072             self::$_timers[$timerName]['realmem_start'] = memory_get_usage(true);
00073             self::$_timers[$timerName]['emalloc_start'] = memory_get_usage();
00074         }
00075         self::$_timers[$timerName]['start'] = microtime(true);
00076         self::$_timers[$timerName]['count'] ++;
00077     }

static start ( timerName  )  [static]

Definition at line 79 of file Profiler.php.

00080     {
00081         self::resume($timerName);
00082     }

static stop ( timerName  )  [static]

Definition at line 103 of file Profiler.php.

00104     {
00105         self::pause($timerName);
00106     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:25:04 2009 for Magento by  doxygen 1.5.8