How to Use Intel’s PIN program: A super simple tutorial

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!

Advertisements

2 thoughts on “How to Use Intel’s PIN program: A super simple tutorial

  1. 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__

What are your thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s