Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show-busy-java-threads support MacOS #33

Open
oldratlee opened this issue Jan 7, 2014 · 6 comments
Open

show-busy-java-threads support MacOS #33

oldratlee opened this issue Jan 7, 2014 · 6 comments

Comments

@oldratlee
Copy link
Owner

oldratlee commented Jan 7, 2014

  • Mac下使用解析命令行参数出错。Macgetopt不兼容GNU
    • 这个不是问题。自己手动来解析 来实现即可。
  • Macshow-busy-java-threads出错。Macps不兼容GNU
    • 比如 不支持 输出 线程ID(即 -L 选项)。
      • Mac下的ps-L是:
        List the set of keywords available for the -O and -o options.
@ghost ghost assigned oldratlee Jan 7, 2014
@undancer
Copy link

undancer commented Sep 11, 2014

同一个文件,head --lines "${count}"部分,Mac下应为 head -n "${count}"

@oldratlee oldratlee assigned oldratlee and unassigned oldratlee Dec 26, 2014
@AnonymMan
Copy link

AnonymMan commented Oct 13, 2015

ps -Leo pid,lwp,user,comm,pcpu --no-headersMac不兼容啊,怎么解决?

@oldratlee
Copy link
Owner Author

oldratlee commented Oct 14, 2015

@AnonymMan Macps命令没有支持,也没有找到其它的命令支持。


我去翻了过Mac的系统API,想写C程序来获取系统的

  • 线程ID
  • 及其CPU使用率

没有找到。


我到现在还没有找到解法, @AnonymMan 你看看有没有办法 ? 😄

@AnonymMan
Copy link

@oldratlee 我这暂时也没有想到什么好的办法。

@oldratlee oldratlee changed the title 兼容Mac show-busy-java-threads.sh 兼容Mac Oct 17, 2017
@oldratlee oldratlee added feature and removed bug labels Oct 17, 2017
@oldratlee oldratlee changed the title show-busy-java-threads.sh 兼容Mac show-busy-java-threads.sh 支持 Mac Mar 6, 2018
@oldratlee oldratlee pinned this issue Apr 20, 2019
@oldratlee oldratlee changed the title show-busy-java-threads.sh 支持 Mac show-busy-java-threads 支持 Mac Apr 20, 2019
@oldratlee oldratlee changed the title show-busy-java-threads 支持 Mac show-busy-java-threads support MacOS May 1, 2021
@oldratlee oldratlee unpinned this issue May 3, 2021
@fireworkor
Copy link

按照 pcpu排序 实际是字典排序 ,导致busy为0,修改findBusyJavaThreadsByPs方法为如下代码试试看

findBusyJavaThreadsByPs() {
    local -a ps_cmd_line=(ps $ps_process_select_options -wwLo pid,lwp,pcpu,user --no-headers)
    local temp_output="$("${ps_cmd_line[@]}")"
    local sorted_output
    sorted_output=$(echo "$temp_output" | awk '{print $3*1,$0}' | sort -nr | awk '{print $2,$3,$4,$5}')
    local -r ps_out="$sorted_output"
    if [ -n "$store_dir" ]; then
        echo "$ps_out" | logAndCat "${ps_cmd_line[@]}" > "${store_file_prefix}$(( i + 1 ))_ps"
    fi
    echo "$ps_out" | head -n "${count}"
}

@oldratlee
Copy link
Owner Author

oldratlee commented Nov 1, 2024

按照 pcpu排序 实际是字典排序 ,导致busy为0,修改findBusyJavaThreadsByPs方法为如下代码试试看

Hi, @fireworkor

  1. 给一下你使用的show-busy-java-threads版本及其实现代码
    • 可以/推荐 使用最新的稳定版本v2.5.4
    • 引用文件对应commit文件行的永久链接可以看该commit的实现代码;如下面是v2.5.4的实现代码:
    • local -a ps_cmd_line=(ps $ps_process_select_options -wwLo 'pid,lwp,pcpu,user' --no-headers)
      # DO NOT combine var ps_out declaration and assignment in ONE line!
      # more info see https://github.com/koalaman/shellcheck/wiki/SC2155
      local ps_out
      ps_out=$("${ps_cmd_line[@]}" | sort -k3,3nr)
      [ -n "$ps_out" ] || __die_when_no_java_process_found
    • 看了下这个版本,有数值排序选项sort -nsort -k3,3nr
  2. 提供一下运行方式 及其 有问题的输出,方便排查
    • 方便的话,也可以提供上 运行环境的相关信息
  3. 提的内容 看起来 与这个 issue 无关,请开一个独立 issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants