EmergeTools / ETTrace

Easily and accurately profile iOS apps

Home Page:https://www.emergetools.com/ettrace

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How is the time taken per frame of the function stack recorded?

denghuihua opened this issue · comments

Hi @denghuihua,

ETTrace saves the stack every 4.5-5ms (here).

Each time we save the stack, we also save the time it was saved using CACurrentMediaTime (here).

Then when creating the flamegraph (here), we use that time to infer the duration of each call.

Thank you for your answer, I understand all the above answers, but after calculating the stack duration, how to determine the time for each layer of the stack to call the function? I see that the flame chart shows the time for each function in the stack, how is this calculated
栈帧

The same logic applies, ETTrace uses multiple recorded stacks to infer the duration of each function call.

Lets say we have these stacks:

Stack s1 Stack s2 Stack s3 Stack s4
main() main() main() main()
func1() func1() func1()
func2()

If each stack was recorded every 5ms we can infer that:

  • main() was executed for 20ms.
  • func1() was executed for 15ms.
  • func2() was executed for 5ms.

In the image you shared, the stacks would have this format:

Stack s1 ... Stack n-1 Stack n Stack n+1
main() ... main() main() main()
UIApplicationMain() ... UIApplicationMain() UIApplicationMain() UIApplicationMain()
... @objc ExploreCardViewController.collectionView(_: didSelectItemAt:) @objc ExploreCardViewController.collectionView(_: didSelectItemAt:)
... ExploreCardViewController.collectionView(_: didSelectItemAt:) ExploreCardViewController.collectionView(_: didSelectItemAt:)
... protocol witness for ExploreCardViewControllerDelegate.exploreCa....: protocol witness for ExploreCardViewControllerDelegate.exploreCa....:
... ExploreViewController.exploreCardViewController(_:didSelectItemAtIndex:) ExploreViewController.exploreCardViewController(_:didSelectItemAtIndex:)

Thank you very much for your answer, very detailed,I have got it