Commit efa6ee93 authored by Brendan Gregg's avatar Brendan Gregg

add BPF.tracepoint_exists()

parent e023bc89
......@@ -644,6 +644,11 @@ class BPF(object):
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="")
......
......@@ -28,9 +28,6 @@ from socket import inet_ntop, ntohs, AF_INET, AF_INET6
from struct import pack
import ctypes as ct
from time import strftime
import os
TRACEFS = "/sys/kernel/debug/tracing"
# arguments
examples = """examples:
......@@ -355,7 +352,7 @@ TRACEPOINT_PROBE(tcp, tcp_set_state)
}
"""
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
......
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