1
votes

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?

1

1 Answers

2
votes

Well it is really impossible to say if those numbers are to be expected without knowing what kind of instrumentation you're doing. There are however several factors that much be considered when it comes to the overhead of PIN.

If your analysis code (the function pointer passed to *_InsertCall) contains calls to other functions, loops or conditional statements a context switch might be required. This is something which will increase the execution time of your tool by a lot. If you read the PIN user guide I'm quite sure that this is discussed briefly, it is also mentioned in the articles published about PIN.

Another factor which is perhaps easier to understand, is that the analysis code you're adding will at the very least cause an increase in execution time equal to the number of instructions in the compiled analysis code, assuming that you're instrumenting on the granularity of an instruction. This will of course increase even more if there are loops in your analysis code. (This is a little simplified, since I assume that every instruction take the same time to execute.)

The slowdown caused by PIN can range from a factor of 2 (which is a rather theoretical slowdown), to a factor of tens of thousands. If your tool only causes a slowdown by a factor of 7 I'd say that it is very fast.