summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorzy <[email protected]>2023-11-26 20:31:44 -0500
committerzy <[email protected]>2023-11-26 20:31:44 -0500
commitd471cc058bee2f75ad0051bb7e23ef18fb77d187 (patch)
tree8d7137b6e4a587bdd97d4e07cc92613691264eef /source
parent6aafc054597cf020df2a37d2d5cb24707a6980f2 (diff)
ucli-py
Diffstat (limited to 'source')
-rw-r--r--source/ucli_py/libunwind/unwind.cc3
-rw-r--r--source/ucli_py/ucli.py57
2 files changed, 44 insertions, 16 deletions
diff --git a/source/ucli_py/libunwind/unwind.cc b/source/ucli_py/libunwind/unwind.cc
index feac03e..6188ad8 100644
--- a/source/ucli_py/libunwind/unwind.cc
+++ b/source/ucli_py/libunwind/unwind.cc
@@ -117,6 +117,8 @@ void diag_printf_raw_stack(int pid, int ns_pid, const char *comm,
entry_cb_arg_t unwind_arg;
static u64 regs_buf[3];
+ printf("##C++ pid %d\n", pid);
+
printf(" 用户态堆栈SP:%lx, BP:%lx, IP:%lx\n", raw_stack->sp,
raw_stack->bp, raw_stack->ip);
stack_sample.user_stack.offset = 0;
@@ -128,4 +130,5 @@ void diag_printf_raw_stack(int pid, int ns_pid, const char *comm,
stack_sample.user_regs.regs[PERF_REG_BP] = raw_stack->bp;
unwind__get_entries(unwind_frame_callback, &unwind_arg, &g_symbol_parser, pid,
ns_pid, &stack_sample);
+ fflush(stdout);
} \ No newline at end of file
diff --git a/source/ucli_py/ucli.py b/source/ucli_py/ucli.py
index 8e42110..c38bbcc 100644
--- a/source/ucli_py/ucli.py
+++ b/source/ucli_py/ucli.py
@@ -211,6 +211,30 @@ def diag_printf_user_stack(pid: int, user_stack: user_stack_detail):
print("#~ 0x%lx UNKNOWN" % (user_stack.stack[i]))
+# 加载 .so 文件
+lib = cdll.LoadLibrary("/root/variable_monitor/source/ucli_py/libunwind/libunwind.so")
+
+# 定义原型等价的ctypes函数
+lib.diag_printf_raw_stack.argtypes = [
+ ctypes.c_int,
+ ctypes.c_int,
+ ctypes.c_char_p,
+ ctypes.POINTER(raw_stack_detail),
+ ctypes.c_int,
+]
+lib.diag_printf_raw_stack.restype = None
+
+
+def diag_printf_raw_stack(task_info: variable_monitor_task):
+ lib.diag_printf_raw_stack(
+ task_info.task.tgid,
+ task_info.task.container_tgid,
+ task_info.task.comm,
+ ctypes.byref(task_info.raw_stack),
+ c_int(1),
+ )
+
+
def load_monitor_extract(buf, len, _):
seq = 0
@@ -241,13 +265,14 @@ def load_monitor_extract(buf, len, _):
f"##CGROUP:[{tsk_info.task.cgroup_buf.decode()}] {tsk_info.task.pid} [{seq:03d}] 采样命中[{'R' if tsk_info.task.state == 0 else 'D'}]"
)
# 打印 tsk_info
- print_structure(tsk_info, struct_name="variable_monitor_task")
- # printk_task_brief(tsk_info.task)
+ # print_structure(tsk_info, struct_name="variable_monitor_task")
+ printk_task_brief(tsk_info.task)
# diag_printf_user_stack(tsk_info.task.pid, tsk_info.user_stack)
- # # for user_stack :18446744073709551615
- # print(f"#* 0xffffffffffffff {tsk_info.task.comm.decode()} (UNKNOWN)")
- # diag_printf_kern_stack(tsk_info.kern_stack)
- # diag_printf_proc_chains(tsk_info.proc_chains)
+ diag_printf_raw_stack(tsk_info)
+ # for user_stack :18446744073709551615
+ print(f"#* 0xffffffffffffff {tsk_info.task.comm.decode()} (UNKNOWN)")
+ diag_printf_kern_stack(tsk_info.kern_stack)
+ diag_printf_proc_chains(tsk_info.proc_chains)
print("##")
@@ -255,16 +280,16 @@ def load_monitor_extract(buf, len, _):
if __name__ == "__main__":
- open_device()
- do_dump(None)
- close_device()
+ # open_device()
+ # do_dump(None)
+ # close_device()
- # with open("buff", "rb") as f:
- # buf_bytes = pickle.load(f)
+ with open("buff", "rb") as f:
+ buf_bytes = pickle.load(f)
- # buf2 = ctypes.create_string_buffer(len(buf_bytes))
- # buf2.raw = buf_bytes
+ buf2 = ctypes.create_string_buffer(len(buf_bytes))
+ buf2.raw = buf_bytes
- # with open("len", "rb") as f:
- # len2 = pickle.load(f)
- # do_extract(buf2, len2.value)
+ with open("len", "rb") as f:
+ len2 = pickle.load(f)
+ do_extract(buf2, len2.value)