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

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.


(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/

You should now have a new directory like obj-intel64 in the Insmix directory and it should contain

(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

./ -t source/tools/Insmix/obj-intel64/ -- 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!

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

    • 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.

  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<

    Pin 2.14
    Copyright (c) 2003-2015, Intel Corporation. All rights reserved.
    @CHARM-VERSION: $Rev: 71293 $
    @CHARM-COMPILER: MS-cl 1800
    @CHARM-TARGET: ia32e

What are your thoughts?

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

You are commenting using your 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