X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrush%2Fdrush%2Fsrc%2FCommands%2Fcore%2FXhprofCommands.php;fp=vendor%2Fdrush%2Fdrush%2Fsrc%2FCommands%2Fcore%2FXhprofCommands.php;h=19531d0eb9852b98e5735c999de8d683889c59fd;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=d5cdad7564632cee56bd1fe62d7b3cee067f31c2;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/vendor/drush/drush/src/Commands/core/XhprofCommands.php b/vendor/drush/drush/src/Commands/core/XhprofCommands.php index d5cdad756..19531d0eb 100644 --- a/vendor/drush/drush/src/Commands/core/XhprofCommands.php +++ b/vendor/drush/drush/src/Commands/core/XhprofCommands.php @@ -8,6 +8,19 @@ use Drush\Drush; use Symfony\Component\Console\Input\InputInterface; use Drush\Commands\DrushCommands; +/** + * Class XhprofCommands + * @package Drush\Commands\core + * + * Supports profiling Drush commands using either XHProf or Tideways XHProf. + * + * Note that XHProf is only compatible with PHP 5.6. For PHP 7+, you must use + * the Tideways XHProf fork. The Tideways XHProf extension recently underwent a + * major refactor; Drush is only compatible with the newer version. + * @see https://tideways.com/profiler/blog/releasing-new-tideways-xhprof-extension + * + * @todo Remove support for XHProf extension once PHP 5.6 is EOL. + */ class XhprofCommands extends DrushCommands { @@ -37,10 +50,7 @@ class XhprofCommands extends DrushCommands { if (self::xhprofIsEnabled()) { $namespace = 'Drush'; - $xhprof_data = xhprof_disable(); - $xhprof_runs = new \XHProfRuns_Default(); - $run_id = $xhprof_runs->save_run($xhprof_data, $namespace); - $namespace = 'Drush'; + $run_id = self::xhprofFinishRun($namespace); $url = Drush::config()->get('xh.link') . '/index.php?run=' . urlencode($run_id) . '&source=' . urlencode($namespace); $this->logger()->notice(dt('XHProf run saved. View report at !url', ['!url' => $url])); } @@ -53,25 +63,32 @@ class XhprofCommands extends DrushCommands */ public function xhprofInitialize(InputInterface $input, AnnotationData $annotationData) { - if (self::xhprofIsEnabled($input)) { + if (self::xhprofIsEnabled()) { $config = Drush::config()->get('xh'); $flags = self::xhprofFlags($config); - \xhprof_enable($flags); + self::xhprofEnable($flags); } } public static function xhprofIsEnabled() { if (Drush::config()->get('xh.link')) { - if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { - throw new \Exception(dt('You must enable the xhprof or tideways PHP extensions in your CLI PHP in order to profile.')); + if (!extension_loaded('xhprof') && !extension_loaded('tideways_xhprof')) { + if (extension_loaded('tideways')) { + throw new \Exception(dt('You are using an older incompatible version of the tideways extension. Please upgrade to the new tideways_xhprof extension.')); + } else { + throw new \Exception(dt('You must enable the xhprof or tideways_xhprof PHP extensions in your CLI PHP in order to profile.')); + } } return true; } + return false; } /** * Determines flags. + * + * TODO: Make these work for Tideways as well. */ public static function xhprofFlags(array $config) { @@ -87,4 +104,34 @@ class XhprofCommands extends DrushCommands } return $flags; } + + /** + * Enable profiling. + */ + public static function xhprofEnable($flags) + { + if (extension_loaded('tideways_xhprof')) { + \tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU); + } else { + \xhprof_enable($flags); + } + } + + /** + * Disable profiling and save results. + */ + public function xhprofFinishRun($namespace) + { + if (extension_loaded('tideways_xhprof')) { + $data = \tideways_xhprof_disable(); + $dir = $this->getConfig()->tmp(); + $run_id = uniqid(); + file_put_contents($dir . DIRECTORY_SEPARATOR . $run_id . '.' . $namespace . '.xhprof', serialize($data)); + return $run_id; + } else { + $xhprof_data = \xhprof_disable(); + $xhprof_runs = new \XHProfRuns_Default(); + return $xhprof_runs->save_run($xhprof_data, $namespace); + } + } }