diff --git a/Elastica/Client.php b/Elastica/Client.php
index e921965..1131ba5 100644
--- a/Elastica/Client.php
+++ b/Elastica/Client.php
@@ -5,6 +5,7 @@ namespace FOS\ElasticaBundle\Elastica;
use Elastica\Client as BaseClient;
use Elastica\Request;
use FOS\ElasticaBundle\Logger\ElasticaLogger;
+use Symfony\Component\Stopwatch\Stopwatch;
/**
* Extends the default Elastica client to provide logging for errors that occur
@@ -21,11 +22,22 @@ class Client extends BaseClient
*/
private $indexCache = array();
+ /**
+ * Symfony's debugging Stopwatch
+ *
+ * @var Stopwatch|null
+ */
+ private $stopwatch;
+
/**
* {@inheritdoc}
*/
public function request($path, $method = Request::GET, $data = array(), array $query = array())
{
+ if ($this->stopwatch) {
+ $this->stopwatch->start('es_request', 'fos_elastica');
+ }
+
$start = microtime(true);
$response = parent::request($path, $method, $data, $query);
@@ -44,6 +56,10 @@ class Client extends BaseClient
$this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
}
+ if ($this->stopwatch) {
+ $this->stopwatch->stop('es_request');
+ }
+
return $response;
}
@@ -55,4 +71,14 @@ class Client extends BaseClient
return $this->indexCache[$name] = new Index($this, $name);
}
+
+ /**
+ * Sets a stopwatch instance for debugging purposes.
+ *
+ * @param Stopwatch $stopwatch
+ */
+ public function setStopwatch(Stopwatch $stopwatch = null)
+ {
+ $this->stopwatch = $stopwatch;
+ }
}
diff --git a/Resources/config/config.xml b/Resources/config/config.xml
index 023688f..dcec2e8 100644
--- a/Resources/config/config.xml
+++ b/Resources/config/config.xml
@@ -16,6 +16,10 @@
+
+
+
+