X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fsrc%2FCommands%2Fcore%2FXhprofCommands.php;fp=vendor%2Fdrush%2Fdrush%2Fsrc%2FCommands%2Fcore%2FXhprofCommands.php;h=d5cdad7564632cee56bd1fe62d7b3cee067f31c2;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/src/Commands/core/XhprofCommands.php b/vendor/drush/drush/src/Commands/core/XhprofCommands.php new file mode 100644 index 000000000..d5cdad756 --- /dev/null +++ b/vendor/drush/drush/src/Commands/core/XhprofCommands.php @@ -0,0 +1,90 @@ + self::REQ]) + { + } + + /** + * Enable profiling via XHProf + * + * @hook post-command * + */ + public function xhprofPost($result, CommandData $commandData) + { + 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'; + $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])); + } + } + + /** + * Enable profiling via XHProf + * + * @hook init * + */ + public function xhprofInitialize(InputInterface $input, AnnotationData $annotationData) + { + if (self::xhprofIsEnabled($input)) { + $config = Drush::config()->get('xh'); + $flags = self::xhprofFlags($config); + \xhprof_enable($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.')); + } + return true; + } + } + + /** + * Determines flags. + */ + public static function xhprofFlags(array $config) + { + $flags = 0; + if (!(isset($config['profile-builtins']) ? $config['profile-builtins']: self::XH_PROFILE_BUILTINS)) { + $flags |= XHPROF_FLAGS_NO_BUILTINS; + } + if (isset($config['profile-cpu']) ? $config['profile-cpu'] : self::XH_PROFILE_CPU) { + $flags |= XHPROF_FLAGS_CPU; + } + if (isset($config['profile-memory']) ? $config['profile-memory'] : self::XH_PROFILE_MEMORY) { + $flags |= XHPROF_FLAGS_MEMORY; + } + return $flags; + } +}