[英]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. 我编写并交叉编译了一个小型的c ++程序,我可以在ARM或PC上运行它。 Since ARM and a PC have different instruction set architectures, I wanna to compare them.
由于ARM和PC具有不同的指令集架构,我想比较它们。 Is that possible for me to get the number of executed instructions in this c++ program for both ISAs?
我可以在这个c ++程序中为两个ISA获取执行指令的数量吗?
What you need is a profiler. 你需要的是一个分析器。 perf would be one easy to use.
perf将是一个易于使用。 It will give you the number of instructions that executed , which is the best metric if you want to compare ISA efficiency.
它将为您提供执行的指令数,如果您想比较ISA效率,这是最佳指标。
Check the tutorial here . 在这里查看教程。
You need to use: perf stat ./your binary
你需要使用:
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.
这种方法在CPU的性能监视单元PMU中使用一个寄存器来计算指令数。
Are you trying to get the number of static instructions or dynamic instructions? 您是否尝试获取静态指令或动态指令的数量? So, for instance, if you have the following loop (pseudocode):
因此,例如,如果您有以下循环(伪代码):
for (i 0 to N):
a[i] = b[i] + c[i]
Static instruction count will be just under 10 instructions, give or take based on your ISA, but the dynamic count would depend on N, on the branch prediction implementation and so on. 静态指令计数将在10个指令之下,根据您的ISA给出或取得,但动态计数将取决于N,在分支预测实现上等等。
So for static count I would recommend using objdump, as per recommendations in the comments. 因此,对于静态计数,我建议使用objdump,根据评论中的建议。 You can find the entry and exit labels of your subroutine and count the number of instructions in between.
您可以找到子例程的入口和出口标签,并计算两者之间的指令数。
For dynamic instruction count, I would recommend one of two things: 对于动态指令计数,我建议使用以下两种方法之一:
Hope this helps :) 希望这可以帮助 :)
objdump -dw mybinary | wc -l
On Linux and friends, this gives a good approximation of the number of instructions in an executable, library or object file. 在Linux和朋友中,这给出了可执行文件,库或目标文件中指令数量的良好近似值。 This is a static count, which is of course completely different than runtime behavior.
这是一个静态计数,当然与运行时行为完全不同。
Linux: valgrind --tool=callgrind ./program 1 > /dev/null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.