From 662225fc72d8f099d797e6091c64cc865acbbad8 Mon Sep 17 00:00:00 2001 From: Fabian Fuelling Date: Sun, 9 Aug 2015 16:37:08 +0200 Subject: [PATCH 1/7] Improve demo page for aggregations --- public/demo.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/public/demo.php b/public/demo.php index 8d9c729..aaf48e5 100644 --- a/public/demo.php +++ b/public/demo.php @@ -93,7 +93,7 @@ $profiler->stop($cache); $view = $profiler->start('PDO::exec', ['query' => 'DELETE FROM users WHERE email = "foo@bar.com"'], '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)); From 9371a7758f5d7200ebeaabad323a3cb9798dfd0f Mon Sep 17 00:00:00 2001 From: Fabian Fuelling Date: Sun, 20 Sep 2015 08:20:28 +0200 Subject: [PATCH 2/7] Replace href "#" with "javascript:void;" to not jump to top of the page, when clicking a button --- src/Fabfuel/Prophiler/View/toolbar.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Fabfuel/Prophiler/View/toolbar.phtml b/src/Fabfuel/Prophiler/View/toolbar.phtml index 204e3f6..1870924 100644 --- a/src/Fabfuel/Prophiler/View/toolbar.phtml +++ b/src/Fabfuel/Prophiler/View/toolbar.phtml @@ -23,13 +23,13 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;
  • - Timeline + Timeline
  • - + @@ -44,7 +44,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter; = 1): ?>
  • - + Logs @@ -57,7 +57,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;
  • - getIcon() ?> getTitle() ?> + getIcon() ?> getTitle() ?>
  • From 2957595e824cafd21d35d6d4927ae12af8e3adc9 Mon Sep 17 00:00:00 2001 From: "lazos@lazos.me" Date: Tue, 22 Sep 2015 21:17:31 +0200 Subject: [PATCH 3/7] Fix #42 --- src/Fabfuel/Prophiler/View/toolbar.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Fabfuel/Prophiler/View/toolbar.phtml b/src/Fabfuel/Prophiler/View/toolbar.phtml index 1870924..727f988 100644 --- a/src/Fabfuel/Prophiler/View/toolbar.phtml +++ b/src/Fabfuel/Prophiler/View/toolbar.phtml @@ -23,13 +23,13 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;
  • - Timeline + Timeline
  • - + @@ -44,7 +44,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter; = 1): ?>
  • - + Logs @@ -57,7 +57,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;
  • - getIcon() ?> getTitle() ?> + getIcon() ?> getTitle() ?>
  • From ef2c69d9c31afe64a2c50ce16a677fa2feb8619a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Sun, 18 Oct 2015 21:42:59 +0200 Subject: [PATCH 4/7] Added Container-Interop adapter to be able to measure how long the object instantiation takes. --- composer.json | 3 +- composer.lock | 40 +++++++++-- .../Adapter/Interop/Container/Container.php | 68 +++++++++++++++++++ 3 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php diff --git a/composer.json b/composer.json index e33a4d3..794dfd2 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ }, "require": { "psr/log": "~1.0", - "php" : "~5.4" + "php" : "~5.4", + "container-interop/container-interop": "^1.1" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/composer.lock b/composer.lock index a352478..cd491ec 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2885e296b1c755384b0d5f3c2b1841ef", + "hash": "774e6620e7b8bc51472bd55a290d7796", + "content-hash": "5ee0ac787bbc5fdca7284b90a5ca3103", "packages": [ + { + "name": "container-interop/container-interop", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "time": "2014-12-30 15:22:37" + }, { "name": "psr/log", "version": "1.0.0", @@ -1034,7 +1062,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/f7e231d866ae2bdb2d175a7907cb229bed52d187", + "url": "https://api.github.com/repos/phalcon/phalcon-devtools/zipball/aabf4b07df813b1d0011dab67b5746abdb560cdc", "reference": "f7e231d866ae2bdb2d175a7907cb229bed52d187", "shasum": "" }, @@ -2081,12 +2109,12 @@ "version": "v2.7.1", "source": { "type": "git", - "url": "https://github.com/symfony/Console.git", + "url": "https://github.com/symfony/console.git", "reference": "564398bc1f33faf92fc2ec86859983d30eb81806" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/564398bc1f33faf92fc2ec86859983d30eb81806", + "url": "https://api.github.com/repos/symfony/console/zipball/564398bc1f33faf92fc2ec86859983d30eb81806", "reference": "564398bc1f33faf92fc2ec86859983d30eb81806", "shasum": "" }, @@ -2138,12 +2166,12 @@ "version": "v2.7.1", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", + "url": "https://github.com/symfony/event-dispatcher.git", "reference": "be3c5ff8d503c46768aeb78ce6333051aa6f26d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/be3c5ff8d503c46768aeb78ce6333051aa6f26d9", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/be3c5ff8d503c46768aeb78ce6333051aa6f26d9", "reference": "be3c5ff8d503c46768aeb78ce6333051aa6f26d9", "shasum": "" }, diff --git a/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php new file mode 100644 index 0000000..02b8385 --- /dev/null +++ b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php @@ -0,0 +1,68 @@ + + * @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) + { + try { + $metadata = [ + 'id' => $id + ]; + $benchmark = $this->profiler->start('Container::get', $metadata, 'Container-Interop'); + + $entry = $this->container->get($id); + } catch (\Exception $e) { + } + + $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; + } +} From 1929daf5e05ad49671137490539dfe46b3a88bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Fri, 23 Oct 2015 19:55:06 +0200 Subject: [PATCH 5/7] Moved container-interop/container-interop to require-dev section. --- composer.json | 6 +++--- composer.lock | 58 +++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 794dfd2..85877e5 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ }, "require": { "psr/log": "~1.0", - "php" : "~5.4", - "container-interop/container-interop": "^1.1" + "php" : "~5.4" }, "require-dev": { "phpunit/phpunit": "~4.0", @@ -28,7 +27,8 @@ "doctrine/orm": "~2.4", "erusev/parsedown": "~1.5", "phalcon/devtools": "1.3.*@dev", - "elasticsearch/elasticsearch": "~1.3" + "elasticsearch/elasticsearch": "~1.3", + "container-interop/container-interop": "^1.1" }, "suggest": { "phalcon/devtools": "This tools provide you useful scripts, helping to develop applications that use with Phalcon.", diff --git a/composer.lock b/composer.lock index cd491ec..ad0981c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,36 +4,9 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "774e6620e7b8bc51472bd55a290d7796", - "content-hash": "5ee0ac787bbc5fdca7284b90a5ca3103", + "hash": "d94e8ee441efc4045a37a005a3d22f1c", + "content-hash": "10dfa091ae7bf6897a82100048c7d116", "packages": [ - { - "name": "container-interop/container-interop", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", - "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", - "shasum": "" - }, - "type": "library", - "autoload": { - "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "time": "2014-12-30 15:22:37" - }, { "name": "psr/log", "version": "1.0.0", @@ -74,6 +47,33 @@ } ], "packages-dev": [ + { + "name": "container-interop/container-interop", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "time": "2014-12-30 15:22:37" + }, { "name": "doctrine/annotations", "version": "v1.2.6", From a2271a338d4c989bab6e7f5561cb39d7afad4ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Fri, 23 Oct 2015 19:58:26 +0200 Subject: [PATCH 6/7] Added comment for empty catch block. --- src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php index 02b8385..c4fbd67 100644 --- a/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php +++ b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php @@ -41,6 +41,7 @@ public function get($id) $entry = $this->container->get($id); } catch (\Exception $e) { + // exception needs to be catched and thrown after stopping the profiler } $this->profiler->stop($benchmark); From 6c0c2a7ec909df22882aee10b3f6a4fa3932de68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Sat, 24 Oct 2015 21:32:17 +0200 Subject: [PATCH 7/7] Added testcases. --- .../Adapter/Interop/Container/Container.php | 11 ++- .../Interop/Container/ContainerTest.php | 82 +++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 tests/Fabfuel/Prophiler/Adapter/Interop/Container/ContainerTest.php diff --git a/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php index c4fbd67..e29e39c 100644 --- a/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php +++ b/src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php @@ -33,21 +33,24 @@ public function __construct(ContainerInterface $container, ProfilerInterface $pr */ public function get($id) { + $entry = null; + $metadata = [ + 'id' => $id + ]; + try { - $metadata = [ - 'id' => $id - ]; $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; } diff --git a/tests/Fabfuel/Prophiler/Adapter/Interop/Container/ContainerTest.php b/tests/Fabfuel/Prophiler/Adapter/Interop/Container/ContainerTest.php new file mode 100644 index 0000000..d97a448 --- /dev/null +++ b/tests/Fabfuel/Prophiler/Adapter/Interop/Container/ContainerTest.php @@ -0,0 +1,82 @@ + + * @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'); + } +}