From 40421c04bb66f3f248829ee03c3e3a04273bea76 Mon Sep 17 00:00:00 2001 From: Hang Zhao Date: Mon, 28 Mar 2022 14:55:05 +0800 Subject: [PATCH] loadtask:adjust output of taskstate Signed-off-by: Hang Zhao --- source/tools/detect/loadtask/loadtask.sh | 11 +++-- source/tools/detect/taskstate/main.c | 52 ++++++++++++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/source/tools/detect/loadtask/loadtask.sh b/source/tools/detect/loadtask/loadtask.sh index e68b18ea..269fdac6 100755 --- a/source/tools/detect/loadtask/loadtask.sh +++ b/source/tools/detect/loadtask/loadtask.sh @@ -204,7 +204,7 @@ current_analyse() { cal_sirq $exist_sirq_tool 1 if [ -f $TOOLS_ROOT/taskstate ]; then - $TOOLS_ROOT/taskstate -r $rtaskfile -d $dtaskfile + $TOOLS_ROOT/taskstate -r $rtaskfile -d $dtaskfile -c $taskcountfile fi running_dump @@ -258,8 +258,12 @@ current_analyse() { fi echo "-----" >> $tmpfile - echo "uninterrupt_cnt: $uninterrupt_cnt" >> $tmpfile - echo "running_cnt: $running_cnt" >> $tmpfile + if [ -f $TOOLS_ROOT/taskstate ]; then + cat $taskcountfile >> $tmpfile + else + echo "uninterrupt_cnt: $uninterrupt_cnt" >> $tmpfile + echo "running_cnt: $running_cnt" >> $tmpfile + fi if [ $detail_result -eq 1 ]; then if [ $(echo "$load*0.2 > $uninterrupt_cnt" | bc) -eq 1 ]; then echo "load reason: high $high_cost cpu cost" >> $tmpfile @@ -380,6 +384,7 @@ global_cpuflamegraph=${loadtask_dir}global_cpuflamegraph-`date "+%Y-%m-%d-%H-%M- tmp_cpuflamegraph=${loadtask_dir}.tmp.svg tmpfile=${loadtask_dir}.tmplog rtaskfile=${loadtask_dir}runtask +taskcountfile=${loadtask_dir}taskcount dtaskfile=${loadtask_dir}dtask tmpsirqfile=${loadtask_dir}tmpsoftirq sirqspeedfile=${loadtask_dir}softirqspeed diff --git a/source/tools/detect/taskstate/main.c b/source/tools/detect/taskstate/main.c index 8003fa8b..588bc5fb 100644 --- a/source/tools/detect/taskstate/main.c +++ b/source/tools/detect/taskstate/main.c @@ -15,8 +15,12 @@ static char g_rtask_file[MAX_PATH_LEN] = {0}; static char g_dtask_file[MAX_PATH_LEN] = {0}; +static char g_taskcount_file[MAX_PATH_LEN] = {0}; static FILE *g_rtask_fp; static FILE *g_dtask_fp; +static FILE *g_taskcount_fp; +static int uninterrupt_cnt = 0; +static int running_cnt = 0; static void usage(void) { @@ -24,7 +28,8 @@ static void usage(void) "sysak taskstate: get tasks whose states are running or uninterruptible\n" "options: -h, help information\n" " -r file, get tasks whose states are running and output result to file\n" - " -d file, get tasks whose states are uninterruptible and output result to file\n"); + " -d file, get tasks whose states are uninterruptible and output result to file\n" + " -c file, get tasks count whose states are uninterruptible and running\n"); exit(-1); } @@ -37,7 +42,7 @@ static void parse_arg(int argc, char *argv[]) if (argc < 2) usage(); - while ((ch = getopt(argc, argv, "r:d:h")) != -1) { + while ((ch = getopt(argc, argv, "r:d:c:h")) != -1) { switch (ch) { case 'r': if (optarg && (strlen(optarg) < MAX_PATH_LEN)) @@ -51,6 +56,12 @@ static void parse_arg(int argc, char *argv[]) else exit(-1); break; + case 'c': + if (optarg && (strlen(optarg) < MAX_PATH_LEN)) + strncpy(g_taskcount_file, optarg, strlen(optarg)); + else + exit(-1); + break; case 'h': default: usage(); @@ -122,14 +133,21 @@ static int get_task_info(long pid) if (strstr(line, TASK_RUNNING)) { snprintf(tid_str, sizeof(tid_str), "%ld\n", tid); fwrite(tid_str, strlen(tid_str), 1, g_rtask_fp); - fwrite(task_name, strlen(task_name), 1, g_rtask_fp); - // fwrite(line, strlen(line), 1, g_rtask_fp); + char *task_name_str = (char *) malloc(strlen("Task_") + strlen(task_name)); + sprintf(task_name_str, "%s%s", "Task_", task_name); + fwrite(task_name_str, strlen(task_name_str), 1, g_rtask_fp); + free(task_name_str); + running_cnt++; } else if (strstr(line, TASK_UNINTERRUPT)) { snprintf(tid_str, sizeof(tid_str), "%ld\n", tid); fwrite(tid_str, strlen(tid_str), 1, g_dtask_fp); - fwrite(task_name, strlen(task_name), 1, g_dtask_fp); - // fwrite(line, strlen(line), 1, g_dtask_fp); + char *task_name_str = (char *) malloc(strlen("Task_") + strlen(task_name)); + sprintf(task_name_str, "%s%s", "Task_", task_name); + fwrite("-----\n", strlen("-----\n"), 1, g_dtask_fp); + fwrite(task_name_str, strlen(task_name_str), 1, g_dtask_fp); + free(task_name_str); + uninterrupt_cnt++; get_dtask_stack(tid); } @@ -152,6 +170,8 @@ static int scan_task(void) int i; int len; long pid; + char rtask_count[MAX_LINE_LEN] = {0}; + char dtask_count[MAX_LINE_LEN] = {0}; if (!(dp = opendir("/proc"))) { return -1; @@ -176,8 +196,18 @@ static int scan_task(void) } } + snprintf(rtask_count, sizeof(running_cnt), "%ld\n", running_cnt); + snprintf(dtask_count, sizeof(uninterrupt_cnt), "%ld\n", uninterrupt_cnt); + char *rtask_count_str = (char *) malloc(strlen("running_cnt: ") + strlen(rtask_count)); + char *dtask_count_str = (char *) malloc(strlen("uninterrupt_cnt: ") + strlen(dtask_count)); + sprintf(rtask_count_str, "%s%s", "running_cnt: ", rtask_count); + sprintf(dtask_count_str, "%s%s", "uninterrupt_cnt: ", dtask_count); + fwrite(rtask_count_str, strlen(rtask_count_str), 1, g_taskcount_fp); + fwrite(dtask_count_str, strlen(dtask_count_str), 1, g_taskcount_fp); + free(rtask_count_str); + free(dtask_count_str); + closedir(dp); -// printf("\n"); return 0; } @@ -196,10 +226,18 @@ int main(int argc, char *argv[]) exit(-1); } + g_taskcount_fp = fopen(g_taskcount_file, "w+"); + if (!g_taskcount_fp) { + fclose(g_dtask_fp); + fclose(g_rtask_fp); + exit(-1); + } + scan_task(); close_file: fclose(g_dtask_fp); fclose(g_rtask_fp); + fclose(g_taskcount_fp); return 0; } -- Gitee