We will not describe optimisation methods for Magento 2 based on profiling, because this is an entirely different topic; we will only consider the possibilities of Tideways in terms of profiling. Also, we will omit the description of all settings and will focus only on the core profile capabilities.
Assume we had a Magento 2 project which needs to be profiled. For example, let’s trigger profiling for the home page. Add a query string provided by Tideways into the store home URL and refresh the page. In Tideways we will now see the available Callgraph Traces:
Timeline
The Timeline profiler collects information about a range of operations performed by the Magento 2 application. In this particular case, we can notice that the request of our page returned an HTTP 200 OK response code, see that the request has been handled via Magento\Cms\Controller\Index\Index controller, Magento 2 generates 167 MySQL queries, the response of the page took 941 ms, consumed 50.2 MB of memory, etc. It’s the primary information you can see at the top of the page.
Also, for example, we can choose the SQL query, which collects EAV (Entity–attribute–value) attribute options data from the block Magento\Swatches\Block\Product\Renderer\Listing\Configurable.In the right sidebar, we will see all the necessary information about this query: execution time, memory usage, etc.
Another example shows the query which collects some products information to display on the page:
Summary
The Summary tab shows an extensive report about how all of the functions work.
The SQL functions are clickable to display the query information itself. For example, we can see that query below executes two times with self duration 22.5ms and with a total duration of 22.5ms:
Another example shows that the Magento 2 event core_layout_render_elemenеt was triggered 109 times with 22.3ms and 4.55ms respectively:
Callgraph
The Callgraph Profiler shows how much time was spent in each function on a call graph. It provides detailed insights into every function call of a PHP request. Let’s trigger one of the pages of the category and look at the results.
Resource-intensive areas of the code are highlighted in yellow (middle) and red (strongest). These are pieces of code that use a lot of resources relative to the rest of the program. It can be a slow function or a large number of fast function calls.
For example, we can see that for the call to function Magento\Catalog\Model\Layer\Filter\AbstractFilter::getItemsCount:
- the total time was 3.47 seconds (53% of the total request)
- the self-time was 0.03 milliseconds (0.00% of the total request)
- the total memory used was 5.1 MB (0.00% of the total request)
- the self memory used was 0 B (0.00% of the total request)
- the function was, itself, called 32 times
Also, we can see the parent calls, child calls, and slowest code path. The example above shows that the selected function has:
- 4 parent functions, including Magento\Catalog\Model\Layer\Category\AvailabilityFlag::canShowOptions and Magento\Framework\View\TemplateEngine\Php::render
- 2 child functions Magento\Catalog\Model\Layer\Filter\AbstractFilter::getItems and count;
- 16 slow code paths, including Magento\Catalog\Model\Layer\Category\AvailabilityFlag::canShowOptions and Magento\Catalog\Model\Layer\Category\AvailabilityFlag::isAvailable
Each time a different function is selected, we can see how each view component is interlinked and changes.
Bottlenecks
Tideways automatically detects some bottlenecks in our requests and gives us helpful clarifications about them. The Bottlenecks tab may display slow or repeated HTTP calls, SQL calls, etc. In the example, we can see that the select, related to retrieving product information, was executed 1 time and took 8.02 ms. All the detected bottlenecks will be highlighted in red: