Commit 416613aa authored by Suchakra Sharma's avatar Suchakra Sharma

Helper to get open k[ret]probes. Fixes #236

parent aa91d3b8
...@@ -708,3 +708,12 @@ class BPF(object): ...@@ -708,3 +708,12 @@ class BPF(object):
return "[unknown]" return "[unknown]"
offset = int(addr - ksym_addrs[idx]) offset = int(addr - ksym_addrs[idx])
return ksym_names[idx] + hex(offset) return ksym_names[idx] + hex(offset)
@staticmethod
def get_open_kprobes():
""" get_open_kprobes()
Get the number of open K[ret]probes. Can be useful for scenarios where
event_re is used while attaching and detaching probes
"""
return len(open_kprobes)
...@@ -32,6 +32,8 @@ add_test(NAME py_test_trace3_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ...@@ -32,6 +32,8 @@ add_test(NAME py_test_trace3_c WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace3_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace3.py test_trace3.c) COMMAND ${TEST_WRAPPER} py_trace3_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace3.py test_trace3.c)
add_test(NAME py_test_trace4 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} add_test(NAME py_test_trace4 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_trace4 sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace4.py) COMMAND ${TEST_WRAPPER} py_trace4 sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_trace4.py)
add_test(NAME py_test_probe_count WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_probe_count sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_probe_count.py)
add_test(NAME py_test_brb WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} add_test(NAME py_test_brb WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TEST_WRAPPER} py_brb_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_brb.py test_brb.c) COMMAND ${TEST_WRAPPER} py_brb_c sudo ${CMAKE_CURRENT_SOURCE_DIR}/test_brb.py test_brb.c)
add_test(NAME py_test_brb2 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} add_test(NAME py_test_brb2 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
......
#!/usr/bin/env python
# Copyright (c) Suchakra Sharma <suchakrapani.sharma@polymtl.ca>
# Licensed under the Apache License, Version 2.0 (the "License")
from bcc import BPF
import os
import sys
from unittest import main, TestCase
class TestKprobeCnt(TestCase):
def setUp(self):
self.b = BPF(text="""
int wololo(void *ctx) {
return 0;
}
""")
self.b.attach_kprobe(event_re="^vfs_.*", fn_name="wololo")
def test_attach1(self):
actual_cnt = 0
with open("/sys/kernel/debug/tracing/available_filter_functions") as f:
for line in f:
if str(line).startswith("vfs_"):
actual_cnt += 1
open_cnt = self.b.get_open_kprobes()
self.assertEqual(actual_cnt, open_cnt)
if __name__ == "__main__":
main()
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