Skip to content

Commit

Permalink
improve display of jms panel
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Aug 7, 2021
1 parent ececfb4 commit a78670e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Debug/RunsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @internal
*/
class RunsListener
final class RunsListener
{
private $runs = [];

Expand Down
2 changes: 1 addition & 1 deletion Debug/TraceableDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @internal
*/
class TraceableDriver implements CacheInterface
final class TraceableDriver implements CacheInterface
{
/**
* @var CacheInterface
Expand Down
2 changes: 1 addition & 1 deletion Debug/TraceableFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @internal
*/
class TraceableFileLocator extends FileLocator
final class TraceableFileLocator extends FileLocator
{
private $files = [];

Expand Down
19 changes: 12 additions & 7 deletions Debug/TraceableHandlerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function registerHandler(int $direction, string $typeName, string $format
$this->registry->registerHandler($direction, $typeName, $format, $handler);
$name = $this->findNameForHandler($handler);
$this->registeredHandlers[$direction][$typeName][$name] = $name;
print_r($this->registeredHandlers);
exit;
$a = &$this->registeredHandlers[$direction];
ksort($a);
}

public function getHandler(int $direction, string $typeName, string $format)
Expand Down Expand Up @@ -95,15 +95,20 @@ public function getTriggeredHandlers(): array
public function getNotTriggeredHandlers(): array
{
$registered = $this->registeredHandlers;
foreach ($this->storage as $handlersByType) {
foreach ($handlersByType as $calls) {

foreach ($this->storage as $direction => $handlersByType) {
foreach ($handlersByType as $type => $calls) {
foreach ($calls as $call) {
$handlerName = $this->findNameForHandler($call['handler']);
unset($registered[$handlerName]);
unset($registered[$direction][$type][$handlerName]);
}

if (!count($registered[$direction][$type])) {
unset($registered[$direction][$type]);
}
}
}
return array_values($registered);

return $registered;
}
}
2 changes: 1 addition & 1 deletion Resources/config/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</service>

<service id="jms_serializer.traceable_event_dispatcher" class="JMS\SerializerBundle\Debug\TraceableEventDispatcher" public="false">
<argument type="service" id="service_container" />
<argument type="service" id="jms_serializer.event_dispatcher.service_locator" />
</service>

<service id="jms_serializer.traceable_runs_listener" class="JMS\SerializerBundle\Debug\RunsListener" public="false">
Expand Down
52 changes: 42 additions & 10 deletions Resources/views/Collector/handlers.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
<p>No triggered handlers.</p>
</div>
{%- else -%}
{{- helper.render_table_triggered_handlers(collector.triggeredHandlers, true) -}}
{{- helper.render_table_triggered_handlers(collector.triggeredHandlers) -}}
{%- endif -%}
</div>
</div>

<div class="tab">
<div class="tab-title">Not Triggered Handlers <span class="badge">{{ collector.getNumHandlers('not_called') }}</span></div>
<div class="tab-content">
{{ helper.render_table_triggered_handlers(collector.notTriggeredHandlers, false) }}
{{ helper.render_not_table_triggered_handlers(collector.notTriggeredHandlers) }}
</div>
</div>
</div>

{%- macro render_table_triggered_handlers(handlers, called) -%}
{%- macro render_not_table_triggered_handlers(handlers) -%}
{%- for direction, callsByType in handlers -%}
<h3>
{%- if direction == constant('JMS\\Serializer\\GraphNavigatorInterface::DIRECTION_SERIALIZATION') -%}
Expand All @@ -45,17 +45,49 @@
{%- endif -%}
</tr>
</thead>
{%- for type, calls in callsByType -%}
{%- for call in calls -%}
{%- for type, handlers in callsByType -%}
<tr>
<td>{{ type }}</td>
<td>{{ call.handler }}</td>
{%- if called|default(false) -%}
<td class="text-right">{{ call.calls }}</td>
<td class="text-right">{{ call.duration ? (call.duration * 1000)|number_format(4) : '' }}</td>
{%- endif -%}
<td>
{%- for handler in handlers -%}
{{ dump(handler) }}<br>
{%- endfor -%}
</td>
</tr>
{%- endfor -%}

</table>
{%- endfor -%}
{%- endmacro -%}

{%- macro render_table_triggered_handlers(handlers) -%}
{%- for direction, callsByType in handlers -%}
<h3>
{%- if direction == constant('JMS\\Serializer\\GraphNavigatorInterface::DIRECTION_SERIALIZATION') -%}
Serialization
{%- else -%}
Deserialization
{%- endif -%}
</h3>
<table>
<thead>
<tr>
<th>Date type</th>
<th>Handler</th>
<th>Calls</th>
<th>Total duration (ms)</th>
</tr>
</thead>
{%- for type, calls in callsByType -%}
{%- for call in calls -%}
<tr>
<td>{{ type }}</td>
<td>{{ dump(call.handler) }}</td>

<td class="text-right">{{ call.calls }}</td>
<td class="text-right">{{ call.duration ? (call.duration * 1000)|number_format(4) : '' }}</td>
</tr>
{%- endfor -%}
{%- endfor -%}

</table>
Expand Down
16 changes: 12 additions & 4 deletions Resources/views/Collector/panel.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,24 @@
<div class="metric-divider"></div>
<div class="metric">
<span class="value">{{- collector.triggeredEvents.count }}</span>
<span class="label">Triggered events</span>
<span class="label">Triggered event listeners</span>
</div>
<div class="metric">
<span class="value">{{- collector.triggeredEvents.duration|round(2) }} <span class="unit">ms</span></span>
<span class="label">Triggered events (time)</span>
<span class="label">Triggered event listeners (time)</span>
</div>
</div>

<div class="sf-tabs">
<div class="tab">
<h3 class="tab-title jms-toggle" data-toggle="#jms-events">
Events
<span class="badge">{{ collector.triggeredListeners|length }}</span>
<span class="badge">
{{ collector.triggeredListeners|length }}
({{ collector.getNumListeners('called') }} listeners)
</span>


</h3>

<div class="tab-content">
Expand All @@ -115,7 +120,10 @@
<div class="tab">
<h3 class="tab-title jms-toggle" data-toggle="#jms-handlers">
Handlers
<span class="badge">{{ collector.triggeredHandlers|length }}</span>
<span class="badge">
{{ collector.triggeredHandlers|length }}
({{ collector.getNumHandlers('called') }} types)
</span>
</h3>

<div class="tab-content">
Expand Down

0 comments on commit a78670e

Please sign in to comment.