|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Configuration for webgrind |
| 5 | + * @author Jacob Oettinger |
| 6 | + * @author Joakim Nygård |
| 7 | + */ |
| 8 | +class Webgrind_Config extends Webgrind_MasterConfig { |
| 9 | + /** |
| 10 | + * Automatically check if a newer version of webgrind is available for download |
| 11 | + */ |
| 12 | + static $checkVersion = true; |
| 13 | + static $hideWebgrindProfiles = true; |
| 14 | + |
| 15 | + /** |
| 16 | + * Writable dir for information storage. |
| 17 | + * If empty, will use system tmp folder or xdebug tmp |
| 18 | + */ |
| 19 | + static $storageDir = ''; |
| 20 | + static $profilerDir = ''; |
| 21 | + |
| 22 | + /** |
| 23 | + * Suffix for preprocessed files |
| 24 | + */ |
| 25 | + static $preprocessedSuffix = '.webgrind'; |
| 26 | + |
| 27 | + /** |
| 28 | + * Image type of graph to output |
| 29 | + * Can be png or svg |
| 30 | + */ |
| 31 | + static $graphImageType = 'svg'; |
| 32 | + |
| 33 | + static $defaultTimezone = 'UTC'; |
| 34 | + static $dateFormat = 'Y-m-d H:i:s'; |
| 35 | + static $defaultCostformat = 'percent'; // 'percent', 'usec' or 'msec' |
| 36 | + static $defaultFunctionPercentage = 90; |
| 37 | + static $defaultHideInternalFunctions = false; |
| 38 | + |
| 39 | + /** |
| 40 | + * Path to python executable |
| 41 | + */ |
| 42 | + static $pythonExecutable = '/usr/bin/python'; |
| 43 | + |
| 44 | + /** |
| 45 | + * Path to graphviz dot executable |
| 46 | + */ |
| 47 | + static $dotExecutable = '/usr/bin/dot'; |
| 48 | + |
| 49 | + /** |
| 50 | + * sprintf compatible format for generating links to source files. |
| 51 | + * %1$s will be replaced by the full path name of the file |
| 52 | + * %2$d will be replaced by the linenumber |
| 53 | + */ |
| 54 | + static $fileUrlFormat = 'index.php?op=fileviewer&file=%1$s#line%2$d'; // Built in fileviewer |
| 55 | + //static $fileUrlFormat = 'txmt://open/?url=file://%1$s&line=%2$d'; // Textmate |
| 56 | + //static $fileUrlFormat = 'file://%1$s'; // ? |
| 57 | +
|
| 58 | + /** |
| 59 | + * format of the trace drop down list |
| 60 | + * default is: invokeurl (tracefile_name) [tracefile_size] |
| 61 | + * the following options will be replaced: |
| 62 | + * %i - invoked url |
| 63 | + * %f - trace file name |
| 64 | + * %s - size of trace file |
| 65 | + * %m - modified time of file name (in dateFormat specified above) |
| 66 | + */ |
| 67 | + static $traceFileListFormat = '%i (%f) [%s]'; |
| 68 | + |
| 69 | + /** |
| 70 | + * Proxy functions are stepped over transparently. Functions listed here |
| 71 | + * MUST make exactly one (though not necessarily the same one) function |
| 72 | + * call per execution. |
| 73 | + */ |
| 74 | + static $proxyFunctions = array( // resolve dynamic function calls in-place |
| 75 | + 'php::call_user_func', |
| 76 | + 'php::call_user_func_array', |
| 77 | + ); |
| 78 | + //static $proxyFunctions = array(); // do not skip any functions |
| 79 | + |
| 80 | + /** |
| 81 | + * Specify which fields display, and the order to display them. Uncomment |
| 82 | + * entries to enable, move entries to change order. |
| 83 | + */ |
| 84 | + static $tableFields = array( |
| 85 | + 'Invocation Count', |
| 86 | + 'Total Self Cost', |
| 87 | + //'Average Self Cost', |
| 88 | + 'Total Inclusive Cost', |
| 89 | + //'Average Inclusive Cost', |
| 90 | + ); |
| 91 | + |
| 92 | + ######################### |
| 93 | + # BELOW NOT FOR EDITING # |
| 94 | + ######################### |
| 95 | + |
| 96 | + /** |
| 97 | + * Regex that matches the trace files generated by xdebug |
| 98 | + */ |
| 99 | + static function xdebugOutputFormat() { |
| 100 | + $outputName = ini_get('xdebug.profiler_output_name'); |
| 101 | + if ($outputName=='') // Ini value not defined |
| 102 | + $outputName = '/^cachegrind\.out\..+$/'; |
| 103 | + else |
| 104 | + $outputName = '/^'.preg_replace('/(%[^%])+/', '.+', $outputName).'$/'; |
| 105 | + return $outputName; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Directory to search for trace files |
| 110 | + */ |
| 111 | + static function xdebugOutputDir() { |
| 112 | + $dir = ini_get('xdebug.profiler_output_dir'); |
| 113 | + if ($dir=='') // Ini value not defined |
| 114 | + return realpath(Webgrind_Config::$profilerDir).'/'; |
| 115 | + return realpath($dir).'/'; |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Writable dir for information storage |
| 120 | + */ |
| 121 | + static function storageDir() { |
| 122 | + if (!empty(Webgrind_Config::$storageDir)) |
| 123 | + return realpath(Webgrind_Config::$storageDir).'/'; |
| 124 | + |
| 125 | + if (!function_exists('sys_get_temp_dir') || !is_writable(sys_get_temp_dir())) { |
| 126 | + // use xdebug setting |
| 127 | + return Webgrind_Config::xdebugOutputDir(); |
| 128 | + } |
| 129 | + return realpath(sys_get_temp_dir()).'/'; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Binary version of the preprocessor (for faster preprocessing) |
| 134 | + * |
| 135 | + * If the proper tools are installed and the bin dir is writeable for php, |
| 136 | + * automatically compile it (when necessary). |
| 137 | + * Automatic compilation disabled if `bin/make-failed` exists. |
| 138 | + * Run `make` in the webgrind root directory to manually compile. |
| 139 | + */ |
| 140 | + static function getBinaryPreprocessor() { |
| 141 | + $localBin = __DIR__.'/bin/'; |
| 142 | + $makeFailed = $localBin.'make-failed'; |
| 143 | + if (PHP_OS == 'WINNT') { |
| 144 | + $binary = $localBin.'preprocessor.exe'; |
| 145 | + } else { |
| 146 | + $binary = $localBin.'preprocessor'; |
| 147 | + } |
| 148 | + |
| 149 | + if (!file_exists($binary) && is_writable($localBin) && !file_exists($makeFailed)) { |
| 150 | + if (PHP_OS == 'WINNT') { |
| 151 | + $success = static::compileBinaryPreprocessorWindows(); |
| 152 | + } else { |
| 153 | + $success = static::compileBinaryPreprocessor(); |
| 154 | + } |
| 155 | + if (!$success || !file_exists($binary)) { |
| 156 | + touch($makeFailed); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + return $binary; |
| 161 | + } |
| 162 | + |
| 163 | + static function compileBinaryPreprocessor() { |
| 164 | + $make = '/usr/bin/make'; |
| 165 | + if (is_executable($make)) { |
| 166 | + $cwd = getcwd(); |
| 167 | + chdir(__DIR__); |
| 168 | + exec($make, $output, $retval); |
| 169 | + chdir($cwd); |
| 170 | + return $retval == 0; |
| 171 | + } |
| 172 | + return false; |
| 173 | + } |
| 174 | + |
| 175 | + static function compileBinaryPreprocessorWindows() { |
| 176 | + if (getenv('VSAPPIDDIR')) { |
| 177 | + $cwd = getcwd(); |
| 178 | + chdir(__DIR__); |
| 179 | + exec('call "%VSAPPIDDIR%\..\Tools\vsdevcmd\ext\vcvars.bat" && nmake -f nmakefile', $output, $retval); |
| 180 | + chdir($cwd); |
| 181 | + return $retval == 0; |
| 182 | + } elseif (getenv('VS140COMNTOOLS')) { |
| 183 | + $cwd = getcwd(); |
| 184 | + chdir(__DIR__); |
| 185 | + exec('call "%VS140COMNTOOLS%\vsvars32.bat" && nmake -f nmakefile', $output, $retval); |
| 186 | + chdir($cwd); |
| 187 | + return $retval == 0; |
| 188 | + } |
| 189 | + return false; |
| 190 | + } |
| 191 | +} |
0 commit comments