示例#1
0
 /**
  * Writable dir for information storage
  */
 static function storageDir()
 {
     if (!empty(Webgrind_Config::$storageDir)) {
         return realpath(Webgrind_Config::$storageDir) . '/';
     }
     if (!function_exists('sys_get_temp_dir') || !is_writable(sys_get_temp_dir())) {
         # use xdebug setting
         return Webgrind_Config::xdebugOutputDir();
     }
     return realpath(sys_get_temp_dir()) . '/';
 }
示例#2
0
 /**
  * Extract information from $inFile and store in preprocessed form in $outFile
  * using the (~20x) faster binary preprocessor
  *
  * @param string $inFile Callgrind file to read
  * @param string $outFile File to write preprocessed data to
  * @return bool True if binary preprocessor was executed
  */
 static function binaryParse($inFile, $outFile)
 {
     $preprocessor = Webgrind_Config::getBinaryPreprocessor();
     if (!is_executable($preprocessor)) {
         return false;
     }
     $cmd = escapeshellarg($preprocessor) . ' ' . escapeshellarg($inFile) . ' ' . escapeshellarg($outFile);
     foreach (Webgrind_Config::$proxyFunctions as $function) {
         $cmd .= ' ' . escapeshellarg($function);
     }
     exec($cmd);
     return true;
 }
示例#3
0
 /**
  * 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_Config::storageDir() . $file . Webgrind_Config::$preprocessedSuffix;
     try {
         $r = new Webgrind_Reader($prepFile, $costFormat);
     } catch (Exception $e) {
         // Preprocessed file does not exist or other error
         Webgrind_Preprocessor::parse(Webgrind_Config::xdebugOutputDir() . $file, $prepFile);
         $r = new Webgrind_Reader($prepFile, $costFormat);
     }
     return $r;
 }
示例#4
0
		break;
    	case 'version_info':
    		$response = @file_get_contents('http://jokke.dk/webgrindupdate.json?version='.Webgrind_Config::$webgrindVersion);
    		echo $response;
    	break;
    	default:
            $welcome = '';
    	    if (!file_exists(Webgrind_Config::storageDir()) || !is_writable(Webgrind_Config::storageDir())) {
    	        $welcome .= 'Webgrind $storageDir does not exist or is not writeable: <code>'.Webgrind_Config::storageDir().'</code><br>';
    	    }
    	    if (!file_exists(Webgrind_Config::xdebugOutputDir()) || !is_readable(Webgrind_Config::xdebugOutputDir())) {
    	        $welcome .= 'Webgrind $profilerDir does not exist or is not readable: <code>'.Webgrind_Config::xdebugOutputDir().'</code><br>';
    	    }
    	    
    	    if ($welcome == '') {
        	    $welcome = 'Select a cachegrind file above<br>(looking in <code>'.Webgrind_Config::xdebugOutputDir().'</code> for files matching <code>'.Webgrind_Config::xdebugOutputFormat().'</code>)';
    	    }
    		require 'templates/index.phtml';
    }
} catch (Exception $e) {
    echo json_encode(array('error' => $e->getMessage().'<br>'.$e->getFile().', line '.$e->getLine()));
    return;
}

function get($param, $default=false){
	return (isset($_GET[$param])? $_GET[$param] : $default);
}

function costCmp($a, $b){
	$a = $a['summedSelfCost'];
	$b = $b['summedSelfCost'];
示例#5
0
文件: index.php 项目: hthetiot/basezf
     $remainingCost = $shownTotal * 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(Webgrind_Config::$dateFormat, filemtime(Webgrind_Config::xdebugOutputDir() . $dataFile));
     echo json_encode($result);
     break;
 case 'callinfo_list':
     $reader = Webgrind_FileHandler::getInstance()->getTraceReader(get('file'), get('costFormat', Webgrind_Config::$defaultCostformat));
     $functionNr = get('functionNr');
     $function = $reader->getFunctionInfo($functionNr);
     $result = array('calledFrom' => array(), 'subCalls' => array());
     $foundInvocations = 0;
     for ($i = 0; $i < $function['calledFromInfoCount']; $i++) {
         $invo = $reader->getCalledFromInfo($functionNr, $i);
         $foundInvocations += $invo['callCount'];
         $callerInfo = $reader->getFunctionInfo($invo['functionNr']);
         $invo['file'] = $callerInfo['file'];
         $invo['callerFunctionName'] = $callerInfo['functionName'];
         $result['calledFrom'][] = $invo;