From ea60dd0f21c10bb8ba788acf3f32b8dd45c3c852 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 10 Jul 2023 09:53:18 +0800 Subject: [PATCH] tasktop: fix readme.md and usage --- source/tools/detect/sched/tasktop/README.md | 99 +++++++++------------ source/tools/detect/sched/tasktop/tasktop.c | 2 +- 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/source/tools/detect/sched/tasktop/README.md b/source/tools/detect/sched/tasktop/README.md index 00afbf39..558e8a26 100644 --- a/source/tools/detect/sched/tasktop/README.md +++ b/source/tools/detect/sched/tasktop/README.md @@ -1,60 +1,45 @@ -# 功能说明 -tasktop实现对task的cpu利用率进行监控 -# 使用说明 -``` -USAGE: tasktop [--help] [-t] [-p TID] [-d DELAY] [-i ITERATION] [-s SORT] [-f LOGFILE] [-l LIMIT] - - -d, --delay=DELAY 采样的周期 默认采样区间为3秒 - -f, --logfile=LOGFILE 日志文件 默认为/var/log/sysak/tasktop/tasktop.log 指定为/dev/stdout每次输出前会刷屏 用于实时监控 - -i, --iter=ITERATION 采样的输出次数 默认是无限次 - -p, --pid=TID 指定监控的TID 如果是子线程ID 需要-t开启线程模式 - -s, --sort=SORT 采样结果的排序方式 可选项为user(用户态)、sys(内核态)、cpu(用户态+内核态)默认为cpu - -t, --thread 线程模式 监控线程级的CPU利用率 默认为进程级 - -l, --limit=LIMIT 每次输出只显示的top-LIMIT个task 默认为所有CPU利用率大于0的task -``` +# Tasktop -# 使用举例 -下面的例子对线程级task的CPU利用率进行采样 采样结果输出到标准输出流 排序方式为总的CPU利用率 连续采样两次 每次采样时间5s -``` -sudo out/sysak tasktop -t -f /dev/stdout -s cpu -i 2 -d 5 -``` -## 日志输出说明 -输出说明如下: -``` -2023-04-28 06:38:09 - COMMAND PID PPID RUNTIME %UTIME %STIME %CPU - (stress) 127560 127556 8 80.67 0.00 80.67 - (stress) 127563 127556 8 80.00 0.00 80.00 - (stress) 127557 127556 8 79.67 0.00 79.67 - (stress) 127559 127556 8 79.33 0.00 79.33 - (stress) 127562 127556 8 78.00 0.00 78.00 - (stress) 127564 127556 8 77.33 0.00 77.33 - (stress) 127558 127556 8 77.00 0.00 77.00 - (stress) 127561 127556 8 75.00 0.00 75.00 - (AliYunDun) 89000 1 1220822 2.67 1.33 4.00 - (AliYunDun) 89995 1 1220813 2.00 2.00 4.00 - (telegraf) 9555 1 65492482 0.33 2.00 2.33 - (telegraf) 9553 1 65492484 0.00 1.33 1.33 - (telegraf) 9546 1 65492484 0.00 1.33 1.33 - (telegraf) 9547 1 65492484 0.33 1.00 1.33 - (tasktop) 127637 127635 6 0.33 1.00 1.33 - (node) 93078 93041 19585 0.33 0.67 1.00 - (uniagent) 122088 1 185555 0.67 0.33 1.00 - (uniagent) 63591 1 10554696 0.33 0.33 0.67 - (telegraf) 9587 1 65492412 0.00 0.67 0.67 - (walle) 63777 1 10554689 0.33 0.33 0.67 - (AliYunDun) 88986 1 1220822 0.33 0.33 0.67 -``` -上面的日志记录了一次采样周期内的CPU利用率大于0的task 并按照总CPU利用率排序。 +针对于负载问题的分析工具,相比loadtask对于细分场景进行了覆盖。 -输出的参数信息说明如下 -``` -COMMAND 命令名 -PID 进程ID或者线程ID -PPID 父进程ID -RUNTIME task的运行时间 -%UTIME 用户态CPU利用率 -%STIME 内核态CPU利用率 -%CPU 总CPU利用率 +## Usgae + +```bash +Usage: tasktop [OPTION...] +A light top, display the process/thread cpu utilization in peroid. + +USAGE: tasktop [--help] [-t] [-p TID] [-d DELAY] [-i ITERATION] [-s SORT] [-f +LOGFILE] [-l LIMIT] [-H] [-e D-LIMIT] + +EXAMPLES: + tasktop # run forever, display the cpu utilization. + tasktop -t # display all thread. + tasktop -p 1100 # only display task with pid 1100. + tasktop -d 5 # modify the sample interval. + tasktop -i 3 # output 3 times then exit. + tasktop -s user # top tasks sorted by user time. + tasktop -l 20 # limit the records number no more than 20. + tasktop -e 10 # limit the d-stack no more than 10, default is 20. + tasktop -H # output time string, not timestamp. + tasktop -f a.log # log to a.log. + tasktop -e 10 # most record 10 d-task stack. + + -d, --delay=DELAY Sample peroid, default is 3 seconds + -e, --d-limit=D-LIMIT Specify the D-LIMIT D tasks's stack to display + -f, --logfile=LOGFILE Logfile for result, default + /var/log/sysak/tasktop/tasktop.log + -H, --human Output human-readable time info. + -i, --iter=ITERATION Output times, default run forever + -l, --r-limit=LIMIT Specify the top R-LIMIT tasks to display + -p, --pid=TID Specify thread TID + -s, --sort=SORT Sort the result, available options are user, sys + and cpu, default is cpu + -t, --thread Thread mode, default process + -?, --help Give this help list + --usage Give a short usage message + -V, --version Print program version ``` -上面的日志可以看到PID为127556的task 创建了8个子进程占用了大量的CPU资源 + +## 使用说明 + +详细的使用案例,请查看`tasktopSelftest`目录下的`test.md`。 diff --git a/source/tools/detect/sched/tasktop/tasktop.c b/source/tools/detect/sched/tasktop/tasktop.c index 388198d9..5835394a 100644 --- a/source/tools/detect/sched/tasktop/tasktop.c +++ b/source/tools/detect/sched/tasktop/tasktop.c @@ -74,7 +74,7 @@ const char argp_program_doc[] = " tasktop -l 20 # limit the records number no more than 20.\n" " tasktop -e 10 # limit the d-stack no more than 10, default is " "20.\n" - " tasktop -H # output time string, not timestamp." + " tasktop -H # output time string, not timestamp.\n" " tasktop -f a.log # log to a.log.\n" " tasktop -e 10 # most record 10 d-task stack.\n"; -- Gitee