Merge pull request #645 from merk/stopwatch
Add stopwatch support for Elastica\Client
This commit is contained in:
commit
425aa3d3e1
|
@ -5,6 +5,7 @@ namespace FOS\ElasticaBundle\Elastica;
|
||||||
use Elastica\Client as BaseClient;
|
use Elastica\Client as BaseClient;
|
||||||
use Elastica\Request;
|
use Elastica\Request;
|
||||||
use FOS\ElasticaBundle\Logger\ElasticaLogger;
|
use FOS\ElasticaBundle\Logger\ElasticaLogger;
|
||||||
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the default Elastica client to provide logging for errors that occur
|
* Extends the default Elastica client to provide logging for errors that occur
|
||||||
|
@ -21,11 +22,22 @@ class Client extends BaseClient
|
||||||
*/
|
*/
|
||||||
private $indexCache = array();
|
private $indexCache = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symfony's debugging Stopwatch
|
||||||
|
*
|
||||||
|
* @var Stopwatch|null
|
||||||
|
*/
|
||||||
|
private $stopwatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function request($path, $method = Request::GET, $data = array(), array $query = array())
|
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);
|
$start = microtime(true);
|
||||||
$response = parent::request($path, $method, $data, $query);
|
$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);
|
$this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->stopwatch) {
|
||||||
|
$this->stopwatch->stop('es_request');
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,4 +71,14 @@ class Client extends BaseClient
|
||||||
|
|
||||||
return $this->indexCache[$name] = new Index($this, $name);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
<service id="fos_elastica.client_prototype" class="%fos_elastica.client.class%" abstract="true">
|
<service id="fos_elastica.client_prototype" class="%fos_elastica.client.class%" abstract="true">
|
||||||
<argument type="collection" /> <!-- configuration -->
|
<argument type="collection" /> <!-- configuration -->
|
||||||
<argument /> <!-- callback -->
|
<argument /> <!-- callback -->
|
||||||
|
|
||||||
|
<call method="setStopwatch">
|
||||||
|
<argument type="service" id="debug.stopwatch" />
|
||||||
|
</call>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="fos_elastica.config_manager" class="FOS\ElasticaBundle\Configuration\ConfigManager">
|
<service id="fos_elastica.config_manager" class="FOS\ElasticaBundle\Configuration\ConfigManager">
|
||||||
|
|
Loading…
Reference in a new issue