Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the number of instructions executed by a program?

I have written and cross compiled a small c++ program, and I could run it in an ARM or a PC. Since ARM and a PC have different instruction set architectures, I wanna to compare them. Is that possible for me to get the number of executed instructions in this c++ program for both ISAs?

like image 355
Cong Wang Avatar asked Dec 20 '22 02:12

Cong Wang


1 Answers

What you need is a profiler. perf would be one easy to use. It will give you the number of instructions that executed, which is the best metric if you want to compare ISA efficiency.

Check the tutorial here.

You need to use: perf stat ./your binary

Look for instructions metric. This approach uses a register in your CPU's performance monitoring unit - PMU - that counts the number of instructions.

like image 179
VAndrei Avatar answered Dec 26 '22 10:12

VAndrei