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.
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