0

There are a lot of profiling tools out there that track async functions and the time between they are called and calling back.

How do I actually profile the time every sync function call withing a function takes?

If one function is slow, I would like to see how much time is spent on every sync function in there.

I can use performance.now to add the time of every function manually, and if a function is called 100 times, add those 100 fractions to a single counter to see the total time spend there. I would end up with something like this:

Iterating people:
getPeople.getLocations = 1909.3
getPeople.getLocations.each = 1784.8
getPeople.getLocations.each.missing = 90.5
getPeople.getLocations.each.getSiblings = 777.6
getPeople.getLocations.each.getSiblings.init = 128.3
getPeople.getLocations.each.getSiblings.init.getData = 86.1
getPeople.getLocations.each.getSiblings.each = 613.6
getPeople.getLocations.each.getSiblings.each.getData = 102.6
getPeople.getLocations.each.getSiblings.each.getProperties = 169.1
getPeople.getLocations.each.merge = 899.3

This is very valuable information. However, obviously it's very tedious to set up all the watches.

I'm looking for an easier way to get this kind of information for a specific function. Surely there must be more automated solutions out there. Like the php profiling functions from zend or xdebug.

Redsandro
  • 11,060
  • 13
  • 76
  • 106
  • I waited to see if anyone else would respond, and they haven't. Can I assume you are asking because you want to see where you can make it take less time? There's a way to do it that does not use measuring. Rather, you randomly trap it several times, and anything wasting enough time to be worth looking at, if you see it two or more times, is pinpointed. [*People who know this often don't say so, because it seems too obvious, while people who don't know it flounder around with measurements.*](http://stackoverflow.com/a/317160/23771) – Mike Dunlavey Oct 21 '15 at 17:16
  • Yes, but more precise than a couple of breaks. Breaking and noting down even 50 times is not nearly as accurate and complete as for example a php profiler, or my own method I described above, for that matter. I a̶m̶ ̶s̶u̶r̶e̶ really thought something like this was so convenient that multiple parties would have made specialistic tools for this. – Redsandro Oct 21 '15 at 21:07

0 Answers0