Skip to content

Commit

Permalink
Merge pull request iovisor#835 from ColinIanKing/master
Browse files Browse the repository at this point in the history
Add snapcraft script to package up bcc as a snap
  • Loading branch information
4ast authored Dec 21, 2016
2 parents 8b302d0 + 96875c5 commit dd5799b
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 0 deletions.
53 changes: 53 additions & 0 deletions snapcraft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright (C) 2016 Canonical
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

#
# Simple makefile to mangle version info in the yaml file
#
VERSION=$(shell git tag | tail -1 | cut -c2-)
COMMITS=$(shell git log --oneline | wc -l)
SHA=$(shell git log -1 --oneline | cut -d' ' -f1)
DATE=$(shell date +'%Y%m%d')
V=$(VERSION)-$(DATE)-$(COMMITS)-$(SHA)

all: set_version
snapcraft

set_version:
cat snapcraft.yaml | sed 's/version: .*/version: $(V)/' > snapcraft-tmp.yaml
mv snapcraft-tmp.yaml snapcraft.yaml

install:
#
# Install latest snap
#
sudo snap install --devmode bcc_*.snap

#
# Connect up interfaces
#
sudo snap connect bcc:mount-observe
sudo snap connect bcc:system-observe
sudo snap connect bcc:system-trace

remove:
sudo snap remove bcc

clean:
snapcraft clean
rm -rf setup *.snap snapcraft
44 changes: 44 additions & 0 deletions snapcraft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# bcc snap

This is an unconfined snap of the BPF Compiler Collection (BCC), a toolkit for
creating efficient kernel tracing and manipulation programs.

First, install snapcraft, e.g. on Ubuntu:

sudo apt install snapcraft

Clone the bcc repo (if you haven't done so already) and create the snap:

git clone https://github.com/iovisor/bcc.git
cd snapcraft
make

Note: running `make` just gets the version from the current bcc gito
repository and uses this in the snapcraft yaml file to version the bcc
snap. The Makefile basically runs snapcraft to snap up bcc.

Install the snap by running:

sudo snap install --devmode bcc_*.snap

One may need to ensure the snap plugins are enabled for the snap using:

sudo snap connect bcc:mount-observe
sudo snap connect bcc:system-observe
sudo snap connect bcc:system-trace

Now run a bcc tool, for example, to run opensnoop use:

sudo bcc.opensnoop

Note that this may fail to build and run if you do not have the kernel
headers installed or perhaps the kernel config is not set up correctly.

This snap has been tested using the mainly 4.8 and 4.9 kernels built
with the Ubuntu Yakkety and Zesty kernel configs as well as the default
Ubuntu 4.8 Yakkey and 4.9 Zesty kernels.

Contact Colin Ian King <[email protected]> for support on this
bcc snap.

Thu 15 Dec 17:08:29 GMT 2016
169 changes: 169 additions & 0 deletions snapcraft/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#
# Copyright (C) 2016 Canonical
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
name: bcc
version: 0.2.0-20161215-1402-7151673
summary: BPF Compiler Collection (BCC)
description: A toolkit for creating efficient kernel tracing and manipulation programs
confinement: strict
grade: stable
plugs:
mount-observe: null
system-observe: null
system-trace: null
apps:
argdist:
command: wrapper argdist
bashreadline:
command: wrapper bashreadline
biolatency:
command: wrapper biolatency
biosnoop:
command: wrapper biosnoop
biotop:
command: wrapper biotop
bitesize:
command: wrapper bitesize
btrfsdist:
command: wrapper btrfsdist
btrfsslower:
command: wrapper btrfsslower
cachestat:
command: wrapper cachestat
cachetop:
command: wrapper cachetop
cpudist:
command: wrapper cpudist
dcsnoop:
command: wrapper dcsnoop
dcstat:
command: wrapper dcstat
execsnoop:
command: wrapper execsnoop
ext4dist:
command: wrapper ext4dist
ext4slower:
command: wrapper ext4slower
filelife:
command: wrapper filelife
fileslower:
command: wrapper fileslower
filetop:
command: wrapper filetop
funccount:
command: wrapper funccount
funclatency:
command: wrapper funclatency
gethostlatency:
command: wrapper gethostlatency
hardirqs:
command: wrapper hardirqs
killsnoop:
command: wrapper killsnoop
mdflush:
command: wrapper mdflush
memleak:
command: wrapper memleak
offcputime:
command: wrapper offcputime
offwaketime:
command: wrapper offwaketime
oomkill:
command: wrapper oomkill
opensnoop:
command: wrapper opensnoop
pidpersec:
command: wrapper pidpersec
runqlat:
command: wrapper runqlat
slabratetop:
command: wrapper slabratetop
softirqs:
command: wrapper softirqs
sslsniff:
command: wrapper sslsniff
stackcount:
command: wrapper stackcount
stacksnoop:
command: wrapper stacksnoop
statsnoop:
command: wrapper statsnoop
syncsnoop:
command: wrapper syncsnoop
tcpaccept:
command: wrapper tcpaccept
tcpconnect:
command: wrapper tcpconnect
tcpconnlat:
command: wrapper tcpconnlat
tcplife:
command: wrapper tcplife
tcpretrans:
command: wrapper tcpretrans
tcptop:
command: wrapper tcptop
ttysnoop:
command: wrapper ttysnop
trace:
command: wrapper trace
vfscount:
command: wrapper vfscount
vfsstat:
command: wrapper vfsstat
wakeuptime:
command: wrapper wakeuptime
xfsdist:
command: wrapper xfsdist
xfsslower:
command: wrapper xfsslower
zfsdist:
command: wrapper zfsdist
zfsslower:
command: wrapper zfsslower
parts:
bcc:
plugin: cmake
configflags:
- -DCMAKE_INSTALL_PREFIX=/usr
source: ..
build-packages:
- bison
- build-essential
- cmake
- flex
- libedit-dev
- libllvm3.7
- llvm-3.7-dev
- libclang-3.7-dev
- python
- zlib1g-dev
- libelf-dev
stage-packages:
- python
snap:
- usr/bin/python*
- usr/share/bcc/tools
- usr/lib/*/lib*.so*
- usr/lib/python2.7
- -usr/share/bcc/tools/doc
wrapper:
source: .
plugin: copy
files:
wrapper: bin/wrapper

# vim: set ai et sts=4 tabstop=4 sw=4:
14 changes: 14 additions & 0 deletions snapcraft/wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e
# Snappy does not yet support CAP_SYS_ADMIN for unconfined snaps, thus sudo:
# https://bugs.launchpad.net/snappy/+bug/1586581
# stdout isn't set to line buffered mode:
# https://bugs.launchpad.net/snappy/+bug/1587675

cmd="$1"
if [ `id -u` = 0 ] ; then
shift
stdbuf -oL $SNAP/usr/bin/python "$SNAP/usr/share/bcc/tools/$cmd" $@
else
echo "Need to run $cmd as root (use sudo $@)"
exit 1
fi

0 comments on commit dd5799b

Please sign in to comment.