diff --git a/README.md b/README.md index 58e3cc7..20fab92 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,35 @@ wp profile hook [--url=] [--fields=] [--format=] - csv --- + + +### wp profile eval + +Profile arbitrary code execution. + +~~~ +wp profile eval [--fields=] [--format=] +~~~ + +**OPTIONS** + + + The code to execute, as a string. + + [--fields=] + Display one or more fields. + + [--format=] + Render output in a particular format. + --- + default: table + options: + - table + - json + - yaml + - csv + --- + ## Installing [Get access to `wp profile` for only $129 per year](https://runcommand.memberful.com/checkout?plan=16079). Purchasing an annual subscription locks you into this price for as long as you stay subscribed. Subscriptions include unlimited downloads of the command, plus support and updates for the length of your subscription. diff --git a/composer.json b/composer.json index d4a8b01..84b368b 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "extra": { "commands": [ "profile stage", - "profile hook" + "profile hook", + "profile eval" ], "readme": { "shields": [ diff --git a/features/profile-eval.feature b/features/profile-eval.feature new file mode 100644 index 0000000..a777b5d --- /dev/null +++ b/features/profile-eval.feature @@ -0,0 +1,37 @@ +Feature: Profile arbitary code execution + + Scenario: Profile a function that doesn't do anything + Given a WP install + And a wp-content/mu-plugins/lame-function.php file: + """ + display_items( $this->loggers ); } + /** + * Profile arbitrary code execution. + * + * ## OPTIONS + * + * + * : The code to execute, as a string. + * + * [--fields=] + * : Display one or more fields. + * + * [--format=] + * : Render output in a particular format. + * --- + * default: table + * options: + * - table + * - json + * - yaml + * - csv + * --- + * + * @when before_wp_load + * @subcommand eval + */ + public function eval_( $args, $assoc_args ) { + + $this->run_profiler(); + + $logger = new Logger( 'eval', 'eval' ); + $logger->start(); + eval( $args[0] ); + $logger->stop(); + + $fields = array( + 'time', + 'query_time', + 'query_count', + 'cache_ratio', + 'cache_hits', + 'cache_misses', + 'request_time', + 'request_count', + ); + $formatter = new Formatter( $assoc_args, $fields ); + $formatter->display_items( array( $logger ) ); + } + /** * Profiling verbosity at the beginning of every action and filter */