.. _profiler:

Profiler
===============

Profiler allows you to measure the performance and execution cost of ``SQL`` and ``PSQL`` code.

.. figure:: img/profiler.png

    Profiler

1. Select the connection of interest from the drop-down list.
2. Click the ``Select`` button and in the window that opens, select the user connection to be profiled:

    .. figure:: img/profiler_user.png
        :width: 70%

        Selecting a user connection to profile

You can also open a saved profiler session by clicking the ``Load`` button:

.. figure:: img/profiler_add.png
    :width: 70%

    Saved Sessions

Formats for displaying the result: 

* ``Compact view`` - Displays an overall view of query execution. Repeating processes within a common parent will be merged into one. This is the default value.
* ``Display access data`` - Displays/hides the plan for executing the request. Enabled by default.
* ``Round values`` - If the total or average time is greater than 1000000ns, it will be converted to a larger unit until the value is less than 1000000ns. Enabled by default.

``Cancel All Sessions`` button cancels all profiling sessions for the selected connection (with the specified ``ATTACHMENT_ID``).

In ``compact view``, for each non-last node (except for ``ROOT NODE`` - the root node) there is a node ``Total time``, 
which shows the time spent without taking into account child processes.

In result table displays information collected by the profiler, viz:

* Process name or SQL code;
* Time per process in nanoseconds (including child processes) and the percentage of time from the parent process;
* Average time per process in nanoseconds (including child processes) for repetitive processes combined into one node;
* Number of calls of the recurring processes.

При двойном клике по узлу откроется окно просмотра данных:

.. figure:: img/profiler_data.png
    :width: 70%

    Data view

A Profiler session can be run for a single query from the Query Editor by clicking the ``Run in Profiler`` button. 
In this case the following will be executed:

1. Starts profiler session.
2. Query in the editor will be executed.
3. Profiler session will finish.
4. Displays profiler panel with the collected information.

