8000 Merged some profiler docs into a single main Profiler article by javiereguiluz · Pull Request #10970 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Merged some profiler docs into a single main Profiler article #10970

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added a Stopwatch section in the new Profiler article
  • Loading branch information
javiereguiluz committed Feb 7, 2019
commit aba88fa5ee096194ffba18ec7b5d737767fbc631
5 changes: 2 additions & 3 deletions components/stopwatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ Symfony Profiler tool uses categories to nicely color-code different events.

.. tip::

When you want to show events in the Symfony profiler, autowire
``Symfony\Component\Stopwatch\Stopwatch`` into your service. Each category
is shown on a separate line.
Read :ref:`this article <profiler-timing-execution>` to learn more about
integrating the Stopwatch component into the Symfony profiler.

Periods
-------
Expand Down
31 changes: 31 additions & 0 deletions profiler 8000 .rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ You can also :doc:`create your own data collector </profiler/data_collector>` to
store any data generated by your app and display it in the debug toolbar and the
profiler web interface.

.. _profiler-timing-execution:

Timing the Execution of the Application
---------------------------------------

If you want to measure the time some tasks take in your application, there's no
need to create a custom data collector. Instead, use the `Stopwatch component`_
which provides utilities to profile code and displayes the results on the
"Performance" panel of the Profiler web interface.

When using :ref:`autowiring <services-autowire>`, type-hint any argument with
the :class:`Symfony\\Component\\Stopwatch\\Stopwatch` class and Symfony will
inject the Stopwatch service. Then, use the ``start()``, ``lapse()`` and
``stop()`` methods to measure time::

// a user signs up and the timer starts...
$stopwatch->start('user-sign-up');

// ...do things to sign up the user...
$stopwatch->lapse('user-sign-up');

// ...the sign up process is finished
$stopwatch->stop('user-sign-up');

.. tip::

Consider using a professional profiler such as `Blackfire`_ to measure and
analyze the execution of your application in detail.

Enabling the Profiler Conditionally
-----------------------------------

Expand Down Expand Up @@ -188,3 +217,5 @@ event::
profiler/data_collector

.. _`Single-page applications`: https://en.wikipedia.org/wiki/Single-page_application
.. _`Stopwatch component`: https://symfony.com/components/Stopwatch
.. _`Blackfire`: https://blackfire.io/
0