MyNixOS website logo
Description

Read files generated by perf on Linux.

This library is for parsing, representing in Haskell and pretty printing the data file output of the Linux perf command. The perf command provides performance profiling information for applications running under the Linux operating system. This information includes hardware performance counters and kernel tracepoints.

Modern CPUs can provide information about the runtime behaviour of software through so-called hardware performance counters http://en.wikipedia.org/wiki/Hardware_performance_counter. Recent versions of the Linux kernel (since 2.6.31) provide a generic interface to low-level events for running processes. This includes access to hardware counters but also a wide array of software events such as page faults, scheduling activity and system calls. A userspace tool called perf is built on top of the kernel interface, which provides a convenient way to record and view events for running processes.

The perf tool has many sub-commands which do a variety of things, but in general it has two main purposes:

  1. Recording events.

  2. Displaying events.

The perf record command records information about performance events in a file called (by default) perf.data. It is a binary file format which is basically a memory dump of the data structures used to record event information. The file has two main parts:

  1. A header which describes the layout of information in the file (section sizes, etcetera) and common information about events in the second part of the file (an encoding of event types and their names).

  2. The payload of the file which is a sequence of event records.

Each event field has a header which says what general type of event it is plus information about the size of its body.

There are nine types of event:

  1. PERF_RECORD_MMAP: memory map event.

  2. PERF_RECORD_LOST: an unknown event.

  3. PERF_RECORD_COMM: maps a command name string to a process and thread ID.

  4. PERF_RECORD_EXIT: process exit.

  5. PERF_RECORD_THROTTLE:

  6. PERF_RECORD_UNTHROTTLE:

  7. PERF_RECORD_FORK: process creation.

  8. PERF_RECORD_READ:

  9. PERF_RECORD_SAMPLE: a sample of an actual hardware counter or a software event.

The PERF_RECORD_SAMPLE events (samples) are the most interesting ones in terms of program profiling. The other events seem to be mostly useful for keeping track of process technicalities. Samples are timestamped with an unsigned 64 bit word, which records elapsed nanoseconds since some point in time (system running time, based on the kernel scheduler clock). Samples have themselves a type which is defined in the file header and linked to the sample by an integer identifier.

Below is an example program which reads a perf.data file and prints out the number of events that it contains.

module Main where

import Profiling.Linux.Perf (readPerfData)
import Profiling.Linux.Perf.Types (PerfData (..))
import System.Environment (getArgs)

main :: IO ()
main = do
   args <- getArgs
   case args of
      [] -> return ()
      (file:_) -> do
         perfData <- readPerfData file
         print $ length $ perfData_events perfData

linux-perf

linux-perf is a library for parsing, representing in Haskell and pretty-printing the data file output of the Linux 'perf' command (Linux performance counters).

License and Copyright

linux-perf is distributed as open source software under the terms of the BSD License (see the file LICENSE in the top directory).

Authors: Simon Marlow, Bernie Pope, Mikolaj Konarski, Duncan Coutts, copyright 2010, 2011, 2012.

Contact information

Email Bernie Pope:

florbitous_at_gmail_dot_com

Building and installing

linux-perf uses the cabal infrastructure for configuring, building and installation. It needs access to the header files from the Linux kernel source distribution (one that is sufficiently recent to support the performance counters tool).

To build and install:

cabal install --extra-include-dirs=/path/to/linux/headers/

To clean:

cabal clean

To test:

dump-perf test/ParFib.perf.data | less

For longer examples see README.ghc-events-perf.md.

Metadata

Version

0.3

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows