Unify python executables to use `#!/usr/bin/env python` shebang (#2102)
* fixed shebangs in tools (and lib)
* fixed shebangs in examples
* do not mangle shebangs in rpm spec
* renamed style-check.sh to c-style-check.sh
* factored out python linter to a separate file
* added shebang validation to the py-style-check
* added shebangs to all python executables
diff --git a/.travis.yml b/.travis.yml
index dd36669..9835547 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,5 +3,6 @@
- sudo apt-get install -y python-pip
- sudo pip install pep8
script:
+ - set -euo pipefail
- ./scripts/check-helpers.sh
- - find tools/ -type f -name "*.py" | xargs pep8 -r --show-source --ignore=E123,E125,E126,E127,E128,E302
+ - ./scripts/py-style-check.sh
diff --git a/SPECS/bcc.spec b/SPECS/bcc.spec
index f74bb61..691ab3d 100644
--- a/SPECS/bcc.spec
+++ b/SPECS/bcc.spec
@@ -88,10 +88,6 @@
%install
pushd build
make install/strip DESTDIR=%{buildroot}
-# mangle shebangs
-find %{buildroot}/usr/share/bcc/{tools,examples} -type f -exec \
- sed -i -e '1 s|^#!/usr/bin/python$|#!'%{__python}'|' \
- -e '1 s|^#!/usr/bin/env python$|#!'%{__python}'|' {} \;
%package -n libbcc
Summary: Shared Library for BPF Compiler Collection (BCC)
diff --git a/examples/networking/dns_matching/dns_matching.py b/examples/networking/dns_matching/dns_matching.py
index 943dca5..c8625cd 100755
--- a/examples/networking/dns_matching/dns_matching.py
+++ b/examples/networking/dns_matching/dns_matching.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
from __future__ import print_function
from bcc import BPF
diff --git a/examples/networking/http_filter/http-parse-complete.py b/examples/networking/http_filter/http-parse-complete.py
index f1e5e0a..1218cb2 100644
--- a/examples/networking/http_filter/http-parse-complete.py
+++ b/examples/networking/http_filter/http-parse-complete.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
#Bertrone Matteo - Polytechnic of Turin
#November 2015
diff --git a/examples/networking/http_filter/http-parse-simple.py b/examples/networking/http_filter/http-parse-simple.py
index b702393..1fad0d8 100644
--- a/examples/networking/http_filter/http-parse-simple.py
+++ b/examples/networking/http_filter/http-parse-simple.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
#Bertrone Matteo - Polytechnic of Turin
#November 2015
diff --git a/examples/networking/simple_tc.py b/examples/networking/simple_tc.py
index ec0a3e7..4dd8aa5 100755
--- a/examples/networking/simple_tc.py
+++ b/examples/networking/simple_tc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
diff --git a/examples/networking/vlan_filter/data-plane-tracing.py b/examples/networking/vlan_filter/data-plane-tracing.py
index efaa7f1..975552f 100755
--- a/examples/networking/vlan_filter/data-plane-tracing.py
+++ b/examples/networking/vlan_filter/data-plane-tracing.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
from __future__ import print_function
from bcc import BPF
diff --git a/examples/tracing/bitehist.py b/examples/tracing/bitehist.py
index c8c7f7a..410424b 100755
--- a/examples/tracing/bitehist.py
+++ b/examples/tracing/bitehist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# bitehist.py Block I/O size histogram.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/disksnoop.py b/examples/tracing/disksnoop.py
index ed3dd81..c30ac0a 100755
--- a/examples/tracing/disksnoop.py
+++ b/examples/tracing/disksnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# disksnoop.py Trace block device I/O: basic version of iosnoop.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/mallocstacks.py b/examples/tracing/mallocstacks.py
index 2f3eb25..4820447 100644
--- a/examples/tracing/mallocstacks.py
+++ b/examples/tracing/mallocstacks.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# mallocstacks Trace malloc() calls in a process and print the full
# stack trace for all callsites.
diff --git a/examples/tracing/mysqld_query.py b/examples/tracing/mysqld_query.py
index 15ff297..cf877d1 100755
--- a/examples/tracing/mysqld_query.py
+++ b/examples/tracing/mysqld_query.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# mysqld_query Trace MySQL server queries. Example of USDT tracing.
# For Linux, uses BCC, BPF. Embedded C.
diff --git a/examples/tracing/nodejs_http_server.py b/examples/tracing/nodejs_http_server.py
index 1017de5..367e9d7 100755
--- a/examples/tracing/nodejs_http_server.py
+++ b/examples/tracing/nodejs_http_server.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# nodejs_http_server Basic example of node.js USDT tracing.
# For Linux, uses BCC, BPF. Embedded C.
diff --git a/examples/tracing/stacksnoop.py b/examples/tracing/stacksnoop.py
index bced93f..d16b59d 100755
--- a/examples/tracing/stacksnoop.py
+++ b/examples/tracing/stacksnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# stacksnoop Trace a kernel function and print all kernel stack traces.
# For Linux, uses BCC, eBPF, and currently x86_64 only. Inline C.
diff --git a/examples/tracing/strlen_count.py b/examples/tracing/strlen_count.py
index 49d7080..103464f 100755
--- a/examples/tracing/strlen_count.py
+++ b/examples/tracing/strlen_count.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# strlen_count Trace strlen() and print a frequency count of strings.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/strlen_hist.py b/examples/tracing/strlen_hist.py
index dda1cb2..4652c4a 100755
--- a/examples/tracing/strlen_hist.py
+++ b/examples/tracing/strlen_hist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# strlen_hist.py Histogram of system-wide strlen return values
diff --git a/examples/tracing/strlen_snoop.py b/examples/tracing/strlen_snoop.py
index c3c7199..44be1ac 100755
--- a/examples/tracing/strlen_snoop.py
+++ b/examples/tracing/strlen_snoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# strlen_snoop Trace strlen() library function for a given PID.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/sync_timing.py b/examples/tracing/sync_timing.py
index 675ad14..a00bf5a 100755
--- a/examples/tracing/sync_timing.py
+++ b/examples/tracing/sync_timing.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# sync_timing.py Trace time between syncs.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/task_switch.py b/examples/tracing/task_switch.py
index 161edfb..46d43ba 100755
--- a/examples/tracing/task_switch.py
+++ b/examples/tracing/task_switch.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
diff --git a/examples/tracing/tcpv4connect.py b/examples/tracing/tcpv4connect.py
index 8a89469..5b03717 100755
--- a/examples/tracing/tcpv4connect.py
+++ b/examples/tracing/tcpv4connect.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# tcpv4connect Trace TCP IPv4 connect()s.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/examples/tracing/urandomread-explicit.py b/examples/tracing/urandomread-explicit.py
index 448ffdf..7be545a 100755
--- a/examples/tracing/urandomread-explicit.py
+++ b/examples/tracing/urandomread-explicit.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# urandomread-explicit Example of instrumenting a kernel tracepoint.
# For Linux, uses BCC, BPF. Embedded C.
diff --git a/examples/tracing/urandomread.py b/examples/tracing/urandomread.py
index 319db2c..80ea9de 100755
--- a/examples/tracing/urandomread.py
+++ b/examples/tracing/urandomread.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# urandomread Example of instrumenting a kernel tracepoint.
# For Linux, uses BCC, BPF. Embedded C.
diff --git a/examples/tracing/vfsreadlat.py b/examples/tracing/vfsreadlat.py
index b2c4156..f4daae5 100755
--- a/examples/tracing/vfsreadlat.py
+++ b/examples/tracing/vfsreadlat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# vfsreadlat.py VFS read latency distribution.
# For Linux, uses BCC, eBPF. See .c file.
diff --git a/examples/usdt_sample/scripts/lat_avg.py b/examples/usdt_sample/scripts/lat_avg.py
index be473d1..36c4dbb 100755
--- a/examples/usdt_sample/scripts/lat_avg.py
+++ b/examples/usdt_sample/scripts/lat_avg.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
import argparse
from time import sleep, strftime
from sys import argv
diff --git a/examples/usdt_sample/scripts/lat_dist.py b/examples/usdt_sample/scripts/lat_dist.py
index af13e89..647f295 100755
--- a/examples/usdt_sample/scripts/lat_dist.py
+++ b/examples/usdt_sample/scripts/lat_dist.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
import argparse
from time import sleep, strftime
from sys import argv
diff --git a/examples/usdt_sample/scripts/latency.py b/examples/usdt_sample/scripts/latency.py
index 4170592..d46f2ef 100755
--- a/examples/usdt_sample/scripts/latency.py
+++ b/examples/usdt_sample/scripts/latency.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
import argparse
from time import sleep
from sys import argv
diff --git a/scripts/style-check.sh b/scripts/c-style-check.sh
similarity index 100%
rename from scripts/style-check.sh
rename to scripts/c-style-check.sh
diff --git a/scripts/py-style-check.sh b/scripts/py-style-check.sh
new file mode 100755
index 0000000..d8c5ece
--- /dev/null
+++ b/scripts/py-style-check.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -euo pipefail
+
+# TODO: stop ignoring this. Maybe autopep8 existing stuff?
+find tools -type f -name "*.py" | xargs pep8 -r --show-source --ignore=E123,E125,E126,E127,E128,E302 || \
+ echo "pep8 run failed, please fix it" >&2
+
+NO_PROPER_SHEBANG="$(find tools examples -type f -executable -name '*.py' | xargs grep -L '#!/usr/bin/env python')"
+if [ -n "$NO_PROPER_SHEBANG" ]; then
+ echo "bad shebangs found:"
+ echo "$NO_PROPER_SHEBANG"
+ echo
+ echo "either add proper shebang or remove executable bit" >&2
+
+ exit 1
+fi
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 86abec9..11960a7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -4,7 +4,7 @@
set(TEST_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh)
-add_test(NAME style-check COMMAND ${CMAKE_SOURCE_DIR}/scripts/style-check.sh)
+add_test(NAME style-check COMMAND ${CMAKE_SOURCE_DIR}/scripts/c-style-check.sh)
set_tests_properties(style-check PROPERTIES PASS_REGULAR_EXPRESSION ".*")
if(ENABLE_CLANG_JIT)
diff --git a/tools/bashreadline.py b/tools/bashreadline.py
index da9c1b7..3d74c93 100755
--- a/tools/bashreadline.py
+++ b/tools/bashreadline.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# bashreadline Print entered bash commands from all running shells.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/tools/biolatency.py b/tools/biolatency.py
index 68aa577..0c6b6bc 100755
--- a/tools/biolatency.py
+++ b/tools/biolatency.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# biolatency Summarize block device I/O latency as a histogram.
diff --git a/tools/biosnoop.py b/tools/biosnoop.py
index 259a81b..51b3a7f 100755
--- a/tools/biosnoop.py
+++ b/tools/biosnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# biosnoop Trace block device I/O and print details including issuing PID.
diff --git a/tools/biotop.py b/tools/biotop.py
index b2b5089..2aab1fc 100755
--- a/tools/biotop.py
+++ b/tools/biotop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# biotop block device (disk) I/O by process.
diff --git a/tools/bitesize.py b/tools/bitesize.py
index f70f091..e57185d 100755
--- a/tools/bitesize.py
+++ b/tools/bitesize.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# bitehist.py Block I/O size histogram.
# For Linux, uses BCC, eBPF. See .c file.
diff --git a/tools/bpflist.py b/tools/bpflist.py
index f73e945..85220b6 100755
--- a/tools/bpflist.py
+++ b/tools/bpflist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# bpflist Display processes currently using BPF programs and maps,
# pinned BPF programs and maps, and enabled probes.
diff --git a/tools/btrfsdist.py b/tools/btrfsdist.py
index 4659ab4..a0aeb24 100755
--- a/tools/btrfsdist.py
+++ b/tools/btrfsdist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# btrfsdist Summarize btrfs operation latency.
diff --git a/tools/btrfsslower.py b/tools/btrfsslower.py
index 0a59820..cff61b8 100755
--- a/tools/btrfsslower.py
+++ b/tools/btrfsslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# btrfsslower Trace slow btrfs operations.
diff --git a/tools/cachestat.py b/tools/cachestat.py
index b00c804..90a55b0 100755
--- a/tools/cachestat.py
+++ b/tools/cachestat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# cachestat Count cache kernel function calls.
# For Linux, uses BCC, eBPF. See .c file.
diff --git a/tools/capable.py b/tools/capable.py
index 65ffa77..368f4b0 100755
--- a/tools/capable.py
+++ b/tools/capable.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# capable Trace security capabilitiy checks (cap_capable()).
diff --git a/tools/cpudist.py b/tools/cpudist.py
index 4d7c9eb..9e61341 100755
--- a/tools/cpudist.py
+++ b/tools/cpudist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# cpudist Summarize on- and off-CPU time per task as a histogram.
diff --git a/tools/cpuunclaimed.py b/tools/cpuunclaimed.py
index b862bad..c899398 100755
--- a/tools/cpuunclaimed.py
+++ b/tools/cpuunclaimed.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# cpuunclaimed Sample CPU run queues and calculate unclaimed idle CPU.
diff --git a/tools/criticalstat.py b/tools/criticalstat.py
index 68c16f7..38c318d 100755
--- a/tools/criticalstat.py
+++ b/tools/criticalstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# criticalstat Trace long critical sections (IRQs or preemption disabled)
diff --git a/tools/dbslower.py b/tools/dbslower.py
index 24e6394..a42df87 100755
--- a/tools/dbslower.py
+++ b/tools/dbslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# dbslower Trace MySQL and PostgreSQL queries slower than a threshold.
#
diff --git a/tools/dbstat.py b/tools/dbstat.py
index a89b097..1d98436 100755
--- a/tools/dbstat.py
+++ b/tools/dbstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# dbstat Display a histogram of MySQL and PostgreSQL query latencies.
#
diff --git a/tools/dcsnoop.py b/tools/dcsnoop.py
index 4c37571..1452191 100755
--- a/tools/dcsnoop.py
+++ b/tools/dcsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# dcsnoop Trace directory entry cache (dcache) lookups.
diff --git a/tools/dcstat.py b/tools/dcstat.py
index 5ecddd1..2009a19 100755
--- a/tools/dcstat.py
+++ b/tools/dcstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# dcstat Directory entry cache (dcache) stats.
diff --git a/tools/execsnoop.py b/tools/execsnoop.py
index 0c2c065..e27e50e 100755
--- a/tools/execsnoop.py
+++ b/tools/execsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# execsnoop Trace new processes via exec() syscalls.
diff --git a/tools/ext4dist.py b/tools/ext4dist.py
index bc797fb..b71cfda 100755
--- a/tools/ext4dist.py
+++ b/tools/ext4dist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ext4dist Summarize ext4 operation latency.
diff --git a/tools/ext4slower.py b/tools/ext4slower.py
index 16b56ec..344e68f 100755
--- a/tools/ext4slower.py
+++ b/tools/ext4slower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ext4slower Trace slow ext4 operations.
diff --git a/tools/filelife.py b/tools/filelife.py
index f66f00b..4095273 100755
--- a/tools/filelife.py
+++ b/tools/filelife.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# filelife Trace the lifespan of short-lived files.
diff --git a/tools/fileslower.py b/tools/fileslower.py
index ce7132a..0515242 100755
--- a/tools/fileslower.py
+++ b/tools/fileslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# fileslower Trace slow synchronous file reads and writes.
diff --git a/tools/filetop.py b/tools/filetop.py
index 4c7a28a..e9f67a2 100755
--- a/tools/filetop.py
+++ b/tools/filetop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# filetop file reads and writes by process.
diff --git a/tools/funccount.py b/tools/funccount.py
index 69dd01c..fcb96b8 100755
--- a/tools/funccount.py
+++ b/tools/funccount.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# funccount Count functions, tracepoints, and USDT probes.
diff --git a/tools/funclatency.py b/tools/funclatency.py
index 3f08a7e..f23d8f0 100755
--- a/tools/funclatency.py
+++ b/tools/funclatency.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# funclatency Time functions and print latency as a histogram.
diff --git a/tools/funcslower.py b/tools/funcslower.py
index 283c801..2143583 100755
--- a/tools/funcslower.py
+++ b/tools/funcslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# funcslower Trace slow kernel or user function calls.
diff --git a/tools/gethostlatency.py b/tools/gethostlatency.py
index 8d07e23..84c7988 100755
--- a/tools/gethostlatency.py
+++ b/tools/gethostlatency.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# gethostlatency Show latency for getaddrinfo/gethostbyname[2] calls.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/tools/hardirqs.py b/tools/hardirqs.py
index 589a890..1f5983a 100755
--- a/tools/hardirqs.py
+++ b/tools/hardirqs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# hardirqs Summarize hard IRQ (interrupt) event time.
diff --git a/tools/killsnoop.py b/tools/killsnoop.py
index 16221a2..ce03d37 100755
--- a/tools/killsnoop.py
+++ b/tools/killsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# killsnoop Trace signals issued by the kill() syscall.
diff --git a/tools/lib/ucalls.py b/tools/lib/ucalls.py
index 352e4d7..3b90b91 100755
--- a/tools/lib/ucalls.py
+++ b/tools/lib/ucalls.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ucalls Summarize method calls in high-level languages and/or system calls.
diff --git a/tools/lib/uflow.py b/tools/lib/uflow.py
index 63fab87..2bfe36b 100755
--- a/tools/lib/uflow.py
+++ b/tools/lib/uflow.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# uflow Trace method execution flow in high-level languages.
diff --git a/tools/lib/ugc.py b/tools/lib/ugc.py
index 8841d5f..77f125e 100755
--- a/tools/lib/ugc.py
+++ b/tools/lib/ugc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ugc Summarize garbage collection events in high-level languages.
diff --git a/tools/lib/uobjnew.py b/tools/lib/uobjnew.py
index 85f5768..8159f9a 100755
--- a/tools/lib/uobjnew.py
+++ b/tools/lib/uobjnew.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# uobjnew Summarize object allocations in high-level languages.
diff --git a/tools/lib/ustat.py b/tools/lib/ustat.py
index 1edc985..ef29d76 100755
--- a/tools/lib/ustat.py
+++ b/tools/lib/ustat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ustat Activity stats from high-level languages, including exceptions,
diff --git a/tools/lib/uthreads.py b/tools/lib/uthreads.py
index 90d0a74..00dd68b 100755
--- a/tools/lib/uthreads.py
+++ b/tools/lib/uthreads.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# uthreads Trace thread creation/destruction events in high-level languages.
diff --git a/tools/llcstat.py b/tools/llcstat.py
index ec2c1f8..b491543 100755
--- a/tools/llcstat.py
+++ b/tools/llcstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# llcstat.py Summarize cache references and cache misses by PID.
# Cache reference and cache miss are corresponding events defined in
diff --git a/tools/mdflush.py b/tools/mdflush.py
index 485635d..507614b 100755
--- a/tools/mdflush.py
+++ b/tools/mdflush.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# mdflush Trace md flush events.
diff --git a/tools/mysqld_qslower.py b/tools/mysqld_qslower.py
index ab23b5b..5737d18 100755
--- a/tools/mysqld_qslower.py
+++ b/tools/mysqld_qslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# mysqld_qslower MySQL server queries slower than a threshold.
# For Linux, uses BCC, BPF. Embedded C.
diff --git a/tools/nfsdist.py b/tools/nfsdist.py
index ff78506..e3317a4 100755
--- a/tools/nfsdist.py
+++ b/tools/nfsdist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# nfsdist Summarize NFS operation latency
diff --git a/tools/nfsslower.py b/tools/nfsslower.py
index 32e91c7..8113eff 100755
--- a/tools/nfsslower.py
+++ b/tools/nfsslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# nfsslower Trace slow NFS operations
diff --git a/tools/offcputime.py b/tools/offcputime.py
index d84ae52..6440260 100755
--- a/tools/offcputime.py
+++ b/tools/offcputime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# offcputime Summarize off-CPU time by stack trace
# For Linux, uses BCC, eBPF.
diff --git a/tools/offwaketime.py b/tools/offwaketime.py
index 38a9ff2..3c4f0f3 100755
--- a/tools/offwaketime.py
+++ b/tools/offwaketime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# offwaketime Summarize blocked time by kernel off-CPU stack + waker stack
# For Linux, uses BCC, eBPF.
diff --git a/tools/old/bashreadline.py b/tools/old/bashreadline.py
index 571b662..c4b8ec2 100755
--- a/tools/old/bashreadline.py
+++ b/tools/old/bashreadline.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# bashreadline Print entered bash commands from all running shells.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/tools/old/biosnoop.py b/tools/old/biosnoop.py
index 37ee3f9..96db56b 100755
--- a/tools/old/biosnoop.py
+++ b/tools/old/biosnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# biosnoop Trace block device I/O and print details including issuing PID.
diff --git a/tools/old/filelife.py b/tools/old/filelife.py
index 075be08..af64b53 100755
--- a/tools/old/filelife.py
+++ b/tools/old/filelife.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# filelife Trace the lifespan of short-lived files.
diff --git a/tools/old/gethostlatency.py b/tools/old/gethostlatency.py
index 7d32cb8..4d87c83 100755
--- a/tools/old/gethostlatency.py
+++ b/tools/old/gethostlatency.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# gethostlatency Show latency for getaddrinfo/gethostbyname[2] calls.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/tools/old/killsnoop.py b/tools/old/killsnoop.py
index ddf9d5a..e2d4cb5 100755
--- a/tools/old/killsnoop.py
+++ b/tools/old/killsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# killsnoop Trace signals issued by the kill() syscall.
diff --git a/tools/old/offcputime.py b/tools/old/offcputime.py
index 38d12a2..dc89063 100755
--- a/tools/old/offcputime.py
+++ b/tools/old/offcputime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# offcputime Summarize off-CPU time by kernel stack trace
# For Linux, uses BCC, eBPF.
diff --git a/tools/old/offwaketime.py b/tools/old/offwaketime.py
index 3b5bb36..b5fdd0f 100755
--- a/tools/old/offwaketime.py
+++ b/tools/old/offwaketime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# offwaketime Summarize blocked time by kernel off-CPU stack + waker stack
# For Linux, uses BCC, eBPF.
diff --git a/tools/old/opensnoop.py b/tools/old/opensnoop.py
index 5df3b41..3736ec2 100755
--- a/tools/old/opensnoop.py
+++ b/tools/old/opensnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# opensnoop Trace open() syscalls.
diff --git a/tools/old/profile.py b/tools/old/profile.py
index e308208..f0328d2 100755
--- a/tools/old/profile.py
+++ b/tools/old/profile.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# profile Profile CPU usage by sampling stack traces at a timed interval.
diff --git a/tools/old/softirqs.py b/tools/old/softirqs.py
index 3b40b1a..30495bc 100755
--- a/tools/old/softirqs.py
+++ b/tools/old/softirqs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# softirqs Summarize soft IRQ (interrupt) event time.
diff --git a/tools/old/stackcount.py b/tools/old/stackcount.py
index 108c800..6eee27f 100755
--- a/tools/old/stackcount.py
+++ b/tools/old/stackcount.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# stackcount Count kernel function calls and their stack traces.
# For Linux, uses BCC, eBPF.
diff --git a/tools/old/stacksnoop.py b/tools/old/stacksnoop.py
index 9fcc12b..238ab82 100755
--- a/tools/old/stacksnoop.py
+++ b/tools/old/stacksnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# stacksnoop Trace a kernel function and print all kernel stack traces.
# For Linux, uses BCC, eBPF, and currently x86_64 only. Inline C.
diff --git a/tools/old/statsnoop.py b/tools/old/statsnoop.py
index ad54ac7..82128c2 100755
--- a/tools/old/statsnoop.py
+++ b/tools/old/statsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# statsnoop Trace stat() syscalls.
diff --git a/tools/old/syncsnoop.py b/tools/old/syncsnoop.py
index cae57ea..b14309d 100755
--- a/tools/old/syncsnoop.py
+++ b/tools/old/syncsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# syncsnoop Trace sync() syscall.
diff --git a/tools/old/tcpaccept.py b/tools/old/tcpaccept.py
index 8125eaa..cc0c240 100755
--- a/tools/old/tcpaccept.py
+++ b/tools/old/tcpaccept.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpaccept Trace TCP accept()s.
diff --git a/tools/old/tcpconnect.py b/tools/old/tcpconnect.py
index 579a85f..e0a59e9 100755
--- a/tools/old/tcpconnect.py
+++ b/tools/old/tcpconnect.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpconnect Trace TCP connect()s.
diff --git a/tools/old/wakeuptime.py b/tools/old/wakeuptime.py
index 783c7ff..512e4f4 100644
--- a/tools/old/wakeuptime.py
+++ b/tools/old/wakeuptime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# wakeuptime Summarize sleep to wakeup time by waker kernel stack
# For Linux, uses BCC, eBPF.
diff --git a/tools/opensnoop.py b/tools/opensnoop.py
index 2a00737..1a68f69 100755
--- a/tools/opensnoop.py
+++ b/tools/opensnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# opensnoop Trace open() syscalls.
diff --git a/tools/pidpersec.py b/tools/pidpersec.py
index c449004..aff1219 100755
--- a/tools/pidpersec.py
+++ b/tools/pidpersec.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# pidpersec Count new processes (via fork).
diff --git a/tools/profile.py b/tools/profile.py
index d1d3d26..084ac63 100755
--- a/tools/profile.py
+++ b/tools/profile.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# profile Profile CPU usage by sampling stack traces at a timed interval.
diff --git a/tools/runqlat.py b/tools/runqlat.py
index 9fd4064..9c56d22 100755
--- a/tools/runqlat.py
+++ b/tools/runqlat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# runqlat Run queue (scheduler) latency as a histogram.
diff --git a/tools/runqlen.py b/tools/runqlen.py
index b56a591..4ff515d 100755
--- a/tools/runqlen.py
+++ b/tools/runqlen.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# runqlen Summarize scheduler run queue length as a histogram.
diff --git a/tools/runqslower.py b/tools/runqslower.py
index 7af12e5..da8d486 100755
--- a/tools/runqslower.py
+++ b/tools/runqslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# runqslower Trace long process scheduling delays.
diff --git a/tools/shmsnoop.py b/tools/shmsnoop.py
index ef99064..db42967 100755
--- a/tools/shmsnoop.py
+++ b/tools/shmsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# shmsnoop Trace shm*() syscalls.
diff --git a/tools/slabratetop.py b/tools/slabratetop.py
index 101c585..ab6c08c 100755
--- a/tools/slabratetop.py
+++ b/tools/slabratetop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# slabratetop Summarize kmem_cache_alloc() calls.
diff --git a/tools/sofdsnoop.py b/tools/sofdsnoop.py
index d6e131e..8256481 100755
--- a/tools/sofdsnoop.py
+++ b/tools/sofdsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# sofdsnoop traces file descriptors passed via socket
diff --git a/tools/softirqs.py b/tools/softirqs.py
index 1e2daf5..10ebc38 100755
--- a/tools/softirqs.py
+++ b/tools/softirqs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# softirqs Summarize soft IRQ (interrupt) event time.
diff --git a/tools/sslsniff.py b/tools/sslsniff.py
index 265e87f..f7bc117 100755
--- a/tools/sslsniff.py
+++ b/tools/sslsniff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# sslsniff Captures data on read/recv or write/send functions of OpenSSL,
# GnuTLS and NSS
diff --git a/tools/statsnoop.py b/tools/statsnoop.py
index 516eda2..9e585be 100755
--- a/tools/statsnoop.py
+++ b/tools/statsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# statsnoop Trace stat() syscalls.
diff --git a/tools/syncsnoop.py b/tools/syncsnoop.py
index 708fbc4..eb892ba 100755
--- a/tools/syncsnoop.py
+++ b/tools/syncsnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# syncsnoop Trace sync() syscall.
diff --git a/tools/tcpaccept.py b/tools/tcpaccept.py
index e278075..d8ef4eb 100755
--- a/tools/tcpaccept.py
+++ b/tools/tcpaccept.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpaccept Trace TCP accept()s.
diff --git a/tools/tcpconnect.py b/tools/tcpconnect.py
index 13c987b..e1f4461 100755
--- a/tools/tcpconnect.py
+++ b/tools/tcpconnect.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpconnect Trace TCP connect()s.
diff --git a/tools/tcpconnlat.py b/tools/tcpconnlat.py
index 9f25f0f..92dc2c1 100755
--- a/tools/tcpconnlat.py
+++ b/tools/tcpconnlat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpconnlat Trace TCP active connection latency (connect).
diff --git a/tools/tcpdrop.py b/tools/tcpdrop.py
index ca89be6..82f66a7 100755
--- a/tools/tcpdrop.py
+++ b/tools/tcpdrop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpdrop Trace TCP kernel-dropped packets/segments.
diff --git a/tools/tcplife.py b/tools/tcplife.py
index 4639582..e7d29d4 100755
--- a/tools/tcplife.py
+++ b/tools/tcplife.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcplife Trace the lifespan of TCP sessions and summarize.
diff --git a/tools/tcpretrans.py b/tools/tcpretrans.py
index 47ac8c1..442fd3e 100755
--- a/tools/tcpretrans.py
+++ b/tools/tcpretrans.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpretrans Trace or count TCP retransmits and TLPs.
diff --git a/tools/tcpstates.py b/tools/tcpstates.py
index 4a21f02..736de97 100755
--- a/tools/tcpstates.py
+++ b/tools/tcpstates.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @lint-avoid-python-3-compatibility-imports
#
diff --git a/tools/tcpsubnet.py b/tools/tcpsubnet.py
index 5f2a806..bf944e1 100755
--- a/tools/tcpsubnet.py
+++ b/tools/tcpsubnet.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcpsubnet Summarize TCP bytes sent to different subnets.
diff --git a/tools/tcptop.py b/tools/tcptop.py
index e1eb241..a8451d2 100755
--- a/tools/tcptop.py
+++ b/tools/tcptop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# tcptop Summarize TCP send/recv throughput by host.
diff --git a/tools/tcptracer.py b/tools/tcptracer.py
index cc92c3f..8f272eb 100755
--- a/tools/tcptracer.py
+++ b/tools/tcptracer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# tcpv4tracer Trace TCP connections.
# For Linux, uses BCC, eBPF. Embedded C.
diff --git a/tools/ttysnoop.py b/tools/ttysnoop.py
index 07f272f..aa18d24 100755
--- a/tools/ttysnoop.py
+++ b/tools/ttysnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# ttysnoop Watch live output from a tty or pts device.
diff --git a/tools/vfscount.py b/tools/vfscount.py
index 10c6b1e..285cd8b 100755
--- a/tools/vfscount.py
+++ b/tools/vfscount.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# vfscount Count VFS calls ("vfs_*").
diff --git a/tools/vfsstat.py b/tools/vfsstat.py
index 1764c60..4a55f8c 100755
--- a/tools/vfsstat.py
+++ b/tools/vfsstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# vfsstat Count some VFS calls.
diff --git a/tools/wakeuptime.py b/tools/wakeuptime.py
index 18e70e4..68e8857 100755
--- a/tools/wakeuptime.py
+++ b/tools/wakeuptime.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# wakeuptime Summarize sleep to wakeup time by waker kernel stack
# For Linux, uses BCC, eBPF.
diff --git a/tools/xfsdist.py b/tools/xfsdist.py
index f409f90..1a7fdd9 100755
--- a/tools/xfsdist.py
+++ b/tools/xfsdist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# xfsdist Summarize XFS operation latency.
diff --git a/tools/xfsslower.py b/tools/xfsslower.py
index b79527b..5b4e0a2 100755
--- a/tools/xfsslower.py
+++ b/tools/xfsslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# xfsslower Trace slow XFS operations.
diff --git a/tools/zfsdist.py b/tools/zfsdist.py
index 6b29b99..9330739 100755
--- a/tools/zfsdist.py
+++ b/tools/zfsdist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# zfsdist Summarize ZFS operation latency.
diff --git a/tools/zfsslower.py b/tools/zfsslower.py
index 7bf160b..6f0382a 100755
--- a/tools/zfsslower.py
+++ b/tools/zfsslower.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# zfsslower Trace slow ZFS operations.