原文:https://github.com/oldratlee/useful-shells
useful-shells
把平時有用的手動操作做成腳本,這樣可以便捷的使用。
show-busy-java-threads.sh
在排查Java
的CPU
性能問題時,找出Java進程中消耗CPU多(top us值過高)的線程,查看它的線程棧,從而找出有性能問題的方法調用。
$ ./show-busy-java-threads.sh The stack of busy(57.0%) thread(23355/0x5b3b) of java process(23269) of user(admin): "pool-1-thread-1" prio=10 tid=0x000000005b5c5000 nid=0x5b3b runnable [0x000000004062c000] java.lang.Thread.State: RUNNABLE at java.text.DateFormat.format(DateFormat.java:316) at com.xxx.foo.services.common.DateFormatUtil.format(DateFormatUtil.java:41) at com.xxx.foo.shared.monitor.schedule.AppMonitorDataAvgScheduler.run(AppMonitorDataAvgScheduler.java:127) at com.xxx.foo.services.common.utils.AliTimer$2.run(AliTimer.java:128) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)