Example #1
0
 /**
  * Writable dir for information storage
  */
 public static function storageDir()
 {
     $storage = Kohana::config('webgrind.storageDir');
     if (!empty($storage)) {
         return realpath($storage) . '/';
     }
     if (!function_exists('sys_get_temp_dir') || !is_writable(sys_get_temp_dir())) {
         # use xdebug setting
         return webgrind::xdebugOutputDir();
     }
     return realpath(sys_get_temp_dir()) . '/';
 }
Example #2
0
 public function function_list()
 {
     $dataFile = webgrind::get('dataFile');
     if ($dataFile == '0') {
         $files = Webgrind_Filehandler::getInstance()->getTraceList();
         $dataFile = $files[0]['filename'];
     }
     $reader = Webgrind_Filehandler::getInstance()->getTraceReader($dataFile, webgrind::get('costFormat', Kohana::config('webgrind.defaultCostformat')));
     $functions = array();
     $shownTotal = 0;
     $breakdown = array('internal' => 0, 'user' => 0, 'class' => 0, 'include' => 0);
     for ($i = 0; $i < $reader->getFunctionCount(); $i++) {
         $functionInfo = $reader->getFunctionInfo($i);
         if (false !== strpos($functionInfo['functionName'], 'php::')) {
             $breakdown['internal'] += $functionInfo['summedSelfCost'];
             $humanKind = 'internal';
             $kind = 'blue';
         } elseif (false !== strpos($functionInfo['functionName'], 'require_once::') || false !== strpos($functionInfo['functionName'], 'require::') || false !== strpos($functionInfo['functionName'], 'include_once::') || false !== strpos($functionInfo['functionName'], 'include::')) {
             $breakdown['include'] += $functionInfo['summedSelfCost'];
             $humanKind = 'include';
             $kind = 'grey';
         } else {
             if (false !== strpos($functionInfo['functionName'], '->') || false !== strpos($functionInfo['functionName'], '::')) {
                 $breakdown['class'] += $functionInfo['summedSelfCost'];
                 $humanKind = 'class';
                 $kind = 'green';
             } else {
                 $breakdown['user'] += $functionInfo['summedSelfCost'];
                 $humanKind = 'procedural';
                 $kind = 'orange';
             }
         }
         if (!(int) webgrind::get('hideInternals', 0) || strpos($functionInfo['functionName'], 'php::') === false) {
             $shownTotal += $functionInfo['summedSelfCost'];
             $functions[$i] = $functionInfo;
             $functions[$i]['nr'] = $i;
             $functions[$i]['kind'] = $kind;
             $functions[$i]['humanKind'] = $humanKind;
         }
     }
     usort($functions, array('webgrind', 'cost_cmp'));
     $remainingCost = $shownTotal * webgrind::get('showFraction');
     $result['functions'] = array();
     foreach ($functions as $function) {
         $remainingCost -= $function['summedSelfCost'];
         $result['functions'][] = $function;
         if ($remainingCost < 0) {
             break;
         }
     }
     $result['summedInvocationCount'] = $reader->getFunctionCount();
     $result['summedRunTime'] = $reader->formatCost($reader->getHeader('summary'), 'msec');
     $result['dataFile'] = $dataFile;
     $result['invokeUrl'] = $reader->getHeader('cmd');
     $result['runs'] = $reader->getHeader('runs');
     $result['breakdown'] = $breakdown;
     $result['mtime'] = date(Kohana::config('webgrind.dateFormat'), filemtime(webgrind::xdebugOutputDir() . $dataFile));
     echo json_encode($result);
 }
 /**
  * Get a trace reader for the specific file.
  * 
  * If the file has not been preprocessed yet this will be done first.
  *
  * @param string File to read
  * @param Cost format for the reader
  * @return Webgrind_Reader Reader for $file
  */
 public function getTraceReader($file, $costFormat)
 {
     $prepFile = webgrind::storageDir() . $file . $this->suffix;
     try {
         $r = new Webgrind_Reader($prepFile, $costFormat);
     } catch (Exception $e) {
         // Preprocessed file does not exist or other error
         Webgrind_Preprocessor::parse(webgrind::xdebugOutputDir() . $file, $prepFile);
         $r = new Webgrind_Reader($prepFile, $costFormat);
     }
     return $r;
 }