diff options
| author | zy <[email protected]> | 2023-11-20 23:11:51 -0500 |
|---|---|---|
| committer | zy <[email protected]> | 2023-11-20 23:11:51 -0500 |
| commit | 47ef0298843971ddd175a23fa74f64a38989743b (patch) | |
| tree | 3dc00bf70cb1f5095246c7d7fa237e8e7f874951 /source | |
| parent | 8081c2cc828031a3066707c038db589ea6b037a8 (diff) | |
ucli_py
Diffstat (limited to 'source')
| -rw-r--r-- | source/ucli_py/lib.py | 19 | ||||
| -rw-r--r-- | source/ucli_py/ucli.py | 3 |
2 files changed, 16 insertions, 6 deletions
diff --git a/source/ucli_py/lib.py b/source/ucli_py/lib.py index 09008c0..9b7874c 100644 --- a/source/ucli_py/lib.py +++ b/source/ucli_py/lib.py @@ -192,11 +192,11 @@ def diag_printf_proc_chains(proc_chains: proc_chains_detail, detail=1): print(f"#^ 0xffffffffffffff {cmdline} (UNKNOWN)") else: chains_bytes = bytes(proc_chains.chains[i]) - chains_str = chains_bytes.decode(errors="ignore") + chains_str = chains_bytes.decode(errors="ignore").split("\0", 1)[0] print(f"#^ 0xffffffffffffff {chains_str} (UNKNOWN)") else: chains_bytes = bytes(proc_chains.chains[i]) - chains_str = chains_bytes.decode(errors="ignore") + chains_str = chains_bytes.decode(errors="ignore").split("\0", 1)[0] print(f"#^ 0xffffffffffffff {chains_str} (UNKNOWN)") @@ -205,7 +205,16 @@ cmdlines = {} def get_pid_cmdline(pid): if pid not in cmdlines: - with open(f"/proc/{pid}/cmdline", "r") as f: - buf = f.read().replace("\x00", " ").strip() - cmdlines[pid] = buf + try: + with open(f"/proc/{pid}/cmdline", "r") as f: + buf = f.read().replace("\x00", " ").strip() + cmdlines[pid] = buf + except FileNotFoundError: + cmdlines[pid] = "" return cmdlines[pid] + + +def printk_task_brief(detail: task_detail): + print( + f" 进程信息: [{detail.cgroup_buf.decode()} / {detail.comm.decode()}], PID: {detail.tgid} / {detail.pid}" + ) diff --git a/source/ucli_py/ucli.py b/source/ucli_py/ucli.py index c7453b0..bd88f61 100644 --- a/source/ucli_py/ucli.py +++ b/source/ucli_py/ucli.py @@ -226,7 +226,7 @@ def load_monitor_extract(buf, len, _): for i in range(vm_record.threshold_num): print( - f"\t: pid:{vm_record.threshold_record[i].task_id}, name:{vm_record.threshold_record[i].name.decode()}, ptr:{vm_record.threshold_record[i].ptr}, threshold:{vm_record.threshold_record[i].threshold}" + f"\t: pid: {vm_record.threshold_record[i].task_id}, name: {vm_record.threshold_record[i].name.decode()}, ptr: {vm_record.threshold_record[i].ptr}, threshold:{vm_record.threshold_record[i].threshold}" ) elif et_type == 1: @@ -240,6 +240,7 @@ def load_monitor_extract(buf, len, _): ) # 打印 tsk_info # 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) diag_printf_kern_stack(tsk_info.kern_stack) print(f"#* 0xffffffffffffff {tsk_info.task.comm.decode()} (UNKNOWN)") |
