Reputation: 14532
I have an issue with a very slow API call and want to find out, what it caused by, using Xhprof: the default GUI and the callgraph. How should this data be analyzed?
What is the approach to find the places in the code, that should be optimized, and especially the most expensive bottlenecks?
Upvotes: 0
Views: 718
Reputation: 40679
Of all those columns, focus on the one called "IWall%", column 5.
Notice that send
, doRequest
, read
, and fgets
each have 72% inclusive wall-clock time.
What that means is if you took 100 stack samples, each of those routines would find itself on 72 of them, give or take, and I suspect they would appear together. (Your graph should show that too.)
So since the whole thing takes 23 seconds, that means about 17 seconds are spent simply reading. The only way you can reduce that 17 seconds is if you can find that some of the reading is unnecessary. Can you?
What about the remaining 28% (6 seconds)? First, is it worth it? Even if you could reduce that to zero (17 seconds total, which you can't), the speedup factor would 1/(1-0.28) = 1.39, or 39%. If you could reduce it by half (20 seconds total), it would be 1/(1-0.14) = 1.16, or 16%. 20 seconds versus 23, it's up to you to decide if it's worth the trouble.
If you decide it is, I recommend the random pausing method, because it doesn't flood you with noise. It gets right to the heart of the matter, not only telling you which routines, but which lines of code, and why they are being executed. (The why is most important, because you can't replace it if it's absolutely necessary. With profilers, you tend to assume it is necessary, because you have no way to tell otherwise.)
Since you are looking for something taking about 14% of the time, you're going to have to examine 2/0.14 = 14 samples, on average, to see it twice, and that will tell you what it is.
Keep in mind that about 14 * 0.72 = 10 of those samples will land in fgets
(and all its callers), so you can either ignore those or use them to make sure all that I/O is really necessary.
(For example, is it just possible that you're reading things twice, for some obscure reason like it was easier to do that way? I've seen that.)
Upvotes: 1