-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Add a profiler #51204
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
[Workflow] Add a profiler #51204
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow_debug.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Symfony\Component\Workflow\DataCollector\WorkflowDataCollector; | ||
|
||
return static function (ContainerConfigurator $container) { | ||
$container->services() | ||
->set('data_collector.workflow', WorkflowDataCollector::class) | ||
->tag('data_collector', [ | ||
'template' => '@WebProfiler/Collector/workflow.html.twig', | ||
'id' => 'workflow', | ||
]) | ||
->args([ | ||
tagged_iterator('workflow', 'name'), | ||
]) | ||
; | ||
}; |
62 changes: 62 additions & 0 deletions
62
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/workflow.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% block menu %} | ||
<span class="label {{ collector.workflows|length == 0 ? 'disabled' }}"> | ||
<span class="icon"> | ||
{{ source('@WebProfiler/Icon/workflow.svg') }} | ||
</span> | ||
<strong>Workflow</strong> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block panel %} | ||
<h2>Workflow</h2> | ||
|
||
{% if collector.workflows|length == 0 %} | ||
<div class="empty empty-panel"> | ||
<p>There are no workflows configured.</p> | ||
</div> | ||
{% else %} | ||
<script type="module"> | ||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs'; | ||
mermaid.initialize({ | ||
flowchart: { useMaxWidth: false }, | ||
securityLevel: 'loose', | ||
}); | ||
// We do not load all mermaid diagrams at once, but only when the tab is opened | ||
// This is because mermaid diagrams are in a tab, and cannot be renderer with a | ||
// "good size" if they are not visible | ||
document.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('.tab').forEach((el) => { | ||
const observer = new MutationObserver(() => { | ||
if (!el.classList.contains('block')) { | ||
return; | ||
} | ||
const mEl = el.querySelector('.sf-mermaid'); | ||
if (mEl.dataset.processed) { | ||
return; | ||
} | ||
mermaid.run({ | ||
nodes: [mEl], | ||
}); | ||
}); | ||
observer.observe(el, { attributeFilter: ['class'] }); | ||
}); | ||
}); | ||
</script> | ||
|
||
<h2>Definitions</h2> | ||
<div class="sf-tabs js-tabs"> | ||
{% for name, data in collector.workflows %} | ||
<div class="tab"> | ||
<h3 class="tab-title">{{ name }}</h3> | ||
<div class="tab-content"> | ||
<pre class="sf-mermaid"> | ||
{{ data.dump|raw }} | ||
</pre> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
{% endblock %} |
1 change: 1 addition & 0 deletions
1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Icon/workflow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Symfony/Component/Workflow/DataCollector/WorkflowDataCollector.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\DataCollector; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; | ||
use Symfony\Component\Workflow\Dumper\MermaidDumper; | ||
use Symfony\Component\Workflow\StateMachine; | ||
|
||
/** | ||
* @author Grégoire Pineau <[email protected]> | ||
*/ | ||
final class WorkflowDataCollector extends DataCollector implements LateDataCollectorInterface | ||
{ | ||
public function __construct( | ||
private readonly iterable $workflows, | ||
) { | ||
} | ||
|
||
public function collect(Request $request, Response $response, \Throwable $exception = null): void | ||
{ | ||
} | ||
|
||
public function lateCollect(): void | ||
{ | ||
foreach ($this->workflows as $workflow) { | ||
$type = $workflow instanceof StateMachine ? MermaidDumper::TRANSITION_TYPE_STATEMACHINE : MermaidDumper::TRANSITION_TYPE_WORKFLOW; | ||
$dumper = new MermaidDumper($type); | ||
$this->data['workflows'][$workflow->getName()] = [ | ||
'dump' => $dumper->dump($workflow->getDefinition()), | ||
]; | ||
} | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'workflow'; | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->data = []; | ||
} | ||
|
||
public function getWorkflows(): array | ||
{ | ||
return $this->data['workflows'] ?? []; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.