Skip to content

fix(syscall-stat): handle -t/--top option instead of rejecting it - #161

Open
yuKing123-king wants to merge 1 commit into
DKapture:mainfrom
yuKing123-king:fix/syscall-stat-parse-top-option
Open

yuKing123-king wants to merge 1 commit into
DKapture:mainfrom
yuKing123-king:fix/syscall-stat-parse-top-option

Conversation

@yuKing123-king

Copy link
Copy Markdown
Contributor

修复的 Bug

syscall-stat 的 -t/--top 功能完全不可用:传入 -t 会被当作非法选项拒绝并退出。

$ sudo dk-syscall-stat -t
Usage: ...        # 打印帮助后 exit(-1)

根因:parse_args() 的 switch(syscall-stat.cpp:164-197)只有 p/f/c/i/h/default,缺少 case 't':。-t 被 getopt_long 正确识别并返回 't',但 switch 里没有对应分支,落到 default → Usage() + exit(-1)。

讽刺的是,该功能的所有其它部分都已就绪:

  • 选项表已定义:{"top", no_argument, 0, 't'}(syscall-stat.cpp:80)
  • 变量已声明:static bool top = false(syscall-stat.cpp:72)
  • 逻辑已实现:timer_task 里 if (top) { printf("\33[H\33[2J\33[3J"); ... } 清屏输出(syscall-stat.cpp:320-324)
  • 帮助文本已写好:{"[top]", "output information in top way\n"}(syscall-stat.cpp:98)

唯独 parse_args 的 switch 漏了 case 't' 这一行,导致整条链路断在入口处。

改了哪些地方

仅 observe/syscall-stat.cpp 的 parse_args switch 内新增一个 case:

case 't': // Top mode
    top = true;
    break;

插入在 case 'i': 与 case 'h': 之间。不涉及 BPF 侧、不涉及 timer_task 逻辑、不涉及选项表。

Signed-off-by: Wang Yu <wangyu6@uniontech.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant