Skip to content

Commit 1bf5198

Browse files
committed
added query profiling
1 parent b3bef92 commit 1bf5198

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/ArangoDBClient/Statement.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ class Statement
149149
* @var bool
150150
*/
151151
private $_failOnWarning = false;
152+
153+
/**
154+
* Whether or not the query should return profiling information
155+
*
156+
* @var bool
157+
*/
158+
private $_profile = false;
152159

153160
/**
154161
* Approximate memory limit value (in bytes) that a query can use on the server-side
@@ -202,6 +209,11 @@ class Statement
202209
*/
203210
const ENTRY_FAIL_ON_WARNING = 'failOnWarning';
204211

212+
/**
213+
* Profile flag
214+
*/
215+
const ENTRY_PROFILE = 'profile';
216+
205217
/**
206218
* Memory limit threshold for query
207219
*/
@@ -309,6 +321,10 @@ public function __construct(Connection $connection, array $data)
309321
$this->_failOnWarning = (bool) $data[self::ENTRY_FAIL_ON_WARNING];
310322
}
311323

324+
if (isset($data[self::ENTRY_PROFILE])) {
325+
$this->_profile = (bool) $data[self::ENTRY_PROFILE];
326+
}
327+
312328
if (isset($data[self::ENTRY_MEMORY_LIMIT])) {
313329
$this->_memoryLimit = (int) $data[self::ENTRY_MEMORY_LIMIT];
314330
}
@@ -658,6 +674,28 @@ public function getFailOnWarning()
658674
return $this->_failOnWarning;
659675
}
660676

677+
/**
678+
* Set whether or not query profiling should be enabled
679+
*
680+
* @param bool $value - value for profiling
681+
*
682+
* @return void
683+
*/
684+
public function setProfile($value = true)
685+
{
686+
$this->_profile = (bool) $value;
687+
}
688+
689+
/**
690+
* Get the configured value for profiling
691+
*
692+
* @return bool - current value of profiling option
693+
*/
694+
public function getProfiling()
695+
{
696+
return $this->_profile;
697+
}
698+
661699
/**
662700
* Set the approximate memory limit threshold to be used by the query on the server-side
663701
* (a value of 0 or less will mean the memory is not limited)
@@ -729,7 +767,8 @@ private function buildData()
729767
self::ENTRY_COUNT => $this->_doCount,
730768
'options' => [
731769
self::FULL_COUNT => $this->_fullCount,
732-
self::ENTRY_FAIL_ON_WARNING => $this->_failOnWarning
770+
self::ENTRY_FAIL_ON_WARNING => $this->_failOnWarning,
771+
self::ENTRY_PROFILE => $this->_profile
733772
]
734773
];
735774

tests/StatementTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,35 @@ public function testMaxRuntime()
609609
static::assertTrue($excepted);
610610
}
611611

612+
public function testProfiling()
613+
{
614+
$connection = $this->connection;
615+
616+
$statement = new Statement(
617+
$connection, [
618+
'query' => 'FOR i IN 1..10000 RETURN CONCAT("testisiteisiitit", i)',
619+
'_flat' => true
620+
]
621+
);
622+
static::assertFalse($statement->getProfiling());
623+
624+
$statement = new Statement(
625+
$connection, [
626+
'query' => 'FOR i IN 1..10000 RETURN CONCAT("testisiteisiitit", i)',
627+
'profile' => true,
628+
'_flat' => true
629+
]
630+
);
631+
632+
static::assertTrue($statement->getProfiling());
633+
634+
$cursor = $statement->execute();
635+
$result = $cursor->getExtra();
636+
static::assertArrayHasKey('profile', $result);
637+
static::assertTrue(is_array($result['profile']));
638+
static::assertArrayHasKey('executing', $result['profile']);
639+
}
640+
612641
public function testStatementStreaming()
613642
{
614643
$connection = $this->connection;

0 commit comments

Comments
 (0)