From e24afc19adf7d0888941ff25625f68bc971271ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Wed, 4 Jun 2008 21:23:30 +0000
Subject: [PATCH] Add OProfile, a system-wide profiler for Linux.

svn path=/nixpkgs/trunk/; revision=11984
---
 .../tools/profiling/oprofile/default.nix      | 41 +++++++++++++++++++
 .../tools/profiling/oprofile/opcontrol.patch  | 16 ++++++++
 pkgs/top-level/all-packages.nix               |  5 +++
 3 files changed, 62 insertions(+)
 create mode 100644 pkgs/development/tools/profiling/oprofile/default.nix
 create mode 100644 pkgs/development/tools/profiling/oprofile/opcontrol.patch

diff --git a/pkgs/development/tools/profiling/oprofile/default.nix b/pkgs/development/tools/profiling/oprofile/default.nix
new file mode 100644
index 000000000000..ca44470598ff
--- /dev/null
+++ b/pkgs/development/tools/profiling/oprofile/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchurl, binutils, popt
+, makeWrapper, gawk, which, gnugrep }:
+
+stdenv.mkDerivation rec {
+  name = "oprofile-0.9.3";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/oprofile/${name}.tar.gz";
+    sha256 = "1jxj8h11rwaviy5dz2ra7q41qfgdl1psc4470327pk5bblbap1jg";
+  };
+
+  patches = [ ./opcontrol.patch ];
+
+  # FIXME: Add optional Qt support.
+  buildInputs = [ binutils popt makeWrapper gawk which gnugrep ];
+
+  configureFlags = "--with-kernel-support";
+
+  postInstall = ''
+    wrapProgram "$out/bin/opcontrol"					\
+       --prefix PATH : "${gawk}/bin:${which}/bin:${gnugrep}/bin"
+  '';
+
+  meta = {
+    description = "Oprofile, a system-wide profiler for Linux";
+    longDescription = ''
+      OProfile is a system-wide profiler for Linux systems, capable of
+      profiling all running code at low overhead.  It consists of a
+      kernel driver and a daemon for collecting sample data, and
+      several post-profiling tools for turning data into information.
+
+      OProfile leverages the hardware performance counters of the CPU
+      to enable profiling of a wide variety of interesting statistics,
+      which can also be used for basic time-spent profiling. All code
+      is profiled: hardware and software interrupt handlers, kernel
+      modules, the kernel, shared libraries, and applications.
+    '';
+    license = "GPLv2";
+    homepage = http://oprofile.sourceforge.net/;
+  };
+}
\ No newline at end of file
diff --git a/pkgs/development/tools/profiling/oprofile/opcontrol.patch b/pkgs/development/tools/profiling/oprofile/opcontrol.patch
new file mode 100644
index 000000000000..fa072c738ffe
--- /dev/null
+++ b/pkgs/development/tools/profiling/oprofile/opcontrol.patch
@@ -0,0 +1,16 @@
+--- oprofile-0.9.3/utils/opcontrol	2007-07-16 20:22:17.000000000 +0200
++++ oprofile-0.9.3/utils/opcontrol	2008-06-04 23:05:20.000000000 +0200
+@@ -1647,12 +1647,10 @@ check_version()
+ 
+ # determine the location of opcontrol and related programs
+ if test -z "$OPDIR"; then
+-	BINDIR="/usr/bin"
+-	OPCONTROL=`$BINDIR/which $0`
+-	OPDIR=`$BINDIR/dirname $OPCONTROL`
++	OPCONTROL=`which $0`
++	OPDIR=`dirname $OPCONTROL`
+ fi
+ 
+-PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
+ 
+ check_options_early $@
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 3d31a126f259..368cfb9da8c7 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2183,6 +2183,11 @@ let pkgs = rec {
     inherit fetchurl stdenv;
   };
 
+  oprofile = import ../development/tools/profiling/oprofile {
+    inherit fetchurl stdenv binutils popt;
+    inherit makeWrapper gawk which gnugrep;
+  };
+
   patchelf = useFromStdenv "patchelf"
     (import ../development/tools/misc/patchelf {
       inherit fetchurl stdenv;