diff --git a/Collector/Collector.php b/Collector/Collector.php index 185e47b1..406cb694 100644 --- a/Collector/Collector.php +++ b/Collector/Collector.php @@ -131,9 +131,13 @@ 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)); } /** @@ -141,13 +145,41 @@ public function getClients() * * @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 */ diff --git a/Resources/views/webprofiler.html.twig b/Resources/views/webprofiler.html.twig index 7a16f069..a66f94b0 100644 --- a/Resources/views/webprofiler.html.twig +++ b/Resources/views/webprofiler.html.twig @@ -71,14 +71,14 @@
These messages are sent by client named "{{ client }}".
- {% for stack in collector.clientStacks(client) if not stack.parent %} + {% for stack in collector.clientRootStacks(client) %}