Say I am executing a program in user space and there is a function in that program. Now I want to know the cpu-time spent in execution of that function.
What did I figure out till now ?
On starting of that program I will get the PID of that process, which I will pass to the kernel module and will get the task_struct for that process. After that in thread_info we can get instruction pointer and Stack pointer.
From user space we can give starting and ending offset of that function to the kernel module and then in kernel we can check these two with the help of instruction pointer to get the execution time. So is there anyway to do it or is there another way to achieve the goal.
Please don't specify some pre-exiting tools. I want to do it on my own by writing a kernel module for this.