If you’re reading this, you probably already know what pin is for, but basically it is used to profile programs. You can use it to answer things like how many instructions does this executable have or how many branches occur, etc. It does this in most cases by inserting counters and other code while your executable is running. So let’s get to a quick demo.
I will be demonstrating with Linux, specifically with Ubuntu, because this was a headache on Windows. Note that you might need root permission to execute some of these commands, so if they don’t work, try re-running with sudo.
(1) Download the pin program tarball
Download the tool from here, making sure that you have a compatible version of gcc.
You can check your gcc version like so:
gcc --version
And get output similar to:
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you don’t want to download through the browser, just use wget on the command line making sure to replace the link to the correct version.
wget http://software.intel.com/sites/landingpage/pintool/downloads/pin-2.14-71313-gcc.4.4.7-linux.tar.gz
(2) Untar it
Let me save you a quick Google:
tar -xzf pin-2.14-71313-gcc.4.4.7-linux.tar.gz
(3) Make a pintool
Pin uses these things called pintools to actually profile your program. As an analogy, think of pin as a game engine like Unreal, while the pintools are the games that are made with this engine like Batman: Arkham Knight.
The pintools you receive are actually just source at this point and need to be compiled by you. Thankfully, there’s the make the make tool to do that for you. Make sure you have it installed.
make --version
We will use the insmix tool in this example, which counts the number of x86 instructions that are executed by a program.
cd pin-2.14-71313-gcc.4.4.7-linux/source/tools/Insmix/
make
You should now have a new directory like obj-intel64 in the Insmix directory and it should contain insmix.so.
(4) Execute it!
We will run instrumentation on the ls command. Go back to the root directory of pin where you’ll find a shell script called pin.sh
./pin.sh -t source/tools/Insmix/obj-intel64/insmix.so -- ls
This executes pin, using the pintool insmix on the executable ls. In your current directory you should see an output file called insmix.out. This file has statistics on the kinds of commands that have been executed. Consult the manual for insmix to see what they mean.
If you have any questions or errors running this, please leave a comment!
Thank you bro! It helped me how to get start
The attaching of pintool to apps means that ” any pintool from Manual Example can be attach to .cpp file like Calculator program ” like that ?
Hi Abdul. Sorry, I’m not sure what you are asking. Can you include a link to provide some context?
If you are asking if a pintool can be used with a .cpp file, then no. A .cpp file is just a text file. It can however be used with the executable that is generated when you compile your C++ file.
Hi
I have built a small pintool on memory leak using pin-2.14-71313-msvc12-windows on windows 7 SP1 64 bit machine with visual studio 2013, GCC version 4.8.2
I have generated memory leak.dll
Now I want to check my tool with a sample test program which has memory leak issues.
Once I run my tool with test program I get a msg as shown in the attachment. Please help me in this regard. I have no clue what went wrong.
My dll is generated in release mode with x64.
C:\pin-2.14-71313-msvc12-windows>pin.exe -t Memoryleak.dll — TestApp.exe
A: Source\pin\base\knob.cpp: LEVEL_BASE::KNOB_BASE::CheckAllKnobs: 523: option w
ith missing family>o,Pintool<
NO STACK TRACE AVAILABLE
Pin 2.14
Copyright (c) 2003-2015, Intel Corporation. All rights reserved.
@CHARM-VERSION: $Rev: 71293 $
@CHARM-BUILDER: BUILDER
@CHARM-COMPILER: MS-cl 1800
@CHARM-TARGET: ia32e
@CHARM-CFLAGS: __OPTIMIZE__=__OPTIMIZE__ __NO_INLINE__=__NO_INLINE__
This was a tutorial on setting up Pin in Linux, not Windows. If you’re having Windows issues, I’d suggest asking Stackoverflow or Intel’s software development forums.
https://software.intel.com/en-us/forum