Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabfuel committed Oct 25, 2015
2 parents 67bbcf8 + 798d72e commit bd0746c
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 24 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,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.",
Expand Down
40 changes: 34 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions public/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand All @@ -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));
Expand Down
72 changes: 72 additions & 0 deletions src/Fabfuel/Prophiler/Adapter/Interop/Container/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* @author @shochdoerfer <S.Hochdoerfer@bitExpert.de>
* @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;
}
}
8 changes: 4 additions & 4 deletions src/Fabfuel/Prophiler/View/toolbar.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;
<span class="label color-3"><i class="fa fa-tasks"></i> <?php echo BenchmarkFormatter::formatMemoryUsage(memory_get_peak_usage()) ?></span>
</li>
<li>
<a href="#" onclick="return $('#prophiler-benchmarks').slideToggle('fast');"><span class="label color-5"><i class="fa fa-tachometer"></i> Timeline</span></a>
<a href="javascript:void(0);" onclick="return $('#prophiler-benchmarks').slideToggle('fast');"><span class="label color-5"><i class="fa fa-tachometer"></i> Timeline</span></a>
</li>

<?php foreach ($aggregators as $aggregator): ?>
<li>
<?php if (count($aggregator)): ?>
<a href="#" onclick="return $('#prophiler-aggregator-<?= spl_object_hash($aggregator) ?>').slideToggle('fast');">
<a href="javascript:void(0);" onclick="return $('#prophiler-aggregator-<?= spl_object_hash($aggregator) ?>').slideToggle('fast');">
<?php endif; ?>

<span class="label severity-<?= $aggregator->getSeverity() ?>">
Expand All @@ -44,7 +44,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;

<?php if (count(new \Fabfuel\Prophiler\Iterator\ComponentFilteredIterator($profiler, 'Logger')) >= 1): ?>
<li>
<a href="#" onclick="return $('#prophiler-logs').slideToggle('fast');">
<a href="javascript:void(0);" onclick="return $('#prophiler-logs').slideToggle('fast');">
<span class="label <?= $alertCount ? 'color-0' : 'color-5' ?>">
<i class="fa fa-align-left"></i> Logs
<?php if ($alertCount): ?>
Expand All @@ -57,7 +57,7 @@ use Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatter;

<?php foreach ($dataCollectors as $dataCollector): ?>
<li>
<a href="#" onclick="return $('#prophiler-datacollector-<?= md5($dataCollector->getTitle()) ?>').slideToggle('fast');"><span class="label color-5"><?= $dataCollector->getIcon() ?> <?= $dataCollector->getTitle() ?></span></a>
<a href="javascript:void(0);" onclick="return $('#prophiler-datacollector-<?= md5($dataCollector->getTitle()) ?>').slideToggle('fast');"><span class="label color-5"><?= $dataCollector->getIcon() ?> <?= $dataCollector->getTitle() ?></span></a>
</li>
<?php endforeach; ?>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* @author @shochdoerfer <S.Hochdoerfer@bitExpert.de>
* @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');
}
}

0 comments on commit bd0746c

Please sign in to comment.