输出堆栈日志
程序员文章站
2022-03-08 09:58:44
...
@echo off&setlocal enabledelayedexpansion
REM 设置JDK路径
REM set JAVA_HOME=D:\Java\jdk1.6.0_10
REM set PATH=D:\Java\jdk1.6.0_10\bin;C:\WINDOWS\system32;
REM 设置网关的pid,可通过任务管理器查看,有500个进程那个
set p_pid=0
:begin
echo .
if %p_pid%==0 (goto choiced) else (goto runprint)
goto end
:choiced
echo .
echo 以下是系统当前的运行进程,前面的数字是进程号(PID)
jps -v
echo .
echo .
set /p p_pid=请输入进程号(PID),退出[Q]
if %p_pid%==null (goto choiced) else (goto runprint)
:runprint
echo .
echo 创建堆栈存放的目录......
echo .
set runtime=%date:~0,10%_%time:~0,2%_%time:~3,2%_%time:~6,2%
set targetpath=JAVA_JDK_PRINT_FILE\%date:~0,10%
if not exist %targetpath% (md %targetpath%)
echo ***************************************************************
echo 1打印进程堆栈(heap)开始
jstack -l %p_pid% > %targetpath%\堆栈_%runtime%.txt
REM 检测文件大小
set heapfile=%targetpath%\堆栈_%runtime%.txt
for /f "delims=" %%a in ('dir /b /s "%heapfile%"') do (
rem 当文件大小为0,表示输入的进程号不存在
if %%~za==0 (
del /s /q %heapfile%
REM set /p noexist=进程号不存在,打印失败,是否重新打印[Y],退出[Q]
REM if /i %noexist% equ q goto end
REM if /i %noexist% equ y goto choiced
)
)
echo 1打印进程堆栈(heap)结束
echo .
echo .
echo 等待60秒后重新打印一次,如果不想继续打印,请直接关闭程序
REM 设置等待60秒进行重打印
ping -n 60 127.0.0.1 >nul
goto runprint
:end
exit
REM 设置JDK路径
REM set JAVA_HOME=D:\Java\jdk1.6.0_10
REM set PATH=D:\Java\jdk1.6.0_10\bin;C:\WINDOWS\system32;
REM 设置网关的pid,可通过任务管理器查看,有500个进程那个
set p_pid=0
:begin
echo .
if %p_pid%==0 (goto choiced) else (goto runprint)
goto end
:choiced
echo .
echo 以下是系统当前的运行进程,前面的数字是进程号(PID)
jps -v
echo .
echo .
set /p p_pid=请输入进程号(PID),退出[Q]
if %p_pid%==null (goto choiced) else (goto runprint)
:runprint
echo .
echo 创建堆栈存放的目录......
echo .
set runtime=%date:~0,10%_%time:~0,2%_%time:~3,2%_%time:~6,2%
set targetpath=JAVA_JDK_PRINT_FILE\%date:~0,10%
if not exist %targetpath% (md %targetpath%)
echo ***************************************************************
echo 1打印进程堆栈(heap)开始
jstack -l %p_pid% > %targetpath%\堆栈_%runtime%.txt
REM 检测文件大小
set heapfile=%targetpath%\堆栈_%runtime%.txt
for /f "delims=" %%a in ('dir /b /s "%heapfile%"') do (
rem 当文件大小为0,表示输入的进程号不存在
if %%~za==0 (
del /s /q %heapfile%
REM set /p noexist=进程号不存在,打印失败,是否重新打印[Y],退出[Q]
REM if /i %noexist% equ q goto end
REM if /i %noexist% equ y goto choiced
)
)
echo 1打印进程堆栈(heap)结束
echo .
echo .
echo 等待60秒后重新打印一次,如果不想继续打印,请直接关闭程序
REM 设置等待60秒进行重打印
ping -n 60 127.0.0.1 >nul
goto runprint
:end
exit
上一篇: SizeOf对象的大小