-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
205 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ | |
$profiler->stop($cache); | ||
|
||
$view = $profiler->start('PDO::exec', ['query' => 'DELETE FROM users WHERE email = "[email protected]"'], 'Database'); | ||
usleep($wait(50)); | ||
usleep($wait(100)); | ||
$profiler->stop($view); | ||
|
||
$cache = $profiler->start('Phalcon\Cache\Backend\Apc::exists', ['get' => 'app_data__lorem_ipsum'], 'Cache'); | ||
|
@@ -104,13 +104,12 @@ | |
usleep($wait(20)); | ||
$profiler->stop($cache); | ||
|
||
$view = $profiler->start('PDO::query', ['query' => 'SELECT userLoginEmail, userID, userLoginPassword FROM users LIMIT 2500;'], 'Database'); | ||
usleep($wait(350)); | ||
$profiler->stop($view); | ||
for ($i=0; $i <= 3; $i++) { | ||
$view = $profiler->start('PDO::query', ['query' => 'SELECT article.*, author.name FROM article JOIN author ON article.author_id = author.id WHERE article.id = ?;'], 'Database'); | ||
usleep($wait(150)); | ||
$profiler->stop($view); | ||
} | ||
|
||
$view = $profiler->start('PDO::query', ['query' => 'SELECT lorem, ipsum FROM foobar WHERE id = ? LIMIT 1;'], 'Database'); | ||
usleep($wait(50)); | ||
$profiler->stop($view); | ||
|
||
$cache = $profiler->start('Phalcon\Cache\Backend\Apc::exists', ['get' => 'app_data__lorem_ipsum'], 'Cache'); | ||
usleep($wait(20)); | ||
|
@@ -120,13 +119,12 @@ | |
usleep($wait(20)); | ||
$profiler->stop($cache); | ||
|
||
$view = $profiler->start('PDO::query', ['query' => 'SELECT lorem, ipsum FROM foobar WHERE id = ? LIMIT 1;'], 'Database'); | ||
usleep($wait(60)); | ||
$profiler->stop($view); | ||
for ($i=0; $i <= 8; $i++) { | ||
$query = $profiler->start('PDO::query', ['query' => 'SELECT lorem, ipsum FROM foobar WHERE id = ? LIMIT 1;'], 'Database'); | ||
usleep($wait(rand(70, 100))); | ||
$profiler->stop($query); | ||
} | ||
|
||
$view = $profiler->start('PDO::query', ['query' => 'SELECT lorem, ipsum FROM foobar WHERE id = ? LIMIT 1;'], 'Database'); | ||
usleep($wait(70)); | ||
$profiler->stop($view); | ||
|
||
$view = $profiler->start('View::render', ['data' => ['user' => ['name' => 'John Doe', 'age' => 26]], 'foobar' => 123], 'View'); | ||
usleep($wait(10)); | ||
|
72 changes: 72 additions & 0 deletions
72
src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* @author @shochdoerfer <[email protected]> | ||
* @created 18.10.15, 12:14 | ||
*/ | ||
namespace Fabfuel\Prophiler\Adapter\Interop\Container; | ||
|
||
use Fabfuel\Prophiler\Adapter\AdapterAbstract; | ||
use Fabfuel\Prophiler\ProfilerInterface; | ||
use Interop\Container\ContainerInterface; | ||
|
||
class Container extends AdapterAbstract implements ContainerInterface | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* Creates a new {@link \Fabfuel\Prophiler\Adapter\Interop\Container\Container}. | ||
* | ||
* @param ContainerInterface $container | ||
* @param ProfilerInterface $profiler | ||
*/ | ||
public function __construct(ContainerInterface $container, ProfilerInterface $profiler) | ||
{ | ||
parent::__construct($profiler); | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($id) | ||
{ | ||
$entry = null; | ||
$metadata = [ | ||
'id' => $id | ||
]; | ||
|
||
try { | ||
$benchmark = $this->profiler->start('Container::get', $metadata, 'Container-Interop'); | ||
$entry = $this->container->get($id); | ||
} catch (\Exception $e) { | ||
// exception needs to be catched and thrown after stopping the profiler | ||
} | ||
|
||
$this->profiler->stop($benchmark); | ||
|
||
if (isset($e)) { | ||
throw $e; | ||
} | ||
|
||
return $entry; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($id) | ||
{ | ||
$metadata = [ | ||
'id' => $id | ||
]; | ||
$benchmark = $this->profiler->start('Container::has', $metadata, 'Container-Interop'); | ||
|
||
$has = $this->container->has($id); | ||
|
||
$this->profiler->stop($benchmark); | ||
return $has; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
tests/Fabfuel/Prophiler/Adapter/Interop/Container/ContainerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* @author @shochdoerfer <[email protected]> | ||
* @created 23.10.15, 10:59 | ||
*/ | ||
namespace Fabfuel\Prophiler\Adapter\Interop\Container; | ||
|
||
use \Fabfuel\Prophiler\Benchmark\Benchmark; | ||
|
||
class ContainerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Interop\Container\ContainerInterface | ||
*/ | ||
protected $container; | ||
/** | ||
* @var \Fabfuel\Prophiler\ProfilerInterface | ||
*/ | ||
protected $profiler; | ||
/** | ||
* @var \Fabfuel\Prophiler\Adapter\Interop\Container\Container | ||
*/ | ||
protected $adapter; | ||
|
||
/** | ||
* @see PHPUnit_Framework_TestCase::setUp() | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->container = $this->getMock('Interop\Container\ContainerInterface'); | ||
$this->profiler = $this->getMock('Fabfuel\Prophiler\ProfilerInterface'); | ||
$this->adapter = new Container($this->container, $this->profiler); | ||
} | ||
|
||
public function testHasCallTriggersProfiler() | ||
{ | ||
$this->profiler->expects($this->once()) | ||
->method('start') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
$this->profiler->expects($this->once()) | ||
->method('stop') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
|
||
$this->adapter->has('sample-id'); | ||
} | ||
|
||
public function testGetCallTriggersProfiler() | ||
{ | ||
$this->profiler->expects($this->once()) | ||
->method('start') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
$this->profiler->expects($this->once()) | ||
->method('stop') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
$this->container->expects($this->once()) | ||
->method('get') | ||
->will($this->returnValue(new \stdClass())); | ||
|
||
$instance = $this->adapter->get('sample-id'); | ||
$this->assertInstanceOf('\stdClass', $instance); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
*/ | ||
public function testGetCallThrowsExceptionAndStillTriggersProfiler() | ||
{ | ||
$this->profiler->expects($this->once()) | ||
->method('start') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
$this->profiler->expects($this->once()) | ||
->method('stop') | ||
->will($this->returnValue(new Benchmark('test'))); | ||
$this->container->expects($this->once()) | ||
->method('get') | ||
->will($this->throwException(new \RuntimeException())); | ||
|
||
$instance = $this->adapter->get('sample-id'); | ||
} | ||
} |