How Self & Total time is calculated having Google

2019-05-21 15:25发布

问题:

I'm writing tool to parse and extract some data from cpuprofile file (file produced when I save profile report) and I'm having some troubles with precision of Self & Total times calculations. So, time depends on the value from field hitCount, but. When hitCount is small (<300) the coefficient between hitCount and Self time ~1.033. But as hitCount grows, coefficient also grows. So, when hitCount=3585, k is 1.057. When hitCount=7265: k=1.066.

Currently I'm using 1.035 as coefficient, I tried to minimize error on my sample data. But I'm not happy with approximation. I'm not familiar with Chromium code base to go and figure it out directly in the source code.

So how do I get Self time for function call having hitCount value?

回答1:

Basically it's:

sampleDuration = totalRecordingDuration / totalHitCount
nodeSelfTime = nodeHitCount * sampleDuration

You can find it here: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js&sq=package:chromium&type=cs&l=31