summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorzy <[email protected]>2023-12-05 00:49:44 -0500
committerzy <[email protected]>2023-12-05 00:49:44 -0500
commit66222370ca73b4241f516d4ec32dc4ec036c9918 (patch)
tree3cc6f6f9e79f409ec883e662bdc9ef3b05a85882 /source
parentc183233d07076821ac1b66cf158c65e853ed3060 (diff)
do_pid
Diffstat (limited to 'source')
-rw-r--r--source/ucli/ucli.cc62
1 files changed, 50 insertions, 12 deletions
diff --git a/source/ucli/ucli.cc b/source/ucli/ucli.cc
index 1a98843..5a8e556 100644
--- a/source/ucli/ucli.cc
+++ b/source/ucli/ucli.cc
@@ -2,9 +2,17 @@
* various_monitor cli 命令行工具
*/
#include "ucli.h"
+#include <cstdio>
#include <getopt.h>
#include <string.h>
-#include <cstdio>
+
+#include <sys/ioctl.h> // for ioctl
+#include <unistd.h>
+
+// ioctl
+// !todo move to a header file
+#define IOCTL_MAGIC_NUMBER 'k'
+#define IOCTL_PID _IOWR(IOCTL_MAGIC_NUMBER, 2, int)
static int task_info_extract(void *buf, unsigned int len, void *) {
int *et_type;
@@ -32,8 +40,8 @@ static int task_info_extract(void *buf, unsigned int len, void *) {
.name, // Assuming name is a null-terminated string
vm_record->threshold_record[i].ptr,
vm_record->threshold_record[i].threshold
- // vm_record->threshold_record[i].true_value
- );
+ // vm_record->threshold_record[i].true_value
+ );
}
break;
case VARIABLE_MONITOR_TASK_TYPE:
@@ -49,9 +57,11 @@ static int task_info_extract(void *buf, unsigned int len, void *) {
printk_task_brief(&tsk_info->task);
// 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);
+ 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_kern_stack(&tsk_info->kern_stack);
printf("#* 0xffffffffffffff %s (UNKNOWN)\n", tsk_info->task.comm);
@@ -71,7 +81,7 @@ static void do_extract(char *buf, int len) {
}
static void do_dump(const char *arg) {
- //!todo
+ //! todo
static char variant_buf[256 * 1024 * 1024];
int len;
int ret = 0;
@@ -93,13 +103,38 @@ static void do_dump(const char *arg) {
}
}
+static void do_pid(char *arg) {
+ int pid = 0;
+ int ret;
+
+ sscanf(optarg, "%d", &pid);
+ if (pid <= 0) {
+ printf("参数错误\n");
+ return;
+ }
+ printf("获取线程信息: %d\n", pid);
+ ret = diag_call_ioctl(IOCTL_PID, (long)&pid);
+ if (ret) {
+ printf("获取线程信息错误: %d\n", ret);
+ }
+ sleep(3);
+
+ do_dump("");
+}
+
int main(int argc, char *argv[]) {
run_in_host = check_in_host();
- static const struct option long_options[] = {{"help", no_argument, 0, 0},
- {"report", no_argument, 0, 0},
- {"pid", required_argument, 0, 0},
- {0, 0, 0, 0}};
+ for (int i = 0; i < argc; i++){
+ printf("argv[%d]: %s\n", i, argv[i]);
+ }
+
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 0},
+ {"report", no_argument, 0, 0},
+ {"pid", required_argument, 0, 0},
+ {"tgid", required_argument, 0, 0},
+ {0, 0, 0, 0}};
int c;
if (argc <= 1) {
@@ -116,7 +151,7 @@ int main(int argc, char *argv[]) {
break;
}
- option_index = 1;
+ option_index = 2;
switch (option_index) {
case 0: // help
@@ -125,6 +160,9 @@ int main(int argc, char *argv[]) {
case 1: // report
do_dump(optarg ? optarg : "");
break;
+ case 2: // pid
+ do_pid(optarg);
+ break;
default:
// usage_pupil();
break;