This is the beginning of the Intel Pin Tool Series. Having read this post, you will be able to set up Intel pin tool and run a basic example to count the number of instructions in your program.
Download the pin tool from Intel (https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-downloads). Select the appropriate operating system and copy the download link. For example,
wget https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz -P /tmp/
Extract the file that you have downloaded.
tar -zxvf pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz
This section is optional. But if you are intending to use the tool on a regular basis, I would strongly suggest that you extract it into /opt directory and that you create a symbolic link so that you could manage versions in the future easily.
sudo cp /tmp/pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz /opt/ cd /opt tar -zxvf pin-3.7-97619-g0d0c92f4f-gcc-linux.tar.gz ln -s /opt/pin-3.7-97619-g0d0c92f4f-gcc-linux /opt/pin-dir
Navigate in to pin-dir and test by running a given example.
Check whether you have a 32 bit architecture or a 64 bit architecture using
lscpu command. Depending on this your compiler arguments will have to be modified. If the architecture is x86_64,
If the architecture is 32 bit,
make all TARGET=ia32
Run the instruction count example, by navigating in to the folder
obj-intel64. To test the tool, you will need a gcc compiled object file. For now assume that the object binary is
cd ManualExamples/obj-intel64 ./pin -t /opt/pin-dir/source/tools/ManualExamples/obj-intel64/inscount0.so -- ~/prog
Pro tip! – Do not forget the
-- in between the above command. This is specified in the pin tool as follows.
./pin -t [full path to tool] – [full path to app]
View the results. The instruction count in your program would be stored in inscount0.out which will be residing in the
In the next blog post in the intel pin series, learn how you could create your own tool to count the number of branches.