Skip to content

document the stopwatch plugin #88

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 1 commit into from
Feb 19, 2016
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
11 changes: 6 additions & 5 deletions plugins/history.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
History Plugin
==============

The ``HistoryPlugin`` notifies a Http\Client\Plugin\Journal of all successful and failed calls::
The ``HistoryPlugin`` notifies a ``Http\Client\Plugin\Journal`` of all
successful and failed calls::

use Http\Discovery\HttpClientDiscovery;
use Http\Client\Plugin\PluginClient;
Expand All @@ -15,8 +16,8 @@ The ``HistoryPlugin`` notifies a Http\Client\Plugin\Journal of all successful an
);


As an example, HttplugBundle uses this plugin to collect responses or exceptions associated with
requests for the debug toolbar
As an example, HttplugBundle uses this plugin to collect responses and exceptions associated with
requests for the debug toolbar.

This plugin only collect data after resolution. For logging purposes it's best to use the `LoggerPlugin` which logs
as soon as possible.
This plugin only collects data after resolution. For logging purposes, it is recommended to use
the :doc:`LoggerPlugin <logger>` instead, which logs events as they occur.
32 changes: 31 additions & 1 deletion plugins/stopwatch.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
Stopwatch Plugin
================

TODO: explain the stopwatch plugin
The ``StopwatchPlugin`` records the duration of HTTP requests with a
``Symfony\Component\Stopwatch\Stopwatch`` instance::

use Http\Discovery\HttpClientDiscovery;
use Http\Client\Plugin\PluginClient;
use Http\Client\Plugin\StopwatchPlugin;
use Symfony\Component\Stopwatch\Stopwatch;

$stopwatch = new Stopwatch();

$stopwatchPlugin = new StopwatchPlugin($stopwatch);

$pluginClient = new PluginClient(
HttpClientDiscovery::find(),
[$stopwatchPlugin]
);

// ...

foreach ($stopwatch->getSections() as $section) {
foreach ($section->getEvents() as $name => $event) {
echo sprintf('Request %s took %s ms and used %s bytes of memory', $name, $event->getDuration(), $event->getMemory());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if this should be here, but Stopwatch plugin can be inconsistent when using async (not the real time, neither memory as it can change if user is doint another async operation). Maybe adding a warning about that (not sure also, don't want to complicate too much the documentation)

Copy link
Contributor Author

@dbu dbu Feb 18, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


.. warning::

The results of the stop watch will be unreliable when using an asynchronous client. Execution
time can be longer than it really was, depending on when the status was checked again, and
memory consumption will be mixed up with other code that was executed while waiting for the
response.