Skip to content

Commit

Permalink
dtrace: add sample scripts for building dev DTrace on Ubuntu
Browse files Browse the repository at this point in the history
Signed-off-by: David Mc Lean <david.mclean@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
dpmclean committed Dec 19, 2020
1 parent 187c56a commit 0f94bd8
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 0 deletions.
23 changes: 23 additions & 0 deletions dists/Ubuntu/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

The scripts here are to ease building DTrace on an Ubuntu installation.

To work properly, the top level scripts "prepare_kernel.sh" and
"build_dtrace.sh" must be run from the directory where this README file is
located. Do not run these scripts from another directory.

These scripts also assume the Ubuntu installation is on an x86_64/amd64 system.

First, run ./prepare_kernel.sh to build a kernel with a few extra tracing
features that DTrace uses. While prepare_kernel.sh is running, the (git)
cloned source code and activity log files will be created in the ./kernel/
subdirectory.

Afterward (once the kernel with additinal tracing features is running) DTrace
can be built. The script build_dtrace.sh builds this userspace application.
67 changes: 67 additions & 0 deletions dists/Ubuntu/build_dtrace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

set -e

echo "This script ($0) is meant to be run on an Ubuntu"
echo "installation, to facilitate building DTrace on Ubuntu."
echo "If this system is not already running on a kernel with added tracing"
echo "features, first build and boot into a kernel with the required features"
echo "-- for example by running prepare_kernel.sh."
echo
echo "Input the letter 'c' to continue with the build of DTrace,"
echo "otherwise this script will exit when the 'Enter' key is pressed."
echo "Press 'c', then press 'Enter' to \"continue\" with the build:"
read CONTINUE

if [ "$CONTINUE" != "c" ]
then
echo "Exiting now per user input."
exit 0
else
echo "User indicated continuation of $0; beginning operations ..."
fi

# Packages needed for DTrace utils
echo "## installing libpcap-dev" | tee -a _makeDevDTUtilsOut.txt
sudo apt-get -y install libpcap-dev >> _makeDevDTUtilsOut.txt
echo "## installing gcc-multilib -- see asm/types.h, etc." \
| tee -a _makeDevDTUtilsOut.txt
sudo apt-get -y install gcc-multilib >> _makeDevDTUtilsOut.txt

echo "## changing directory to dtrace-utils"
cd ../../../dtrace-utils

echo "## making dtrace-utils"
# Build dtrace-utils -- build of utils is fairly quick
make SHELL=/bin/bash LIBDIR='/usr/local/lib' \
> dists/Ubuntu/_makeDevDTUtilsOut.txt 2>&1

echo "To briefly explore the operation of DTrace, you may choose not to"
echo "install DTrace -- you can use $PWD/build/run-dtrace"
echo "as an equivalent, instead of 'dtrace'."
echo ""
echo "Quit this script to avoid installing DTrace."
echo ""
echo "To install so that DTrace can be used more easily, with the command"
echo "'dtrace', input the word 'install' to have this script install DTrace;"
echo "otherwise this script will exit when the 'Enter' key is pressed."
echo ""
echo "Input 'install', then press 'Enter' to \"install\" DTrace:"
read INSTALL

if [ "$INSTALL" != "install" ]
then
echo "Exiting now per user input."
exit 0
else
echo "User indicated install of DTrace; beginning install ..."
fi

sudo make LIBDIR='/usr/local/lib' install
sudo /sbin/ldconfig # access libdtrace.so.2
20 changes: 20 additions & 0 deletions dists/Ubuntu/kernel/steps/0_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

set -e
cd kernel
echo $0 > _00_steprunning.txt

# Get current.
date | tee -a _000_stepsOut.txt
echo "## Beginning system update:" | tee -a _000_stepsOut.txt
sudo apt-get -y update >> _000_stepsOut.txt
date | tee -a _000_stepsOut.txt
echo "## Beginning upgrade:" | tee -a _000_stepsOut.txt
sudo apt-get -y upgrade >> _000_stepsOut.txt
date | tee -a _000_stepsOut.txt
134 changes: 134 additions & 0 deletions dists/Ubuntu/kernel/steps/1_deps_clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

# Install dependency packages and git-clone source. Try to use cloning time
# efficiently by running package installs, checkout and build libdtrace-ctf.

set -e
cd kernel
echo $0 > _00_steprunning.txt

echo "## installing build-essential" | tee -a _000_stepsOut.txt
sudo apt-get -y install build-essential >> _1_installs.txt

echo "## Beginning git clone of Linux kernel ... " | tee -a _000_stepsOut.txt
STABLE="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
git clone $STABLE DTrace-Ubuntu-kernel > _1clnDTraceKernOut.txt 2>&1 &
CLNKRN=$!

echo "## Beginning git clone of binutils ... " | tee -a _000_stepsOut.txt
git clone https://sourceware.org/git/binutils-gdb.git srcbinut > \
_1clnBinOut.txt 2>&1 &
CLNBIN=$!

echo "## Beginning git clone of gcc ... " | tee -a _000_stepsOut.txt
git clone https://gcc.gnu.org/git/gcc.git srcgcc > _1clnGccOut.txt 2>&1 &
CLNGCC=$!

echo "## Beginning git clone of libdtrace-ctf ... " | tee -a _000_stepsOut.txt
git clone https://github.com/oracle/libdtrace-ctf.git > \
_1clnLibDTraceCTFOut.txt 2>&1 &
CLNLCT=$!


# Needed for binutils build
echo "## installing texinfo" | tee -a _000_stepsOut.txt
sudo apt-get -y install texinfo >> _1_installs.txt
echo "## installing bison" | tee -a _000_stepsOut.txt
sudo apt-get -y install bison >> _1_installs.txt
echo "## installing flex" | tee -a _000_stepsOut.txt
sudo apt-get -y install flex >> _1_installs.txt

# Needed for gcc build
echo "## installing libgmp-dev" | tee -a _000_stepsOut.txt
sudo apt-get -y install libgmp-dev >> _1_installs.txt
echo "## installing libmpc-dev" | tee -a _000_stepsOut.txt
sudo apt-get -y install libmpc-dev >> _1_installs.txt

# Needed for libdtrace-ctf build
echo "## installing glib2.0" | tee -a _000_stepsOut.txt
sudo apt-get -y install glib2.0 >> _1_installs.txt

# For kernel build
echo "## installing kernel-package" | tee -a _000_stepsOut.txt # ELF
sudo apt-get -y install kernel-package >> _1_installs.txt
echo "## installing libdw-dev" | tee -a _000_stepsOut.txt # dwarf
sudo apt-get -y install libdw-dev >> _1_installs.txt
echo "## installing libssl-dev" | tee -a _000_stepsOut.txt # openssl
sudo apt-get -y install libssl-dev >> _1_installs.txt

echo "## installing gawk" | tee -a _000_stepsOut.txt
sudo apt-get -y install gawk >> _1_installs.txt

echo "## installing binutils-dev -- see sys/ctf_api.h, etc." \
| tee -a _000_stepsOut.txt
sudo apt-get -y install binutils-dev >> _1_installs.txt

wait $CLNLCT
echo "## Completed clone of libdtrace-ctf; build ..." | tee -a _000_stepsOut.txt
cd libdtrace-ctf
# Pass in the install location because Ubuntu doesn't use default /usr/lib64
make prefix=/usr/local LIBDIR='$(prefix)/lib'
sudo make prefix=/usr/local LIBDIR='$(prefix)/lib' install
sudo /sbin/ldconfig
cd ..

# Confirm git has configuration so that merge operation will work:
GITSTATUS="bad"
while [ $GITSTATUS != "good" ]; do
GITSTATUS="good"
if ! git config user.email > /dev/null; then
echo
echo error: git user.email is not set
GITSTATUS="bad"
fi
if ! git config user.name > /dev/null; then
echo
echo error: git user.name is not set
GITSTATUS="bad"
fi
if [ $GITSTATUS != "good" ]; then
echo
echo "'git user.email' and 'git user.name' must be set to proceed"
echo "with merging commits to the kernel source."
echo "git will not merge commits without these values set."
echo "Example lines that would set these values, including '\"', are:"
echo " git config --global user.email \"your.email@domain.you\""
echo " git config --global user.name \"Your Name\""
echo "User:"
whoami
echo "Network address should be somewhere here:"
ip addr | grep inet
echo "Consider setting the git values in another terminal, then"
echo "press 'Enter' in this terminal."
read NOMINAL
fi
done


wait $CLNBIN
echo "## Completed git clone of binutils" | tee -a _000_stepsOut.txt
if kill -0 "$CLNGCC" >/dev/null 2>&1; then
echo clone of gcc still running | tee -a _000_stepsOut.txt
else
echo NOT clone of gcc running | tee -a _000_stepsOut.txt
fi
if kill -0 "$CLNKRN" >/dev/null 2>&1; then
echo clone of kernel still running | tee -a _000_stepsOut.txt
else
echo NOT clone of kernel running | tee -a _000_stepsOut.txt
fi
date | tee -a _000_stepsOut.txt

wait $CLNKRN
echo "## Completed git clone of Linux kernel" | tee -a _000_stepsOut.txt
date | tee -a _000_stepsOut.txt

wait $CLNGCC
echo "## Completed git clone of gcc" | tee -a _000_stepsOut.txt
date | tee -a _000_stepsOut.txt
39 changes: 39 additions & 0 deletions dists/Ubuntu/kernel/steps/2_build_bpf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

set -e
cd kernel
echo $0 > _00_steprunning.txt

date | tee -a _000_stepsOut.txt

# leave binutils at master; no checkout required
echo "## starting build of BPF binutils" | tee -a _000_stepsOut.txt
mkdir -p _buildbinutils
cd _buildbinutils
# configure binutils for bpf
../srcbinut/configure --prefix=/usr/local --target=bpf-unknown-none \
> ../_2cfgbinutout.txt 2>&1
make -j $(($(getconf _NPROCESSORS_ONLN)+1)) >> ../_2makebinutout.txt 2>&1
sudo make install >> ../_2makebinutout.txt 2>&1
cd ..

echo "## starting build of BPF gcc" | tee -a _000_stepsOut.txt
cd srcgcc/
git checkout releases/gcc-10
cd ..
mkdir -p _buildgcc
cd _buildgcc
# configure gcc for bpf
../srcgcc/configure --prefix=/usr/local --target=bpf-unknown-none \
--disable-bootstrap > ../_2cfggccout.txt 2>&1
make -j $(($(getconf _NPROCESSORS_ONLN)+1)) >> ../_2makegccout.txt 2>&1
sudo make install >> ../_2makegccout.txt 2>&1
cd ..

date | tee -a _000_stepsOut.txt
90 changes: 90 additions & 0 deletions dists/Ubuntu/kernel/steps/3_kernel_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
#
# Oracle Linux DTrace.
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

# This script offers no error checking for user input. The assumption is the
# user will select valid values for the version of the additional tracing
# features and the Ubuntu kernel version.
# Also, the assumption is the user will select a tracing features version
# less than or equal to the Ubuntu kernel version.

set -e
cd kernel
echo $0 > _00_steprunning.txt

date | tee -a _000_stepsOut.txt

# Glean known good kernels as suggestions for user
UKPROMPT=`cat ./steps/eg_ubuntu_kern`
DKPROMPT=`cat ./steps/eg_dtrace_kern`

# Collect information now -- select branches and add tracing and Ubuntu commits.
cd DTrace-Ubuntu-kernel

# Source Ubuntu kernel commits
git remote add Ubuntu https://git.launchpad.net/~ubuntu-kernel-test/ubuntu/\
+source/linux/+git/mainline-crack
echo "## Beginning update of Ubuntu source remote" | \
tee -a ../_000_stepsOut.txt
git remote update Ubuntu >> ../_3ubupout.txt 2>&1

# Source tracing feature commits for DTrace to use
echo ""
git remote add dtrace https://github.com/oracle/dtrace-linux-kernel
echo "## Beginning update of kernel source with additional tracing features." |\
tee -a ../_000_stepsOut.txt
git remote update dtrace >> ../_3dtupout.txt 2>&1
echo "Listing of kernel branches with additional tracing features:" | \
tee -a ../_000_stepsOut.txt
git remote show dtrace | grep "v2/"

# See Ubuntu kernel source here: https://kernel.ubuntu.com/~kernel-ppa/mainline/
# and pick checkout version based on the kernel version we intend to build.
echo "## Select Ubuntu kernel source branch" | tee -a ../_000_stepsOut.txt
echo "Consider using a browser to see the Ubuntu kernels available at:"
echo " https://kernel.ubuntu.com/~kernel-ppa/mainline/"
echo "Note the kernel versions in the list above, which will be needed"
echo "to find a near match with the Ubuntu kernel chosen here."
echo "TracingKernelVersion <= UbuntuKernelVersion"
echo "Enter Ubuntu kernel version numbers here (e.g. $UKPROMPT):"
read UKERNEL

# Save the kernel version chosen, for later reference (selecting reboot kernel)
echo "Ubuntu kernel version selected $UKERNEL" | tee -a ../_000_stepsOut.txt
echo $UKERNEL > ../_3kernel-build-version

# git ls-remote --tags Ubuntu -l *cod*v$UKERNEL
echo "## Fetching Ubuntu kernel tag" | tee -a ../_000_stepsOut.txt
git fetch Ubuntu "refs/tags/cod/mainline/v$UKERNEL:cod/mainline/v$UKERNEL"

echo "## Checking-out kernel version" | tee -a ../_000_stepsOut.txt
git checkout v$UKERNEL -b DTraceUbuntu_$UKERNEL

echo "## Merging Ubuntu commits" | tee -a ../_000_stepsOut.txt
git merge --no-edit cod/mainline/v$UKERNEL >> ../_3ubmrgout.txt 2>&1

# Choose the appropriate version providing additional tracing features to use
# as a code source.
# Pick checkout version based on the kernel version we intend to build.
echo "The kernel version from the additional tracing feature repository must be"
echo "equal to or less than Ubuntu version $UKERNEL. If there is no choice"
echo "equal, choose the nearest version less than the Ubuntu version"
echo "(previously chosen)."
echo "See the output above for the additional tracing feature kernel versions"
echo "available."
echo "Enter additional tracing features kernel version numbers here"
echo "(e.g. $DKPROMPT):"
read DKERNEL
echo "Tracing version selected $DKERNEL" | tee -a ../_000_stepsOut.txt

echo "## Merging commits for additional tracing features" | \
tee -a ../_000_stepsOut.txt
git merge --no-edit dtrace/v2/$DKERNEL | tee -a ../_3dtmrgout.txt 2>&1

cd ..

date | tee -a _000_stepsOut.txt

0 comments on commit 0f94bd8

Please sign in to comment.