This commit is contained in:
zy
2023-11-26 20:31:44 -05:00
parent 6aafc05459
commit d471cc058b
2 changed files with 44 additions and 16 deletions

View File

@@ -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);
}

View File

@@ -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)