platform/upstream/bcc.git
6 years agoadd --state to offcputime
Brendan Gregg [Tue, 1 Aug 2017 01:39:30 +0000 (18:39 -0700)]
add --state to offcputime

6 years agoexplain that 'args' can be used as 'ctx' in tracepoints
Jean-Tiare Le Bigot [Sun, 30 Jul 2017 17:19:11 +0000 (19:19 +0200)]
explain that 'args' can be used as 'ctx' in tracepoints

6 years agomake it easier to discover the reference documentation
Jean-Tiare Le Bigot [Sun, 30 Jul 2017 17:17:57 +0000 (19:17 +0200)]
make it easier to discover the reference documentation

6 years agotcptop: Filter out negative values in receive probe
Benjamin Poirier [Fri, 28 Jul 2017 20:25:14 +0000 (13:25 -0700)]
tcptop: Filter out negative values in receive probe

When tcp_cleanup_rbuf() is called from tcp_recvmsg(), "copied" may be an
error code, especially -EAGAIN for non-blocking receives.

6 years agotcptop: Cleanup argument parsing
Benjamin Poirier [Thu, 27 Jul 2017 23:07:06 +0000 (16:07 -0700)]
tcptop: Cleanup argument parsing

6 years agoUse unsigned conversion specifier for nlmsg_pid
Toshiaki Makita [Mon, 31 Jul 2017 11:20:55 +0000 (20:20 +0900)]
Use unsigned conversion specifier for nlmsg_pid

nlmsg_pid is __u32, so let's use %u instead of %d.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
6 years agoFix wrong netlink port id check
Toshiaki Makita [Mon, 31 Jul 2017 11:20:55 +0000 (20:20 +0900)]
Fix wrong netlink port id check

As per man netlink, nlmsg_pid is not process id and in fact a value
different from process id can be used.

  bpf: Wrong pid -1615084642, expected 24407

This problem can be triggered by using pyroute2 with bcc.

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
6 years agoRemove redundant semicolon
Nan Xiao [Mon, 31 Jul 2017 05:02:20 +0000 (13:02 +0800)]
Remove redundant semicolon

6 years ago1. Use more safe snprintf instead of sprintf;
Nan Xiao [Sat, 29 Jul 2017 02:47:24 +0000 (10:47 +0800)]
1. Use more safe snprintf instead of sprintf;
2. Modify procfilename buffer length in bcc_procutils_language function.

6 years agoPut libfl-dev into Build-Depends on Debian
Ivan Babrou [Fri, 28 Jul 2017 21:57:26 +0000 (14:57 -0700)]
Put libfl-dev into Build-Depends on Debian

On Debian Stretch `libfl-dev` is not installed automatically
if you install `flex`, this takjes care of the issue.

6 years agoMerge pull request #1263 from iovisor/yhs_dev
Brenden Blanco [Thu, 27 Jul 2017 15:47:08 +0000 (08:47 -0700)]
Merge pull request #1263 from iovisor/yhs_dev

permit multiple pids attaching to the same probe

6 years agopermit multiple pids attaching to the same probe
Yonghong Song [Sat, 22 Jul 2017 05:13:20 +0000 (22:13 -0700)]
permit multiple pids attaching to the same probe

Currently, if more than one pid-associated USDT attaching to
the same probe, usdt readarg code will be generated twice and
the compiler will complain.

This patch solves issue by preventing code duplication if
a previous context with the same mnt point and exec binary
has generated the code for the same probe. The event name is
also changed to have pid embedded so different pid-associated
uprobe event will have different names.

This patch introduces an internal uprobe event name
discrepency. It is a good idea to have event name
generation in libbpf so that both C++ API and Python API
will have consistent name conventions. This will be
addressed in a subsequent commit as it is largely
a different issue.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1261 from iovisor/yhs_dev
4ast [Wed, 19 Jul 2017 05:08:48 +0000 (22:08 -0700)]
Merge pull request #1261 from iovisor/yhs_dev

generate proper usdt code to prevent llvm meddling with ctx->#fields

6 years agogenerate proper usdt code to prevent llvm meddling with ctx->#fields
Yonghong Song [Tue, 18 Jul 2017 21:12:10 +0000 (14:12 -0700)]
generate proper usdt code to prevent llvm meddling with ctx->#fields

Qin reported a test case where llvm still messes up with ctx->#fields.
For code like below:
  switch(ctx->ip) {
    case 0x7fdf2ede9820ULL: *((int64_t *)dest) = *(volatile int64_t *)&ctx->r12; return 0;
    case 0x7fdf2edecd9cULL: *((int64_t *)dest) = *(volatile int64_t *)&ctx->bx; return 0;
  }
The compiler still generates:
    # r1 is the pointer to the ctx
    r1 += 24
    goto LBB0_4
  LBB0_3:
    r1 += 40
  LBB0_4:
    r3 = *(u64 *)(r1 + 0)
The verifier will reject the above code since the last load is not "ctx + field_offset"
format.

The responsible llvm optimization pass is CFGSimplifyPass. Its main implementation
in llvm/lib/Transforms/Utils/SimplifyCFG.cpp. The main routine to do the optimization
is SinkThenElseCodeToEnd. The routine canSinkInstructions is used to determine whether
an insn is a candidate for sinking.

Unfortunately, volatile load/store is not a condition to prevent the optimization.
But inline assembly is a condition which can prevent further optimization.

In this patch, instead of using volatile to annotate ctx->#field access, we do
normal ctx->#field access but put a compiler inline assembly memory barrier
   __asm__ __volatile__(\"\": : :\"memory\");
after the field access.

Tested with usdt unit test case, usdt_samples example, a couple of usdt unit tests
developed in the past.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMySQL tracing without USDT (#1239)
Igor Mazur [Tue, 18 Jul 2017 07:06:34 +0000 (10:06 +0300)]
MySQL tracing without USDT (#1239)

Support tracing MySQL queries even when MySQL is built
without USDT support, by using uprobes on internal functions
responsible for command (query) dispatching.

6 years agoMerge pull request #1259 from iovisor/yhs_dev
4ast [Tue, 18 Jul 2017 07:04:45 +0000 (00:04 -0700)]
Merge pull request #1259 from iovisor/yhs_dev

Fix a clang memory leak

6 years agoFix a clang memory leak
Yonghong Song [Tue, 18 Jul 2017 06:20:17 +0000 (23:20 -0700)]
Fix a clang memory leak

In clang frontend actions, several compiler invocations are called
for rewriter and transforming source code to IR. During the invocation
to transform source code to IR, CodeGenOpts.DisableFree is used
to control whether the top target machine structure should be
freed or not for a particular clang invocation,
and its default value is TRUE.

See clang:lib/CodeGen/BackendUtil.cpp:
  ~EmitAssemblyHelper() {
    if (CodeGenOpts.DisableFree)
      BuryPointer(std::move(TM));
  }

So by default, the memory held by TM will not freed, even if
BPF module itself is freed. This is even more problematic
when continuous building/loading/unloading happens for long
live service.

This patch explicitly sets CodeGenOpts.DisableFree to FALSE
so memory can be properly freed. I did a simple experiment
to compile/load/unload an empty BPF program and the saving
is roughly 0.5MB.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1258 from shodoco/tcpbpf
Brenden Blanco [Mon, 17 Jul 2017 22:55:57 +0000 (15:55 -0700)]
Merge pull request #1258 from shodoco/tcpbpf

Update bpf.h and virtual_bpf.h to 4.13-rc1

6 years agoUpdate bpf.h and virtual_bpf.h to 4.13-rc1
Huapeng Zhou [Mon, 17 Jul 2017 22:06:14 +0000 (15:06 -0700)]
Update bpf.h and virtual_bpf.h to 4.13-rc1

6 years agotools: Add some documentation to lib/ucalls.py output (#1257)
Geneviève Bastien [Fri, 14 Jul 2017 20:04:12 +0000 (16:04 -0400)]
tools: Add some documentation to lib/ucalls.py output (#1257)

Signed-off-by: Geneviève Bastien <gbastien@versatic.net>
6 years agoFix trace.py for library filenames containing colons (#1252)
vkhromov [Fri, 14 Jul 2017 19:42:29 +0000 (20:42 +0100)]
Fix trace.py for library filenames containing colons (#1252)

`trace.py` parses a probe using the colon as a separator.  As a result, it
fails to create a uprobe for binary/library with a filename containing colons.

This diff fixes that issue with `trace.py`.  It requires a kernel with
https://lkml.org/lkml/2017/1/13/585 merged to work properly, otherwise
`trace.py` still fails for create uprobes.

6 years agocc: Add open_perf_event to the C/C++ API (#1232)
Romain [Tue, 11 Jul 2017 18:15:09 +0000 (11:15 -0700)]
cc: Add open_perf_event to the C/C++ API (#1232)

6 years agomemleak: expand allocator coverage (#1214)
Rinat Ibragimov [Tue, 11 Jul 2017 18:14:08 +0000 (21:14 +0300)]
memleak: expand allocator coverage (#1214)

* memleak: handle libc allocation functions other than malloc

* memleak: use tracepoints to track kernel allocations

* memleak: add combined-only mode

With large number of outstanding allocations, amount of data passed from
kernel becomes large, which slows everything down.

This patch calculates allocation statistics inside kernel, allowing user-
space part to pull combined statistics data only, thus significantly
reducing amount of passed data.

* memleak: increase hashtable capacities

There are a lot of allocations happen in kernel. Default values are not
enough to keep up.

* test: add a test for the memleak tool

6 years agoAdd USDT sample (#1229)
bveldhoen [Tue, 11 Jul 2017 18:09:35 +0000 (20:09 +0200)]
Add USDT sample (#1229)

This sample contains:
    - A library with an operation that uses usdt probes.
    - A console application that calls the operation.
    - Scripts to trace the latency of the operation.
    - Corresponding cmake files.

6 years agodocs: update features list
Quentin Monnet [Fri, 7 Jul 2017 11:39:40 +0000 (13:39 +0200)]
docs: update features list

And fix a typo: direct_action -> direct-action

6 years agolibbpf: fix build warning on setns (#1246)
Colin Ian King [Thu, 6 Jul 2017 12:58:17 +0000 (13:58 +0100)]
libbpf: fix build warning on setns (#1246)

The macro _GNU_SOURCE should be defined to pick up the function
declaration for setns.  Fixes build warning:

"src/cc/libbpf.c:482:7: warning: implicit declaration of
 function 'setns' [-Wimplicit-function-declaration]
   if (setns(target_fd, CLONE_NEWNS)) {"

Signed-off-by: Colin Ian King <colin.king@canonical.com>
6 years agoMerge pull request #1237 from iovisor/yhs_dev
4ast [Sat, 1 Jul 2017 19:59:49 +0000 (12:59 -0700)]
Merge pull request #1237 from iovisor/yhs_dev

Fix bcc.lua build issue in Ubuntu 17.04

6 years agousdt: Use ProcMountNS
Vicent Marti [Tue, 27 Jun 2017 17:06:46 +0000 (19:06 +0200)]
usdt: Use ProcMountNS

6 years agoproc: Enhance bcc_mapping_is_file_backed
Vicent Marti [Tue, 27 Jun 2017 13:22:38 +0000 (15:22 +0200)]
proc: Enhance bcc_mapping_is_file_backed

Cleanup the `strncmp` code and add a few more ignored map names

6 years agoFix bcc.lua build issue in Ubuntu 17.04
Yonghong Song [Fri, 30 Jun 2017 05:46:29 +0000 (22:46 -0700)]
Fix bcc.lua build issue in Ubuntu 17.04

In fc25 box, gcc6.3.1 is configured with pie default off.
Here, pie stands for position independent execution.

In ubuntu 17.04, gcc6.3.0, however, is configured with
pie default on. The gcc driver automatically adds -pie
to the linker options.

Since bcc.lua build needs pie off, previously, -fno-pie
is passed to the compiler. -fno-pie is a gcc option
impacting the code generation and it didn't
negate the -pie option in the linker. The correct way
seems to use gcc linker option -no-pie which can
successfully cancel the default -pie in the linker.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoUpdate LINKS.md
Nan Xiao [Fri, 30 Jun 2017 01:52:47 +0000 (09:52 +0800)]
Update LINKS.md

6 years agoAdded helpers for BPF_PERCPU_ARRAY (#1230)
Romain [Thu, 29 Jun 2017 19:00:31 +0000 (12:00 -0700)]
Added helpers for BPF_PERCPU_ARRAY (#1230)

6 years agoAdd an option to strip leading zeros from histograms (#1226)
Taekho Nam [Thu, 29 Jun 2017 14:20:47 +0000 (23:20 +0900)]
Add an option to strip leading zeros from histograms (#1226)

6 years agotest: python3 fix for test_uprobes (#1228)
Brenden Blanco [Fri, 23 Jun 2017 08:08:07 +0000 (01:08 -0700)]
test: python3 fix for test_uprobes (#1228)

Treat strings as bytes. This is independent of the larger refactor
(#1139) from which it is cherry-picked)

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
6 years agogethostlatency was rounding to full ms
Brendan Gregg [Thu, 22 Jun 2017 18:58:21 +0000 (11:58 -0700)]
gethostlatency was rounding to full ms

6 years agoChange clang frontend optimization level from 0 to 2
Yonghong Song [Mon, 12 Jun 2017 01:37:25 +0000 (18:37 -0700)]
Change clang frontend optimization level from 0 to 2

The issue is caused by the following clang change on 5.0:
https://reviews.llvm.org/D28404

Basically, at -O0, unless always inlining is specified, a
function will be marked as optnone and noinline.

This causes two kinds of issues: (1). optnone will generate
suboptimal code with heavy stack use and this high likely can
cause verifier failure; and (2). even if user mark all his/her
defined functions in bpf program as always inlining, some
functions in linux header files are not marked as always inline
and hence will be marked as noinline instead, ultimately
causing llvm complaining about global function reference.

This patch bumps the clang optimization level to -O2.
This should work with older versions of llvm as well.

Signed-off-by: Yonghong Song <yhs@fb.com>
6 years agoMerge pull request #1224 from NavinF/patch-1
Brendan Gregg [Wed, 14 Jun 2017 16:28:13 +0000 (09:28 -0700)]
Merge pull request #1224 from NavinF/patch-1

Update the installation instructions for Fedora

6 years agoUpdate the installation instructions for Fedora
Navin Francis [Wed, 14 Jun 2017 13:15:07 +0000 (06:15 -0700)]
Update the installation instructions for Fedora

6 years agoAdd probe result verification for usdt unit test
Yonghong Song [Fri, 2 Jun 2017 07:41:44 +0000 (00:41 -0700)]
Add probe result verification for usdt unit test

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoAdd installation instructions for openSUSE (#1222)
Gary Ching-Pang Lin [Mon, 12 Jun 2017 10:22:10 +0000 (18:22 +0800)]
Add installation instructions for openSUSE (#1222)

7 years agofix cc: error: unrecognized command line option -no-pie
Carlos Neira [Fri, 9 Jun 2017 19:07:37 +0000 (15:07 -0400)]
fix cc: error: unrecognized command line option -no-pie

cnb@ubuntu-14:~/iovisor/bcc/build$ make
[  6%] Built target clang_frontend
[  9%] Built target bpf-static
[ 16%] Built target bcc-loader-static
[ 30%] Built target b_frontend
[ 47%] Built target bcc-static
[ 48%] Built target CPUDistribution
[ 50%] Built target FollyRequestContextSwitch
[ 51%] Built target HelloWorld
[ 52%] Built target LLCStat
[ 54%] Built target RandomRead
[ 55%] Built target RecordMySQLQuery
[ 56%] Built target TCPSendStack
[ 80%] Built target bcc-shared
[ 83%] Built target bpf-shared
[ 84%] Built target bcc_py
Linking C executable bcc-lua
cc: error: unrecognized command line option â-no-pieâ
make[2]: *** [src/lua/bcc-lua] Error 1
make[1]: *** [src/lua/CMakeFiles/bcc-lua.dir/all] Error

option is called -fno-pie

7 years agoFix ld error due to debian/ubuntu -pie default
Ryan Tomayko [Mon, 5 Jun 2017 17:43:46 +0000 (17:43 +0000)]
Fix ld error due to debian/ubuntu -pie default

Fixes #782. Solution taken verbatim from @jepio here:

https://github.com/iovisor/bcc/issues/782#issuecomment-259075010

I ran into the same issue attempting to compile from source on
a fresh Ubuntu 16.10/Yakkety host:

Linking C executable bcc-lua
/usr/bin/ld: libluajit-5.1.a(ljamalg.o): relocation R_X86_64_32S
    against `.rodata' can not be used when making a shared object;
    recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

Build succeeded after patch was applied.

7 years agofix incorrect code generation in usdt
Yonghong Song [Tue, 6 Jun 2017 00:55:24 +0000 (17:55 -0700)]
fix incorrect code generation in usdt

o This is caused by my ignorant error in previous usdt change.
  Obviously, I need to store into pointer address in order to
  propagate value back to caller.
o Thanks Tetsuo Handa pointing this out.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoAdd missing funcslower from the snap.
Evan Dandrea [Thu, 27 Apr 2017 15:20:39 +0000 (11:20 -0400)]
Add missing funcslower from the snap.

7 years agoAdd aliases for all commands in the snap (e.g. bcc.biotop -> biotop)
Evan Dandrea [Thu, 27 Apr 2017 15:16:01 +0000 (11:16 -0400)]
Add aliases for all commands in the snap (e.g. bcc.biotop -> biotop)

7 years agoRequire a more recent, auto-updating version of snapd for alises.
Evan Dandrea [Mon, 8 May 2017 13:04:00 +0000 (08:04 -0500)]
Require a more recent, auto-updating version of snapd for alises.

7 years agoAdd libbcc-example package for Ubuntu Xenial
Taekho Nam [Mon, 5 Jun 2017 09:52:39 +0000 (09:52 +0000)]
Add libbcc-example package for Ubuntu Xenial

7 years agoAdd a python test for usdt
Yonghong Song [Tue, 30 May 2017 13:37:02 +0000 (06:37 -0700)]
Add a python test for usdt

  o The sample application covers different aspects
    of usdt rewriter code generation:
    - const
    - *(ctx + offset)
    - use bpf_probe_read to get trace data
    - the switch in ctx->ip if the same probe
      is triggered in multiple .text locations.
  o folly (https://github.com/facebook/folly/) tracing
    header files are pulled into python test directory and
    used to produce USDT probes.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoImprove PerfEventArray clean up
Teng Qin [Thu, 25 May 2017 20:30:13 +0000 (13:30 -0700)]
Improve PerfEventArray clean up

7 years agoMerge pull request #1212 from iovisor/yhs_dev
4ast [Wed, 31 May 2017 21:08:57 +0000 (14:08 -0700)]
Merge pull request #1212 from iovisor/yhs_dev

Force udst ctx->#reg load to be volatile

7 years agoMerge pull request #1211 from iovisor/libbpf_c_includes
4ast [Wed, 31 May 2017 16:08:43 +0000 (09:08 -0700)]
Merge pull request #1211 from iovisor/libbpf_c_includes

Add linux/sched.h to list of libbpf.c includes

7 years agoAdd linux/sched.h to list of libbpf.c includes
Brenden Blanco [Wed, 31 May 2017 15:44:22 +0000 (08:44 -0700)]
Add linux/sched.h to list of libbpf.c includes

This should hopefully fix compile errors on some ubuntu systems.

Also, reorders the includes according to clang-format

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agomake libbpf standalone-ready
Brenden Blanco [Wed, 31 May 2017 00:35:53 +0000 (17:35 -0700)]
make libbpf standalone-ready

Break the c++ dependency in libbpf.c, and turn it into a separate lib
from cmake point of view.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agoMove ProcMountNSGuard to separate file
Brenden Blanco [Thu, 25 May 2017 20:24:15 +0000 (13:24 -0700)]
Move ProcMountNSGuard to separate file

This moves ProcMountNS[Guard] classes to a separate header file and
implementation. The goal will be to use these more directly in libbpf.c
without creating a circular dependency.
Removed the friend class statements and exposed a few public getters instead.
Slightly changed the implementation in ProcMountNS constructor to avoid
a few error cases and the use of snprintf.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agobcc_procutils_which: return if snprintf fails or would overflow
Christian Resell [Fri, 26 May 2017 19:44:07 +0000 (21:44 +0200)]
bcc_procutils_which: return if snprintf fails or would overflow

7 years agobcc_proc.c: fix stack overflow in bcc_procutils_which()
Christian Resell [Fri, 26 May 2017 14:50:52 +0000 (16:50 +0200)]
bcc_proc.c: fix stack overflow in bcc_procutils_which()

7 years agoForce udst ctx->#reg load to be volatile
Yonghong Song [Tue, 30 May 2017 09:03:06 +0000 (02:03 -0700)]
Force udst ctx->#reg load to be volatile

This is related to issue #1133. Compiler sometimes
generates code patterns likes:
     r1 = ctx + 96
     goto next
   here:
     r1 = ctx + 48
   next:
     r3 = load (r1 + 0)
Verifier will fail for such cases as r1 is marked
as "unknown" at the time of load.

The previous workaround is to add volatile attribute
to the store like
   *(volatile u64 *)&dest = ctx->bx
The hope is to force ctx related load in-place since
its value is needed for store.

Unfortunately, this does not always work and compiler
still has freedom to merge different ctx loads at the
same time honoring the volatile &dest. In USDT generated
code, different branches of &dest are the same.

This patch directly make ctx->bx itself as a volatile load:
  *(volatile u64 *)&ctx->bx
This seems working as compiler stops playing around
the address pointing to a volatile data.

Signed-off-by: Yonghong Song <yhs@fb.com>
7 years agoMention that linux-headers deb must be installed.
Tomaz Solc [Fri, 26 May 2017 11:52:30 +0000 (13:52 +0200)]
Mention that linux-headers deb must be installed.

7 years agoMerge pull request #1201 from htbegin/master
Brenden Blanco [Thu, 25 May 2017 18:54:14 +0000 (11:54 -0700)]
Merge pull request #1201 from htbegin/master

funclatency/sslsniff: fix the TypeError when enabling pid filter on u…

7 years agoMerge pull request #1191 from GBuella/cmake_build_type_fix
4ast [Thu, 25 May 2017 05:14:11 +0000 (22:14 -0700)]
Merge pull request #1191 from GBuella/cmake_build_type_fix

Fix usage of CMAKE_BUILD_TYPE setting

7 years agoMerge pull request #1190 from palmtenor/cur_cpu
4ast [Thu, 25 May 2017 05:13:44 +0000 (22:13 -0700)]
Merge pull request #1190 from palmtenor/cur_cpu

Use BPF_F_CURRENT_CPU in perf_submit when possible

7 years agoUse BPF_F_CURRENT_CPU in perf_submit / perf_read when possible
Teng Qin [Tue, 23 May 2017 18:57:44 +0000 (11:57 -0700)]
Use BPF_F_CURRENT_CPU in perf_submit / perf_read when possible

7 years agoMerge pull request #1200 from palmtenor/perf_event_clean_up
4ast [Wed, 24 May 2017 20:08:26 +0000 (13:08 -0700)]
Merge pull request #1200 from palmtenor/perf_event_clean_up

Improve perf event clean up

7 years agoDisable perf event FD before free
Teng Qin [Wed, 24 May 2017 05:18:56 +0000 (22:18 -0700)]
Disable perf event FD before free

7 years agoAdd bpf_close_perf_event_fd
Teng Qin [Tue, 23 May 2017 23:35:11 +0000 (16:35 -0700)]
Add bpf_close_perf_event_fd

Add bpf_close_perf_event_fd helper that first disables, then closes a
perf event fd. Use it in Python and C++ API for detach perf event

7 years agoMerge pull request #1196 from palmtenor/cpp_sym_option
4ast [Wed, 24 May 2017 16:53:51 +0000 (09:53 -0700)]
Merge pull request #1196 from palmtenor/cpp_sym_option

Support symbol option in C++ API stack table

7 years agofunclatency/sslsniff: fix the TypeError when enabling pid filter on uprobe
htbegin [Wed, 24 May 2017 14:53:17 +0000 (22:53 +0800)]
funclatency/sslsniff: fix the TypeError when enabling pid filter on uprobe

attach_uprobe() and attach_uretprobe() expect the type of pid argument
is "int" instead of "str". Fix it by specifying the type of the "-p"/"--pid"
option as "int", and updating the format string of args.pid accordingly.

Fixes: d73c58f0c8c754bd591264205ac2ddc83c1d2c7f

7 years agoMerge pull request #1185 from gospo/master
Brenden Blanco [Tue, 23 May 2017 18:56:59 +0000 (11:56 -0700)]
Merge pull request #1185 from gospo/master

Add support for generic XDP mode

7 years agoSupport symbol option in C++ API stack table
Teng Qin [Tue, 23 May 2017 18:30:33 +0000 (11:30 -0700)]
Support symbol option in C++ API stack table

7 years agoAdd support for generic XDP mode
Andy Gospodarek [Wed, 17 May 2017 20:18:45 +0000 (16:18 -0400)]
Add support for generic XDP mode

Reused some of the code and command-line format from kernel XDP samples.

$ sudo ./xdp_drop_count.py -S enp1s0
Printing drops per IP protocol-number, hit CTRL+C to stop
17: 36616 pkt/s
17: 19720757 pkt/s
17: 19685768 pkt/s
17: 19643601 pkt/s
17: 19694537 pkt/s
[...]
$ sudo ./xdp_drop_count.py enp1s0
Printing drops per IP protocol-number, hit CTRL+C to stop
17: 7029 pkt/s
17: 29996706 pkt/s
17: 30048705 pkt/s
17: 30261417 pkt/s
17: 30291967 pkt/s
[...]

Throughput difference is expected since generic XDP takes more
instructions per packet than optimized XDP.

v2: switch __u32 to uint32_t in bpf_attach_xdp

Signed-off-by: Andy Gospodarek <gospo@broadcom.com>
7 years agoMerge pull request #1193 from palmtenor/cppleak
4ast [Mon, 22 May 2017 16:31:24 +0000 (09:31 -0700)]
Merge pull request #1193 from palmtenor/cppleak

Fix bcc_resolve_symname memory leak in C++ API

7 years agoMerge pull request #1192 from palmtenor/perf_config
4ast [Mon, 22 May 2017 14:56:10 +0000 (07:56 -0700)]
Merge pull request #1192 from palmtenor/perf_config

Unify Perf Event related Enums and checks

7 years agoMerge pull request #1194 from palmtenor/minor_fixes
4ast [Mon, 22 May 2017 06:24:02 +0000 (23:24 -0700)]
Merge pull request #1194 from palmtenor/minor_fixes

Minor fixes for example and compiler warning

7 years agoFix compiler warning by cast int to pointer
Teng Qin [Sun, 21 May 2017 05:46:00 +0000 (22:46 -0700)]
Fix compiler warning by cast int to pointer

7 years agoGet correct PID in TCPSendStack example
Teng Qin [Sun, 21 May 2017 05:44:32 +0000 (22:44 -0700)]
Get correct PID in TCPSendStack example

7 years agoFix bcc_resolve_symname memory leak in C++ API
Teng Qin [Sun, 21 May 2017 05:11:30 +0000 (22:11 -0700)]
Fix bcc_resolve_symname memory leak in C++ API

7 years agoUnify perf event enums in Python API
Teng Qin [Sat, 20 May 2017 02:10:09 +0000 (19:10 -0700)]
Unify perf event enums in Python API

7 years agoUnify perf_event type and config check
Teng Qin [Sat, 20 May 2017 02:05:24 +0000 (19:05 -0700)]
Unify perf_event type and config check

7 years agoMerge pull request #1164 from palmtenor/symboloptions
Brenden Blanco [Sat, 20 May 2017 05:19:05 +0000 (22:19 -0700)]
Merge pull request #1164 from palmtenor/symboloptions

Add ability for users to control symboling behavior

7 years agoDo not pass type flag to symbol callback
Teng Qin [Wed, 10 May 2017 19:51:17 +0000 (12:51 -0700)]
Do not pass type flag to symbol callback

As the symbol type check now controled by the specified
`bcc_symbol_option` and handled in lower level, there is not need to
pass the type flag to the callback anymore.

7 years agoUse bcc_symbol_option in ProcSyms
Teng Qin [Wed, 10 May 2017 00:26:02 +0000 (17:26 -0700)]
Use bcc_symbol_option in ProcSyms

This commit makes `ProcSyms` constructor takes a `bcc_symbol_option`,
and pass it down to underlying calls to control symboling behavior.
If `nullptr` is passed, `ProcSyms` will use default setting, which is
to use debug file, verify debug file checksum, and only load function symbols.

This commit also makes `bcc_symcache_new` take a `bcc_symbol_option`
parameter and pass it to the underlying `ProcSyms` constructor.

7 years agoUse bcc_symbol_option in bcc_resolve_symname
Teng Qin [Tue, 9 May 2017 22:49:14 +0000 (15:49 -0700)]
Use bcc_symbol_option in bcc_resolve_symname

This commit makes `bcc_resolve_symname` to take an `bcc_symbol_option`
parameter, and pass it to underlying calls to control symboling behavior.
When `NULL` is passed, it will fallback to default which is current
behavior that uses debug file, verify debug file CRC, and check all
types of symbols.

This commit also removes the unneccesary intermediate
`bcc_find_symbol_addr`.

Added documentation for usage of the API, updated most call sites to use
default with `NULL`, and fixed some memory leaks at call sites.

7 years agoFix bcc_resolve_symname memory leak on error
Teng Qin [Tue, 9 May 2017 22:25:39 +0000 (15:25 -0700)]
Fix bcc_resolve_symname memory leak on error

`bcc_resolve_symname` should free `sym->module` on error. Also remove
unused `sym_search_t`

7 years agoUse bcc_symbol_option in bcc_foreach_function_symbol
Teng Qin [Thu, 4 May 2017 07:21:20 +0000 (00:21 -0700)]
Use bcc_symbol_option in bcc_foreach_function_symbol

This commit changes `bcc_foreach_symbol` to use the new `bcc_symbol_option` to
control it only wants function symbols. Also renamed it to
bcc_foreach_function_symbol and added comments for better information.

This commit maintained current behavior of the function to prefer use
debug file and check debug file CRC. We could add option to configure
that behavior in the future if needed.

7 years agoAdd option to control bcc_elf_foreach_sym behavior
Teng Qin [Thu, 4 May 2017 07:09:20 +0000 (00:09 -0700)]
Add option to control bcc_elf_foreach_sym behavior

This commit adds a `bcc_symbol_option` to configure various symboling
behaviors. Currently added options for reading debug file, and what type
of symbols are wanted.

This commit also makes bcc_elf_foreach_sym take a `bcc_symbol_option`
parameter and repect the specified configurations.

7 years agoFix usage of CMAKE_BUILD_TYPE setting
Gabor Buella [Fri, 19 May 2017 13:33:08 +0000 (15:33 +0200)]
Fix usage of CMAKE_BUILD_TYPE setting

The build type was set to Release in the top level cmake file.
This was a rather confusing behaviour, as one would expect to
be able to easily debug the code after using `cmake -DCMAKE_BUILD_TYPE=Debug`.

7 years agoMerge pull request #1183 from palmtenor/firstkey
Brenden Blanco [Fri, 19 May 2017 04:40:51 +0000 (21:40 -0700)]
Merge pull request #1183 from palmtenor/firstkey

Use new Kernel functionality to get first key of map

7 years agoUse bpf_get_first_key in Python API
Teng Qin [Tue, 16 May 2017 22:49:22 +0000 (15:49 -0700)]
Use bpf_get_first_key in Python API

7 years agoUse bpf_get_first_key in C++ API
Teng Qin [Tue, 16 May 2017 20:00:48 +0000 (13:00 -0700)]
Use bpf_get_first_key in C++ API

7 years agoAdd bpf_get_first_key helper
Teng Qin [Tue, 16 May 2017 08:10:15 +0000 (01:10 -0700)]
Add bpf_get_first_key helper

This commit adds bpf_get_first_key helper, which gets the first key of
the map. It automatically tries to use the new Kernel functionality and
falls back to old Kernel behavior. This helps us unify the logic to walk
a map across different APIs (Python, C++, etc.)

7 years agoMerge pull request #1189 from iovisor/fix_test_brb
Brenden Blanco [Thu, 18 May 2017 17:59:41 +0000 (10:59 -0700)]
Merge pull request #1189 from iovisor/fix_test_brb

Workaround for possible race in pyroute2.ipdb

7 years agoWorkaround for possible race in pyroute2.ipdb
Brenden Blanco [Thu, 18 May 2017 16:57:42 +0000 (09:57 -0700)]
Workaround for possible race in pyroute2.ipdb

In simulation.py, add a call to initdb() to force-refresh the netlink
socket and the interface list.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agoMerge pull request #1187 from mauriciovasquezbernal/remove_trailing_spaces
4ast [Thu, 18 May 2017 16:00:12 +0000 (09:00 -0700)]
Merge pull request #1187 from mauriciovasquezbernal/remove_trailing_spaces

remove trailing white spaces from source code files

7 years agoremove trailing white spaces from source code files
Mauricio Vasquez B [Thu, 18 May 2017 01:26:47 +0000 (20:26 -0500)]
remove trailing white spaces from source code files

Trailing white spaces cause problems with git.

Signed-off-by: Mauricio Vasquez B <mauricio.vasquez@polito.it>
7 years agoMerge pull request #1180 from iovisor/scanf_string_support
4ast [Wed, 17 May 2017 18:03:03 +0000 (11:03 -0700)]
Merge pull request #1180 from iovisor/scanf_string_support

Enable recursive scanf support for char[] as string

7 years agoAdd sscanf reader/writer code comments
Brenden Blanco [Wed, 17 May 2017 17:37:05 +0000 (10:37 -0700)]
Add sscanf reader/writer code comments

Improve the internal documentation for the reader and writer generated
functions in the case that u8[]=>"" is used.

Change one `+=` to `=`.

Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agoFix bpf_perf_event_read helper signature
Teng Qin [Tue, 16 May 2017 08:13:06 +0000 (01:13 -0700)]
Fix bpf_perf_event_read helper signature

7 years agoEnable recursive scanf support for char[] as string
Brenden Blanco [Tue, 9 May 2017 20:52:42 +0000 (13:52 -0700)]
Enable recursive scanf support for char[] as string

When a bpf table contains i8[] in one of its keys/leaves, use "" to
enclose the value, rather than [ %i %i %i ... ] format. This simplifies
the code that is generated for cases such as #1154, and brings it back
under ~200ms code generation, instead of >30s. This change of format is
not particularly robust (it doesn't handle escaping the doublequote
character itself), but it should make more sense for the common case,
such as tracing files and pathnames.

The test case included tests both the functionality of the format string
handling as well as the compile time, since test_clang already has an
implicit 10second timeout limit.

Fixes: #1154
Signed-off-by: Brenden Blanco <bblanco@gmail.com>
7 years agoMerge pull request #1168 from palmtenor/fixso
Brenden Blanco [Fri, 12 May 2017 00:44:05 +0000 (17:44 -0700)]
Merge pull request #1168 from palmtenor/fixso

Fix bug when finding symbols for shared libraries

7 years agoFix bug when finding symbols for shared libraries
Teng Qin [Wed, 10 May 2017 22:16:42 +0000 (15:16 -0700)]
Fix bug when finding symbols for shared libraries