There are multiple ways available.
if you want to profile a function then you can use fprof. The problem I see with Fprof is it’s a huge text file and it’s very difficult to interpret. So Kcachegrind will help you in visualising. Here are the steps how can you use Kcachegrind.
Step1 — Download Kcachegrind
incase of mac-os use qcachegrind. (if you have higher mac-os version qcachegrind doesn’t work, you can use these change and create qcachegrind binary for yourself https://github.com/anuragjain67/kcachegrind/tree/qcachegrind_macos_catlina_support)
Step2 — Download erlgrind script
(This will help you in converting fprof output in .grind output.)
Step3 — Create fprof file
Step4 — Convert .fprof file to .cgrind file:
erlgrind outputfile.frof outputfil.cgrind
Step5 — Open this file in kcachegrind or qcachegrind (mac)