1

I am writing a Pin tool and it seems to add a significant time overhead.
My tool must instrument the program in the granularity of an instruction.

To check for the overhead source I wrote a small Pin-tool that just counts the instruction by
instrumentation every instruction (as I must do in my tool).

In addition I wrote a simple program that checks a registry value (The C code is around 20 lines).

(Running on an i7 CPU, Windows 7)
When running the simple program, it takes almost immediately to return.
When running the Pin tool init and the program with no instrumentation at all it takes 2.35+- sec
When running the Pin tool with the simple instruction instrumentation it takes 5-6 sec
Number of instructions: 3,107,098.

I have tried it also on a more complex code, a program that loops over a recursion function.

Without Pin it takes around 1 min.
With Pin (that only counts the instructions) it takes around 7 min.
The number of instructions was: 1,850,919,077

Is this the expected overhead?

4

1 回答 1

2

好吧,如果不知道您正在使用哪种仪器,真的不可能说这些数字是否可以预期。然而,当谈到 PIN 的开销时,有几个因素需要考虑。

如果您的分析代码(传递给 *_InsertCall 的函数指针)包含对其他函数、循环或条件语句的调用,则可能需要上下文切换。这会大大增加工具的执行时间。如果您阅读了 PIN 用户指南,我很确定这已被简要讨论过,在发表的有关 PIN 的文章中也提到了这一点。

另一个可能更容易理解的因素是,假设您正在检测粒度,您添加的分析代码至少会导致执行时间增加等于已编译分析代码中的指令数量的一条指令。如果您的分析代码中有循环,这当然会增加更多。(这有点简化,因为我假设每条指令都需要相同的时间来执行。)

PIN 引起的减速范围可以从 2 倍(这是一个相当理论上的减速)到数万倍。如果您的工具仅导致减速 7 倍,我会说它非常快。

于 2014-09-17T11:53:07.487 回答