/** * 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()) . '/'; }
/** * 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; }
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'];
$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;