diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php
index 6947bfcc3a..83ee051458 100644
--- a/pandora_console/ajax.php
+++ b/pandora_console/ajax.php
@@ -14,6 +14,15 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
+// Enable profiler for testing
+if (!defined("__PAN_XHPROF__")) define ("__PAN_XHPROF__", 0);
+
+if (__PAN_XHPROF__ === 1) {
+ if (function_exists('tideways_xhprof_enable')) {
+ tideways_xhprof_enable();
+ }
+}
+
if ((! file_exists("include/config.php")) || (! is_readable("include/config.php"))) {
exit;
}
@@ -90,4 +99,8 @@ if (file_exists ($page)) {
else {
echo '
Sorry! I can\'t find the page '.$page.'!';
}
+
+if (__PAN_XHPROF__ === 1) {
+ pandora_xhprof_display_result("ajax", "console");
+}
?>
diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php
index ff2ce52deb..ae6ac202bd 100644
--- a/pandora_console/include/functions.php
+++ b/pandora_console/include/functions.php
@@ -3391,5 +3391,39 @@ function validate_csrf_code() {
function generate_hash_to_api(){
hash('sha256', db_get_value ('value', 'tupdate_settings', '`key`', 'customer_key'));
+}
+
+/**
+ * Disable the profiller and display de result
+ *
+ * @param string Key to identify the profiler run.
+ * @param string Way to display the result
+ * "link" (default): Click into word "Performance" to display the profilling info.
+ * "console": Display with a message in pandora_console.log.
+ */
+function pandora_xhprof_display_result($key = "", $method = "link") {
+ // Check if function exists
+ if (!function_exists('tideways_xhprof_disable')) {
+ error_log("Cannot find tideways_xhprof_disable function");
+ return;
}
+
+ $run_id = uniqid();
+ $data = tideways_xhprof_disable();
+ $source = "pandora_$key";
+ file_put_contents(
+ sys_get_temp_dir() . "/" . $run_id . ".$source.xhprof",
+ serialize($data)
+ );
+ $new_url = "http://{$_SERVER['HTTP_HOST']}/profiler/index.php?run={$run_id}&source={$source}";
+ switch($method) {
+ case "console":
+ error_log("'{$new_url}'");
+ case "link":
+ default:
+ echo "Performance\n";
+ break;
+
+ }
+}
?>
diff --git a/pandora_console/index.php b/pandora_console/index.php
index 9111aec168..8669f39d2d 100755
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -14,6 +14,17 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
+// Enable profiler for testing
+if (!defined("__PAN_XHPROF__")) define ("__PAN_XHPROF__", 0);
+
+if (__PAN_XHPROF__ === 1) {
+ if (function_exists('tideways_xhprof_enable')) {
+ tideways_xhprof_enable();
+ } else {
+ error_log("Cannot find tideways_xhprof_enable function");
+ }
+}
+
//Set character encoding to UTF-8 - fixes a lot of multibyte character headaches
if (function_exists ('mb_internal_encoding')) {
mb_internal_encoding ("UTF-8");
@@ -1266,3 +1277,8 @@ require('include/php_to_js_values.php');
*/
}
+
\ No newline at end of file