美文网首页
2020-04-01 linux上快速打印出最占cpu的java

2020-04-01 linux上快速打印出最占cpu的java

作者: 五大RobertWu伍洋 | 来源:发表于2020-04-01 11:25 被阅读0次

    top -d 1找出最占资源的java进程的pid和cpu,内存大概的占用率

    759502 runtime   20   0 10.244g 5.365g  14796 S   9.9 22.9 240058:48 java
    

    编写 jvmtop.sh 文件保存到/tmp目录

    export LANG="zh_CN.UTF-8";
    export LC_ALL="zh_CN.UTF-8";
    
    LOG_FILE="jvmtop.log";
    JSTACK_FILE="jstack.log";
    
    PID="$1";
    shift;
    i=0;
    j="$1";
    if [ -z "${j}" ]; then
        j=5;
    fi
    
    ps -mp ${PID} -o THREAD,tid,time | sort -rn > ${LOG_FILE};
    jstack ${PID} > ${JSTACK_FILE};
    chmod 777 ${JSTACK_FILE}
    for LINE in `cat ${LOG_FILE}|gawk -F '-' '{print $4}'|gawk -F ' ' '{print $1}'`
    do
        i=$(($i+1));
        if (($i>$j)); then
            break;
        fi;
        XPID=`printf "%x\n" ${LINE}`;
        echo -ne "\033[32m";
        echo ${XPID};
        echo -e "\033[34m";
        grep -A 10 "0x${XPID}" ${JSTACK_FILE};
        echo -e "\e[0m";
    done;
    

    打印出java进程中cpu占用最高的线程id

    sudo -u runtime bash jvmtop.sh  759502
    

    相关文章

      网友评论

          本文标题:2020-04-01 linux上快速打印出最占cpu的java

          本文链接:https://www.haomeiwen.com/subject/yduouhtx.html