Javascript counter function functions in Chrome profile

Can I get information from my Chrome profile (Developer Tools) how many times the function is called?
I found how to do this in code:

console.count("Function called"); 

and some really old (year 2011 and around) themes and feature requests such as this one . But there is no new information if you can write a counter for each function.

Sometimes you realize that some calls are called many times per second and significantly improve performance if called only once (add some delay to execute). A counter is required to track this feature.

+5
source share
1 answer

You will not see the function call counter in the Timeline / CPU profiler, since the standard profiler in Chrome Dev Tools is a sampler profiler.

The sampler takes snapshots of the execution at a given interval. When this is done, JS execution is paused and functions in the current execution stack are written. This is what you see in the fiery timeline chart.

Given the described behavior, it should be clear that the sampling profiler cannot record all function calls (a function can be called and complete between two measurement pauses).

There are other profilers that can record all function calls, the easiest way to use is perhaps the Web Tracing Framework . It works using your code (rewrite it by wrapping every function call with a measurement code). WTF takes a little longer to set up (instrumentation step) and will affect measured times (as it introduces a new code), but at least it can show all function calls.

The bottom line is that there is not a single profiler that would be ideal for all trace jobs. You have to use different ones, depending on what you want to measure. There is a wonderful conversation in which various profilers are examined in detail, it is highly recommended: https://www.youtube.com/watch?v=nxXkquTPng8

+6
source

Source: https://habr.com/ru/post/1257371/


All Articles