Skip to content

Commit

Permalink
Update documentation to reflect previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
njsmith committed Sep 15, 2017
1 parent b36ae51 commit ce8d71f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 68 deletions.
2 changes: 2 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ https://github.com/python-trio/trio/issues/314
- :class:`~trio.hazmat.Error`
- :class:`~trio.hazmat.Value`
- :func:`~trio.hazmat.current_task`
- :func:`~trio.hazmat.current_clock`
- :func:`~trio.hazmat.current_statistics`

deprecate most of the task and nursery APIs

Expand Down
68 changes: 0 additions & 68 deletions docs/source/reference-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ custom :class:`~trio.abc.Clock` class:
.. autoclass:: trio.abc.Clock
:members:

You can also fetch a reference to the current clock, which might be
useful if you're using a custom clock class:

.. autofunction:: current_clock


.. _cancellation:

Expand Down Expand Up @@ -1534,69 +1529,6 @@ messages between the thread and a trio task::
trio.run(main)


.. _instrumentation:

Debugging and instrumentation
-----------------------------

Trio tries hard to provide useful hooks for debugging and
instrumentation. Some are documented above (the nursery introspection
attributes, :meth:`Queue.statistics`, etc.). Here are some more:


Global statistics
~~~~~~~~~~~~~~~~~

.. autofunction:: current_statistics


Instrument API
~~~~~~~~~~~~~~

The instrument API provides a standard way to add custom
instrumentation to the run loop. Want to make a histogram of
scheduling latencies, log a stack trace of any task that blocks the
run loop for >50 ms, or measure what percentage of your process's
running time is spent waiting for I/O? This is the place.

The general idea is that at any given moment, :func:`trio.run`
maintains a set of "instruments", which are objects that implement the
:class:`trio.abc.Instrument` interface. When an interesting event
happens, it loops over these instruments and notifies them by calling
an appropriate method. The tutorial has :ref:`a simple example of
using this for tracing <tutorial-instrument-example>`.

Since this hooks into trio at a rather low level, you do have to be
somewhat careful. The callbacks are run synchronously, and in many
cases if they error out then there isn't any plausible way to
propagate this exception (for instance, we might be deep in the guts
of the exception propagation machinery...). Therefore our `current
strategy <https://github.com/python-trio/trio/issues/47>`__ for
handling exceptions raised by instruments is to (a) dump a stack trace
to stderr and (b) disable the offending instrument.

You can register an initial list of instruments by passing them to
:func:`trio.run`. :func:`add_instrument` and
:func:`remove_instrument` let you add and remove instruments at
runtime. There's also :func:`current_instruments`, which is deprecated
and will be removed soon.

.. autofunction:: add_instrument

.. autofunction:: remove_instrument

.. autofunction:: current_instruments

And here's the instrument API:

.. autoclass:: trio.abc.Instrument
:members:

The tutorial has a :ref:`fully-worked example
<tutorial-instrument-example>` of defining a custom instrument to log
trio's internal scheduling decisions.


Exceptions and warnings
-----------------------

Expand Down
67 changes: 67 additions & 0 deletions docs/source/reference-hazmat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,73 @@ carefully: using this module makes it your responsibility to handle
the nasty cases and expose a friendly Trio-style API to your users.


Debugging and instrumentation
=============================

Trio tries hard to provide useful hooks for debugging and
instrumentation. Some are documented above (the nursery introspection
attributes, :meth:`trio.Queue.statistics`, etc.). Here are some more.


Global statistics
-----------------

.. autofunction:: current_statistics


The current clock
-----------------

.. autofunction:: current_clock


.. _instrumentation:

Instrument API
--------------

The instrument API provides a standard way to add custom
instrumentation to the run loop. Want to make a histogram of
scheduling latencies, log a stack trace of any task that blocks the
run loop for >50 ms, or measure what percentage of your process's
running time is spent waiting for I/O? This is the place.

The general idea is that at any given moment, :func:`trio.run`
maintains a set of "instruments", which are objects that implement the
:class:`trio.abc.Instrument` interface. When an interesting event
happens, it loops over these instruments and notifies them by calling
an appropriate method. The tutorial has :ref:`a simple example of
using this for tracing <tutorial-instrument-example>`.

Since this hooks into trio at a rather low level, you do have to be
somewhat careful. The callbacks are run synchronously, and in many
cases if they error out then there isn't any plausible way to
propagate this exception (for instance, we might be deep in the guts
of the exception propagation machinery...). Therefore our `current
strategy <https://github.com/python-trio/trio/issues/47>`__ for
handling exceptions raised by instruments is to (a) dump a stack trace
to stderr and (b) disable the offending instrument.

You can register an initial list of instruments by passing them to
:func:`trio.run`. :func:`add_instrument` and
:func:`remove_instrument` let you add and remove instruments at
runtime.

.. autofunction:: add_instrument

.. autofunction:: remove_instrument

And here's the interface to implement if you want to build your own
:class:`~trio.abc.Instrument`:

.. autoclass:: trio.abc.Instrument
:members:

The tutorial has a :ref:`fully-worked example
<tutorial-instrument-example>` of defining a custom instrument to log
trio's internal scheduling decisions.


Low-level I/O primitives
========================

Expand Down

0 comments on commit ce8d71f

Please sign in to comment.