how can i generate a record of all instructions executed by a given pr

I have written a small program to tracing a child process instruction by instruction and recording them all. what my aim is to count all the instruction executed inside the child process and maintain their cycle time needd to execute.

My program is as follows: But it not working properly. i am using Linux operating system. please help.