zoukankan      html  css  js  c++  java
  • 【JVM性能调优】检测最耗cpu的线程的脚本

    经常定位线程对cpu的耗时情况,每次重复去输入命令很不方便,特别写了一个脚本用于快速打印jvm的线程耗时情况

    #!/bin/bash
    
    if [ $# -eq 0 ];then
      echo "please enter java pid"
      exit -1
    fi
    
    pid=$1
    jstack_cmd=""
    
    if [[ $JAVA_HOME != "" ]]; then
      jstack_cmd="$JAVA_HOME/bin/jstack"
    else
      r=`which jstack 2>/dev/null`
      if [[ $r != "" ]]; then
        jstack_cmd=$r
      else
        echo "can not find jstack"
        exit -2
      fi
    fi
    
    #line=`top -H  -o %CPU -b -n 1  -p $pid | sed '1,/^$/d' | grep -v $pid | awk 'NR==2'`
    
    line=`top -H -b -n 1  -p $pid | sed '1,/^$/d' | sed '1d;/^$/d' | grep -v $pid | sort -nrk9 | head -1`
    echo "$line" | awk '{print "tid: "$1," cpu: %"$9}'
    tid_0x=`printf "%0x" $(echo "$line" | awk '{print $1}')`
    $jstack_cmd $pid | grep $tid_0x -A20 | sed -n '1,/^$/p'

  • 相关阅读:
    跨域问题
    window7_64+python3.6安装Twisted
    resful协议1
    Http状态码
    数据库学习笔记
    linux学习笔记
    前端学习笔记
    python学习笔记
    mongoDB
    git的使用方法
  • 原文地址:https://www.cnblogs.com/it-science/p/12834165.html
Copyright © 2011-2022 走看看