diff --git a/src/Controller/XHProfController.php b/src/Controller/XHProfController.php index a4d93e4..fb0ab4a 100644 --- a/src/Controller/XHProfController.php +++ b/src/Controller/XHProfController.php @@ -109,6 +109,10 @@ class XHProfController extends ControllerBase { '#type' => 'inline_template', '#template' => '

Summary

', ), + 'path' => array( + '#type' => 'inline_template', + '#template' => $this->t('Path: !path', array('!path' => $run->getPath())), + ), 'table' => array( '#theme' => 'table', '#header' => array(), diff --git a/src/XHProfLib/Run.php b/src/XHProfLib/Run.php index 35bc08a..85f42f3 100755 --- a/src/XHProfLib/Run.php +++ b/src/XHProfLib/Run.php @@ -18,6 +18,11 @@ class Run { * @var string */ private $namespace; + + /** + * @var string + */ + private $path; /** * @var array @@ -32,11 +37,13 @@ class Run { /** * @param string $run_id * @param string $namespace + * @param string $path * @param array $data */ - public function __construct($run_id, $namespace, $data) { + public function __construct($run_id, $namespace, $path, $data) { $this->run_id = $run_id; $this->namespace = $namespace; + $this->path = $path; $this->symbols = $this->parseSymbols($data); } @@ -47,6 +54,13 @@ class Run { return $this->run_id; } + /** + * @return string + */ + public function getPath() { + return $this->path; + } + /**+ * @return array */ diff --git a/src/XHProfLib/Storage/FileStorage.php b/src/XHProfLib/Storage/FileStorage.php index e7c6638..c229066 100755 --- a/src/XHProfLib/Storage/FileStorage.php +++ b/src/XHProfLib/Storage/FileStorage.php @@ -53,7 +53,7 @@ class FileStorage implements StorageInterface { throw new \UnexpectedValueException("Unable to unserialize $file_name!"); } - $run = new Run($run_id, $namespace, $contents); + $run = new Run($run_id, $namespace, $contents['path'], $contents['data']); return $run; } @@ -62,6 +62,7 @@ class FileStorage implements StorageInterface { */ public function getRuns($namespace = NULL) { $files = $this->scanXHProfDir($this->dir, $namespace); + $files = array_map(function ($f) { $f['date'] = strtotime($f['date']); return $f; @@ -75,13 +76,17 @@ class FileStorage implements StorageInterface { public function saveRun($data, $namespace, $run_id) { // Use PHP serialize function to store the XHProf's // raw profiler data. - $data = serialize($data); + $file_data = array( + 'data' => $data, + 'path' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'], + ); + $file_data = serialize($file_data); $file_name = $this->fileName($run_id, $namespace); $file = fopen($file_name, 'w'); if ($file) { - fwrite($file, $data); + fwrite($file, $file_data); fclose($file); } else { @@ -102,11 +107,13 @@ class FileStorage implements StorageInterface { if (is_dir($dir)) { foreach (glob("{$this->dir}/*.{$this->suffix}") as $file) { preg_match("/(?:(?\w+)\.)(?:(?[^.]+)\.)(?[\w.]+)/", basename($file), $matches); + $run = $this->getRun($matches['run'], $matches['namespace']); $runs[] = array( 'run_id' => $matches['run'], 'namespace' => $matches['namespace'], 'basename' => htmlentities(basename($file)), 'date' => date("Y-m-d H:i:s", filemtime($file)), + 'path' => $run->getPath(), ); } }