What is the difference between the 'self' and 'total' columns in the Chrome CPU profiling of JS code?
-
15Self time is almost never useful in serious software, because nearly all the time is spent in calling system/library/DB/IO, etc., so the program counter spends very little actual time, as a percentage, in your code, unless you happen to write some kind of tight loop. It might tell you a lot is used in a system routines, but that does you no good. You need to know which part of *your code* causes a lot of time to be spent. – Mike Dunlavey Aug 20 '11 at 01:47
-
If a function is blocking by calling built-in object (like non-async XMLHttpRequest send), self time might be very useful. In such cases these functions, while being the bottlenecks, may not show at the top of total time measurements. – Konstantin Aug 12 '14 at 13:54
2 Answers
self
is how much time was spent doing work directly in that function.
total
is how much time was spent in that function, and in the functions it called.
-
11so self would only be inline statements, and not function calls? And total is all the code executing inside the call? – CoolUserName Aug 19 '11 at 21:39
-
47Incidentally, since people seem to be finding this a useful answer: This is true of profilers in general, not just in Chrome. – Mar 30 '12 at 21:08
-
2What would happen if a function calls itself recursively? how would you correctly read it then ? – David Limkys Feb 21 '17 at 21:29
-
4Documents link is [here (at 'View function details' section)](https://developers.google.com/web/tools/chrome-devtools/rendering-tools/js-execution). **`Self time`** : _How long it took to complete the current invocation of the function, including only the statements in the function itself, not including any functions that it called._ **`Total time`**: _The time it took to complete the current invocation of this function and any functions that it called._ – Iman Mahmoudinasab Apr 12 '17 at 10:32
-
And what's the semantics of the percentage that is now shown along self and total time values? I mean it's a percent of what in what? – jayarjo Jun 22 '18 at 06:21
Self Time: For a function, is the amount of time to execute code within the function (inline statements). Checking the performance of individual functions is known as bottom-up analysis.
Total Time: For a function, is the self time of that function and the self times of all functions that function calls. Checking the performance of functions along with their callees is top-down analysis.
NB: Just because a function has a high self time, doesn't mean that the function itself is inefficient. It is also important to look at how many times that function is being called.
Italics paraphrased from Article by Intel.

- 4,555
- 31
- 31
- 45

- 11,272
- 7
- 78
- 65