ucli adjust
This commit is contained in:
@@ -71,12 +71,14 @@ long diag_call_ioctl(unsigned long request, unsigned long arg) {
|
||||
|
||||
fd = open(DEVICE, O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
printf("open %s error!\n", DEVICE);
|
||||
fd = open(DEVICE_BAK, O_RDWR, 0);
|
||||
if (fd < 0){
|
||||
printf("open %s error!\n", DEVICE_BAK);
|
||||
return EEXIST;
|
||||
}
|
||||
printf("open %s error,try to open %s\n", DEVICE, DEVICE_BAK);
|
||||
fd = open(DEVICE_BAK, O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
printf("open %s error!\n", DEVICE_BAK);
|
||||
return EEXIST;
|
||||
} else {
|
||||
printf("open %s success!\n", DEVICE_BAK);
|
||||
}
|
||||
}
|
||||
|
||||
ret = ioctl(fd, request, arg);
|
||||
@@ -168,9 +170,92 @@ void diag_printf_raw_stack(int pid, int ns_pid, const char *comm,
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
// 根据 sys_task 取值返回对应的字符串
|
||||
static const char *sys_task_str(int sys_task) {
|
||||
switch (sys_task) {
|
||||
case 0:
|
||||
return "USER TASK";
|
||||
case 1:
|
||||
return "SYSTEM TASK";
|
||||
case 2:
|
||||
return "IDLE TASK";
|
||||
default:
|
||||
return "UNKNOWN TASK";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *user_mode_str(int user_mode) {
|
||||
switch (user_mode) {
|
||||
case 1:
|
||||
return "USER MODE";
|
||||
case 0:
|
||||
return "SYSTEM MODE";
|
||||
default:
|
||||
return "UNKNOWN MODE";
|
||||
}
|
||||
}
|
||||
|
||||
// 判断 __state 具体是下面哪种状态.输出: 单个状态 | 组合状态
|
||||
// #define TASK_RUNNING 0x0000 // 正在运行
|
||||
// #define TASK_INTERRUPTIBLE 0x0001 // 等待事件阻塞 可信号唤醒
|
||||
// #define TASK_UNINTERRUPTIBLE 0x0002 // 等待事件阻塞 不可信号唤醒
|
||||
// #define __TASK_STOPPED 0x0004 // 暂停执行
|
||||
// #define __TASK_TRACED 0x0008 //调试状态
|
||||
// #define TASK_PARKED 0x0040 // parked 状态,暂停执行 保留在 cpu 但不被调度
|
||||
// #define TASK_DEAD 0x0080 // dead
|
||||
// #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
|
||||
// #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
|
||||
// #define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
|
||||
// static const char *state_str(int __state){
|
||||
|
||||
// }
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define TASK_RUNNING 0x0000
|
||||
#define TASK_INTERRUPTIBLE 0x0001
|
||||
#define TASK_UNINTERRUPTIBLE 0x0002
|
||||
#define __TASK_STOPPED 0x0004
|
||||
#define __TASK_TRACED 0x0008
|
||||
#define TASK_PARKED 0x0040
|
||||
#define TASK_DEAD 0x0080
|
||||
#define TASK_WAKEKILL 0x0100
|
||||
#define TASK_NOLOAD 0x0200
|
||||
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
|
||||
#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
|
||||
#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
|
||||
|
||||
std::string state_str(int __state){
|
||||
std::vector<std::string> states;
|
||||
|
||||
if (__state == TASK_RUNNING) states.push_back("TASK_RUNNING");
|
||||
// if (__state & TASK_RUNNING) states.push_back("TASK_RUNNING");
|
||||
if (__state & TASK_INTERRUPTIBLE) states.push_back("TASK_INTERRUPTIBLE");
|
||||
if (__state & TASK_UNINTERRUPTIBLE) states.push_back("TASK_UNINTERRUPTIBLE");
|
||||
if (__state & __TASK_STOPPED) states.push_back("__TASK_STOPPED");
|
||||
if (__state & __TASK_TRACED) states.push_back("__TASK_TRACED");
|
||||
if (__state & TASK_PARKED) states.push_back("TASK_PARKED");
|
||||
if (__state & TASK_DEAD) states.push_back("TASK_DEAD");
|
||||
if (__state == TASK_KILLABLE) states.push_back("TASK_KILLABLE");
|
||||
if (__state == TASK_STOPPED) states.push_back("TASK_STOPPED");
|
||||
if (__state == TASK_IDLE) states.push_back("TASK_IDLE");
|
||||
|
||||
std::string result;
|
||||
for (const auto& state : states) {
|
||||
if (!result.empty()) result += " | ";
|
||||
result += state;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void printk_task_brief(task_detail *detail) {
|
||||
printf(" 进程信息: [%s / %s], PID: %d / %d\n", detail->cgroup_buf,
|
||||
detail->comm, detail->tgid, detail->pid);
|
||||
printf(" 进程信息: [%s / %s], PID: %d / %d\n", detail->cgroup_buf, detail->comm, detail->tgid,
|
||||
detail->pid);
|
||||
printf(" 进程状态: type: %s, state: %s, state %d\n", sys_task_str(detail->sys_task), state_str(detail->state).c_str(),
|
||||
detail->state);
|
||||
}
|
||||
|
||||
void diag_printf_kern_stack(kern_stack_detail *kern_stack) {
|
||||
|
||||
@@ -123,11 +123,21 @@ static int task_info_extract(void *buf, unsigned int len, void *) {
|
||||
// diag_printf_raw_stack(tsk_info->task.tgid, tsk_info->task.container_tgid,
|
||||
// tsk_info->task.comm, &tsk_info->raw_stack);
|
||||
// printf("run_in_host: %d\n", run_in_host);
|
||||
diag_printf_raw_stack(run_in_host ? tsk_info->task.tgid
|
||||
: tsk_info->task.container_tgid,
|
||||
tsk_info->task.container_tgid, tsk_info->task.comm,
|
||||
&tsk_info->raw_stack);
|
||||
// diag_printf_raw_stack(run_in_host ? tsk_info->task.tgid
|
||||
// : tsk_info->task.container_tgid,
|
||||
// tsk_info->task.container_tgid, tsk_info->task.comm,
|
||||
// &tsk_info->raw_stack);
|
||||
// test(tsk_info);
|
||||
|
||||
// system task no need print raw_stack
|
||||
if (tsk_info->task.sys_task == 1){
|
||||
diag_printf_kern_stack(&tsk_info->kern_stack);
|
||||
}else{
|
||||
diag_printf_raw_stack(run_in_host ? tsk_info->task.tgid : tsk_info->task.container_tgid,
|
||||
tsk_info->task.container_tgid, tsk_info->task.comm, &tsk_info->raw_stack);
|
||||
diag_printf_kern_stack(&tsk_info->kern_stack);
|
||||
}
|
||||
|
||||
diag_printf_kern_stack(&tsk_info->kern_stack);
|
||||
|
||||
printf("#* 0xffffffffffffff %s (UNKNOWN)\n", tsk_info->task.comm);
|
||||
|
||||
Reference in New Issue
Block a user