Open Jakhotiya opened 6 months ago
Hi Abhishek,
The problem lies in the fact that several calls to addProduct() are merged together in your sampled profile. This is one of the unavoidable inaccuracies caused by sampling mode.
Here is what happens technically:
This one could be fixed but I'm not sure that it's worth it as the other inaccuracies cannot be fixed (e.g. missing function calls with their costs wrongly integrated either in parent or siblings...) and will still make the timeline view more or less accurate depending on sampling period.
In sampling mode you must in fact not trust the function call boundaries (and consequently the function call counts in the flap profile & flame graph), you must just roughly trust the overall time collected for a given function or stack.
By the way 5ms is a very huge sampling period, maybe you use it to have a small report ? If you want to reduce SPX's own overhead in order to improve measured timings accuracy, a sampling period of 20 to 100us is sufficient in most cases.
There is however one thing that could be fixed, the documentation. The effects of sampling mode on the report analysis side are not documented.
Visualization of how many times a child function was called inside parent can be wildly in accurate.
Following profiles were taken for exact same request and payload. Only in the first screenshot sampling is 5ms and in the second screenshot sampling is disabled
In this screenshot UI shown that
Magento\Catalog\Model\Product\Type\AbstractType::prepareForCartAdvanced
was called multiple times byMagento\Quote\Model\Quote::addProduct
. That's not true. From the source code below you can see only one call is made for prepareForCartAdvanced inside addProduct.This confused me because following is the source code
At this point I suspected if sampling was causing this. Then I disabled sampling and visualization is correct. Each
Magento\Quote\Model\Quote::addProduct
callsMagento\Catalog\Model\Product\Type\AbstractType::prepareForCartAdvanced
only once.I've experience this a few times but I do not know how to reproduce it for bare minimum php script.
This seems to happen because sampling will always miss a few function calls. The test case we are talking is "What happens when parent functions are missed but child functions are recorded. "
This may or may not have solution but makes sense to document this behavior.