by Lucas De Marchi
RSS icon Home icon
  • Stripping perf out from kernel source

    You may have heard about perf, a tool made by Linux kernel developers to help debugging, benchmarking and profiling.

    The problem is you have to download the whole kernel source in order to compile perf. If you are not used to follow kernel developping, most likely you will not have its source. But it’s still possible to compile perf.

    As I’m helping to maintain perf package in Archlinux, I made the following script to strip perf from a given kernel version:

    #!/bin/bash
     
    function usage() {
    	cat - <<EOF
    USAGE:
    	make-perf-util.sh git-tag-version
     
    EOF
    }
     
    function die() {
    	echo -e "ERROR\n\tSee usage\n"
    	usage
    	exit 1
    }
     
    VERSION=$1
    BASENAME=perf-util
    NAME=$BASENAME-$VERSION
    PKGNAME=$NAME.tar.bz2
     
    if [ $# -ne 1 ]; then
    	die
    fi
     
    git checkout $VERSION || die
    [ -a $NAME ] && rm -rf $NAME
     
    cd tools/perf && make clean
    cd -
     
    rsync -Ra tools lib include/linux arch/x86/include/asm include/asm-generic \
              --link-dest=. $NAME
    tar -cjf $PKGNAME $NAME
    rm -rf $NAME
     
    echo "created $PKGNAME"

    This script works fine with latest 2.6.33 kernel. Regularly I’m uploading to this site the stripped version of perf. The latest one, you find here.

     

    2 responses to “Stripping perf out from kernel source” RSS icon

    • Is this something like OpenSolaris/FreeBSD DTrace? Does it need a lot of dependencies, doesn’t it? Is this suitable for embedded apps?

      How different is perf from Valgrind?

      • Lucas De Marchi

        Yes, it’s related to opensolaris/freebsd DTrace. There are a few dependencies, namely: elfutils, zlib, perl (perl dependency was introduced with latest version). To compile it you also need asciidoc and xmlto for documentation and libdwarf.

        Valgrind is used mostly to find bugs in memory accesses like using an uninitialized var, freed memory, wrong pointer dereference etc. It does can be used to profile cache references, but it uses a simulation model to give you the miss/hit-rate. Perf, instead, relies on hardware counters and thus you can profile your application with the architecture it is running on.

        It was first born as an access to hardware counters, but now it’s becoming the de facto performance debugging utility for linux kernel.