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支持top来获取cpu占用率,ps的cpu占用率非实时 #67

Closed
qsLI opened this issue May 14, 2018 · 4 comments
Assignees
Labels

Comments

@qsLI
Copy link

qsLI commented May 14, 2018

ps aux是根据各类时间算出的cpu占用率,top是实时的!
这方面的说明参见:纠结ps和top的cpu占用率不一致问题

可以使用 top -H -p 来计算各个线程的cpu时间

@oldratlee
Copy link
Owner

oldratlee commented May 19, 2018

收到,@qsLI

在查一下top如何方便的用脚本来调用,以完成这个功能的实现

@oldratlee oldratlee reopened this May 19, 2018
@oldratlee
Copy link
Owner

oldratlee commented May 22, 2018

@qsLI @sdslnmd (#23) 实现好了,使用top命令来获取线程的CPU占用率。

你们试试看看好用不? ❤️

当然,可以使用选项-P, --use-ps,来指定还是用ps命令获取线程整个生命周期的CPU占用率。


帮助信息

$ show-busy-java-threads -h
Usage: show-busy-java-threads [OPTION]... [delay [count]]
Find out the highest cpu consumed threads of java, and print the stack of these threads.

Example:
  show-busy-java-threads       # show busy java threads info
  show-busy-java-threads 1     # update every 1 second, (stop by eg: CTRL+C)
  show-busy-java-threads 3 10  # update every 3 seconds, update 10 times

Output control:
  -p, --pid <java pid>      find out the highest cpu consumed threads from the specified java process,
                            default from all java process.
  -c, --count <num>         set the thread count to show, default is 5.
  -a, --append-file <file>  specifies the file to append output as log.
  -S, --store-dir <dir>     specifies the directory for storing intermediate files, and keep files.
                            default store intermediate files at tmp dir, and auto remove after run.
                            use this option to keep files so as to review jstack/top/ps output later.
  delay                     the delay between updates in seconds.
  count                     the number of updates.
                            delay/count arguments imitates the style of vmstat command.

jstack control:
  -s, --jstack-path <path>  specifies the path of jstack command.
  -F, --force               set jstack to force a thread dump.
                            use when jstack <pid> does not respond (process is hung).
  -m, --mix-native-frames   set jstack to print both java and native frames (mixed mode).
  -l, --lock-info           set jstack with long listing. Prints additional information about locks.

cpu usage calculation control:
  -d, --top-delay           specifies the delay between top samples, default is 0.5 (second).
                            get thread cpu percentage during this delay interval.
                            more info see top -d option. eg: -d 1 (1 second).
  -P, --use-ps              use ps command to find busy thread(cpu usage) instead of top command,
                            default use top command, because cpu usage of ps command is expressed as
                            the percentage of time spent running during the entire lifetime of a process,
                            this is not ideal.

Miscellaneous:
  -h, --help                display this help and exit.

更多详见文档:
https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/java.md#-show-busy-java-threads

oldratlee pushed a commit that referenced this issue May 22, 2018
@oldratlee oldratlee changed the title show-busy-java-threads.sh cpu占用不准确 show-busy-java-threads支持top来获取cpu占用率,ps的cpu占用率不准确 May 22, 2018
@oldratlee oldratlee self-assigned this May 22, 2018
@qsLI
Copy link
Author

qsLI commented Jul 3, 2018

赞!

@oldratlee oldratlee changed the title show-busy-java-threads支持top来获取cpu占用率,ps的cpu占用率不准确 show-busy-java-threads支持top来获取cpu占用率,ps的cpu占用率非实时 Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants