Skip to content

minor profiler updates #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Collector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,55 @@ public function getFailedStacks()
*/
public function getClients()
{
$stacks = array_filter($this->data['stacks'], function (Stack $stack) {
return $stack->getParent() === null;
});

return array_unique(array_map(function (Stack $stack) {
return $stack->getClient();
}, $this->data['stacks']));
}, $stacks));
}

/**
* @param $client
*
* @return Stack[]
*/
public function getClientStacks($client)
public function getClientRootStacks($client)
{
return array_filter($this->data['stacks'], function (Stack $stack) use ($client) {
return $stack->getClient() == $client;
return $stack->getClient() == $client && $stack->getParent() == null;
});
}

/**
* Count all messages for a client.
*
* @param $client
*
* @return int
*/
public function countClientMessages($client)
{
return array_sum(array_map(function (Stack $stack) {
return $this->countStackMessages($stack);
}, $this->getClientRootStacks($client)));
}

/**
* Recursively count message in stack.
*
* @param Stack $stack
*
* @return int
*/
private function countStackMessages(Stack $stack)
{
return 1 + array_sum(array_map(function (Stack $child) {
return $this->countStackMessages($child);
}, $this->getChildrenStacks($stack)));
}

/**
* @return int
*/
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/webprofiler.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
<div class="sf-tabs">
{% for client in collector.clients %}
<div class="tab">
<h3 class="tab-title">{{ client }} <span class="badge">{{ collector.clientStacks(client)|length }}</span></h3>
<h3 class="tab-title">{{ client }} <span class="badge">{{ collector.countClientMessages(client) }}</span></h3>

<div class="tab-content">
<p class="help">
These messages are sent by client named "{{ client }}".
</p>

{% for stack in collector.clientStacks(client) if not stack.parent %}
{% for stack in collector.clientRootStacks(client) %}
<div class="httplug-stack">
{% include '@Httplug/stack.html.twig' with {
'collector': collector,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Collector/CollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function testAddStack()
$collector->addStack($stack);

$this->assertEquals(['acme'], $collector->getClients());
$this->assertEquals([$stack], $collector->getClientStacks('acme'));
$this->assertEquals([$stack], $collector->getClientRootStacks('acme'));
}
}