Skip to content

Commit

Permalink
add BPF.tracepoint_exists()
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Dec 30, 2017
1 parent e023bc8 commit efa6ee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ def get_tracepoints(tp_re):
results.append(tp)
return results

@staticmethod
def tracepoint_exists(category, event):
evt_dir = os.path.join(TRACEFS, "events", category, event)
return os.path.isdir(evt_dir)

def attach_tracepoint(self, tp="", tp_re="", fn_name=""):
"""attach_tracepoint(tp="", tp_re="", fn_name="")
Expand Down
5 changes: 1 addition & 4 deletions tools/tcplife.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from struct import pack
import ctypes as ct
from time import strftime
import os

TRACEFS = "/sys/kernel/debug/tracing"

# arguments
examples = """examples:
Expand Down Expand Up @@ -355,7 +352,7 @@
}
"""

if (os.path.exists(TRACEFS + "/events/tcp/tcp_set_state")):
if (BPF.tracepoint_exists("tcp", "tcp_set_state")):
bpf_text += bpf_text_tracepoint
else:
bpf_text += bpf_text_kprobe
Expand Down

0 comments on commit efa6ee9

Please sign in to comment.