Commit 466de843 authored by Brenden Blanco's avatar Brenden Blanco Committed by GitHub

Merge pull request #1056 from goldshtn/bpflist-enh

bpflist: Add to tests and use Python directory listing
parents 5f3751bf 563af796
...@@ -76,6 +76,9 @@ class SmokeTests(TestCase): ...@@ -76,6 +76,9 @@ class SmokeTests(TestCase):
def test_bitesize(self): def test_bitesize(self):
self.run_with_int("biotop.py") self.run_with_int("biotop.py")
def test_bpflist(self):
self.run_with_duration("bpflist.py")
def test_btrfsdist(self): def test_btrfsdist(self):
# Will attempt to do anything meaningful only when btrfs is installed. # Will attempt to do anything meaningful only when btrfs is installed.
self.run_with_duration("btrfsdist.py 1 1") self.run_with_duration("btrfsdist.py 1 1")
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
from bcc import BPF, USDT from bcc import BPF, USDT
import argparse import argparse
import re import re
import os
import subprocess import subprocess
examples = """examples: examples = """examples:
...@@ -54,16 +55,21 @@ if args.verbosity > 0: ...@@ -54,16 +55,21 @@ if args.verbosity > 0:
parse_probes("kprobe") parse_probes("kprobe")
parse_probes("uprobe") parse_probes("uprobe")
cmd = "ls -l /proc/*/fd/* | grep bpf" def find_bpf_fds(pid):
p = subprocess.Popen(cmd, shell=True, root = '/proc/%d/fd' % pid
stderr=subprocess.PIPE, stdout=subprocess.PIPE) for fd in os.listdir(root):
for line in p.stdout: try:
match = re.search('/proc/(\\d+)/fd/\\d+.*bpf-(\\w+)', line) link = os.readlink(os.path.join(root, fd))
if match is None: except OSError:
continue continue
pid = int(match.group(1)) match = re.match('.*bpf-(\\w+)', link)
t = match.group(2) if match:
counts[(pid, t)] = counts.get((pid, t), 0) + 1 tup = (pid, match.group(1))
counts[tup] = counts.get(tup, 0) + 1
for pdir in os.listdir('/proc'):
if re.match('\\d+', pdir):
find_bpf_fds(int(pdir))
print("%-6s %-16s %-8s %s" % ("PID", "COMM", "TYPE", "COUNT")) print("%-6s %-16s %-8s %s" % ("PID", "COMM", "TYPE", "COUNT"))
for (pid, typ), count in sorted(counts.items(), key=lambda t: t[0][0]): for (pid, typ), count in sorted(counts.items(), key=lambda t: t[0][0]):
......
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