Commit e7dff43a authored by Kenny Yu's avatar Kenny Yu

Address comments from https://github.com/iovisor/bcc/pull/936

- Remove dependency on networkx. I did this by copying only the parts I needed
  from networkx, and adapting it to only use what I needed. These include:
  `DiGraph`, `strongly_connected_components`, `simple_cyles`

- Symbolize global and static mutexes. In order to do this, I subshell out to
  `subshell`. This isn't very efficient, but this only happens at the end of
  the program if a deadlock is found, so it's not too bad.

- `--verbose` mode to print graph statistics

- Make `--binary` flag optional. Not needed by default, However, this is needed
  on kernels without this recent kernel patch
  (https://lkml.org/lkml/2017/1/13/585, submitted 2 weeks ago): we can't attach
  a uprobe on a binary that has `:` in the path name. Instead, we can create a
  symlink without `:` in the path and pass that to the `--binary` argument
  instead.
parent 66fb4d29
Q: while running 'make test' I'm seeing: Q: while running 'make test' I'm seeing:
'ImportError: No module named pyroute2' or 'ImportError: No module named networkx' 'ImportError: No module named pyroute2'
A: Install pyroute2 and networkx: A: Install pyroute2:
git clone https://github.com/svinota/pyroute2.git git clone https://github.com/svinota/pyroute2.git
cd pyroute2; sudo make install cd pyroute2; sudo make install
git clone https://github.com/networkx/networkx.git
cd networkx; sudo make install
Q: hello_world.py fails with: Q: hello_world.py fails with:
OSError: libbcc.so: cannot open shared object file: No such file or directory OSError: libbcc.so: cannot open shared object file: No such file or directory
......
...@@ -99,13 +99,6 @@ cd pyroute2; sudo make install ...@@ -99,13 +99,6 @@ cd pyroute2; sudo make install
sudo python /usr/share/bcc/examples/simple_tc.py sudo python /usr/share/bcc/examples/simple_tc.py
``` ```
(Optional) Install networkx for additional deadlock detector features
```bash
git@github.com:networkx/networkx.git
cd networkx; sudo make install
sudo python /usr/share/bcc/tools/deadlock_detector.py
```
## Fedora - Binary ## Fedora - Binary
Install a 4.2+ kernel from Install a 4.2+ kernel from
...@@ -207,7 +200,6 @@ sudo dnf install -y luajit luajit-devel # for Lua support ...@@ -207,7 +200,6 @@ sudo dnf install -y luajit luajit-devel # for Lua support
sudo dnf install -y \ sudo dnf install -y \
http://pkgs.repoforge.org/netperf/netperf-2.6.0-1.el6.rf.x86_64.rpm http://pkgs.repoforge.org/netperf/netperf-2.6.0-1.el6.rf.x86_64.rpm
sudo pip install pyroute2 sudo pip install pyroute2
sudo pip install networkx
``` ```
### Install binary clang ### Install binary clang
......
...@@ -3,7 +3,7 @@ Maintainer: Brenden Blanco <bblanco@plumgrid.com> ...@@ -3,7 +3,7 @@ Maintainer: Brenden Blanco <bblanco@plumgrid.com>
Section: misc Section: misc
Priority: optional Priority: optional
Standards-Version: 3.9.5 Standards-Version: 3.9.5
Build-Depends: debhelper (>= 9), cmake, libllvm3.7 | libllvm3.8, llvm-3.7-dev | llvm-3.8-dev, libclang-3.7-dev | libclang-3.8-dev, libelf-dev, bison, flex, libedit-dev, clang-format | clang-format-3.7, python-netaddr, python-networkx, python-pyroute2, luajit, libluajit-5.1-dev Build-Depends: debhelper (>= 9), cmake, libllvm3.7 | libllvm3.8, llvm-3.7-dev | llvm-3.8-dev, libclang-3.7-dev | libclang-3.8-dev, libelf-dev, bison, flex, libedit-dev, clang-format | clang-format-3.7, python-netaddr, python-pyroute2, luajit, libluajit-5.1-dev
Homepage: https://github.com/iovisor/bcc Homepage: https://github.com/iovisor/bcc
Package: libbcc Package: libbcc
......
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
deadlock_detector \- Find potential deadlocks (lock order inversions) deadlock_detector \- Find potential deadlocks (lock order inversions)
in a running program. in a running program.
.SH SYNOPSIS .SH SYNOPSIS
.B deadlock_detector [\-h] [\--dump-graph FILE] .B deadlock_detector [\-h] [\--binary BINARY] [\--dump-graph DUMP_GRAPH]
[\--lock-symbols LOCK_SYMBOLS] [\--unlock-symbols UNLOCK_SYMBOLS] binary pid .B [\--verbose] [\--lock-symbols LOCK_SYMBOLS]
.B [\--unlock-symbols UNLOCK_SYMBOLS]
.B pid
.SH DESCRIPTION .SH DESCRIPTION
deadlock_detector detects potential deadlocks on a running process. The program deadlock_detector finds potential deadlocks in a running process. The program
attaches uprobes on `pthread_mutex_lock` and `pthread_mutex_unlock` by default attaches uprobes on `pthread_mutex_lock` and `pthread_mutex_unlock` by default
to build a mutex wait directed graph, and then looks for a cycle in this graph. to build a mutex wait directed graph, and then looks for a cycle in this graph.
This graph has the following properties: This graph has the following properties:
...@@ -29,38 +31,56 @@ This tool does not work for shared mutexes or recursive mutexes. ...@@ -29,38 +31,56 @@ This tool does not work for shared mutexes or recursive mutexes.
Since this uses BPF, only the root user can use this tool. Since this uses BPF, only the root user can use this tool.
.SH REQUIREMENTS .SH REQUIREMENTS
CONFIG_BPF, bcc, and networkx CONFIG_BPF and bcc
.SH OPTIONS .SH OPTIONS
.TP .TP
\-h, --help
show this help message and exit
.TP
\--binary BINARY
If set, use this as the path to the binary for the process.
.TP
\--dump-graph DUMP_GRAPH \--dump-graph DUMP_GRAPH
If set, this will dump the mutex graph to the specified file. If set, this will dump the mutex graph to the specified file.
.TP .TP
\--verbose
Print statistics about the mutex wait graph.
.TP
\--lock-symbols LOCK_SYMBOLS \--lock-symbols LOCK_SYMBOLS
Comma-separated list of lock symbols to trace. Default is pthread_mutex_lock Comma-separated list of lock symbols to trace. Default is pthread_mutex_lock
.TP .TP
\--unlock-symbols UNLOCK_SYMBOLS \--unlock-symbols UNLOCK_SYMBOLS
Comma-separated list of unlock symbols to trace. Default is pthread_mutex_unlock Comma-separated list of unlock symbols to trace. Default is pthread_mutex_unlock
.TP .TP
binary
Absolute path to binary
.TP
pid pid
Pid to trace Pid to trace
.SH EXAMPLES .SH EXAMPLES
.TP .TP
Find potential deadlocks in a process: Find potential deadlocks in a process:
# #
.B deadlock_detector /path/to/binary $(pidof binary) .B deadlock_detector $(pidof binary)
.TP .TP
Find potential deadlocks in a process and dump the mutex wait graph to a file: Find potential deadlocks in a process and dump the mutex wait graph to a file:
# #
.B deadlock_detector /path/to/binary $(pidof binary) --dump-graph graph.json .B deadlock_detector $(pidof binary) --dump-graph graph.json
.TP
Find potential deadlocks in a process and print mutex wait graph statistics:
#
.B deadlock_detector $(pidof binary) --verbose
.TP .TP
Find potential deadlocks in a process with custom mutexes: Find potential deadlocks in a process with custom mutexes:
# #
.B deadlock_detector /path/to/binary $(pidof binary) .B deadlock_detector $(pidof binary)
--lock-symbols custom_mutex1_lock,custom_mutex2_lock .B --lock-symbols custom_mutex1_lock,custom_mutex2_lock
--unlock_symbols custom_mutex1_unlock,custom_mutex2_unlock .B --unlock_symbols custom_mutex1_unlock,custom_mutex2_unlock
.TP
Find potential deadlocks in a process, and provide the path to the binary. On \
older kernels without https://lkml.org/lkml/2017/1/13/585, binaries that \
contain `:` in the path cannot be attached with uprobes. As a workaround, we \
can create a symlink to the binary, and provide the symlink name instead with \
the `--binary` option:
#
.B deadlock_detector $(pidof binary) --binary /path/to/program
.SH OUTPUT .SH OUTPUT
This program does not output any fields. Rather, it will keep running until This program does not output any fields. Rather, it will keep running until
it finds a potential deadlock, or the user hits Ctrl-C. If the program finds it finds a potential deadlock, or the user hits Ctrl-C. If the program finds
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment