jstack 실행 시 결과에 LWP(Lightweight PID) 추가하기

  • short3300
    (스벅오늘의커피)
  • short3300's Avatar 이 글의 작성자
  • Offline
  • Junior
  • Junior
더보기
18 May 2020 09:42 - 18 May 2020 09:43 #5075 작성자: short3300
short3300 님의 글: jstack 실행 시 결과에 LWP(Lightweight PID) 추가하기
jstack <PID> | perl -ne 'if (/nid=(0x[[:xdigit:]]+)/) { $lwp = hex($1); s/nid=/lwp=$lwp nid=/; } print;'

예를 들어 java 프로세스의 PID가 3031이면 이렇게 실행한다.

jstack 3031 | perl -ne 'if (/nid=(0x[[:xdigit:]]+)/) { $lwp = hex($1); s/nid=/lwp=$lwp nid=/; } print;'


그냥 실행할 때는 아래와 같이 lwp 필드가 없다.

"main" #1 prio=5 os_prio=31 tid=0x00007f9da1009000 nid=0x1203 runnable [0x0000700010100000]
   java.lang.Thread.State: RUNNABLE
	at java.net.PlainSocketImpl.socketAccept(Native Method)
	at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
	at java.net.ServerSocket.implAccept(ServerSocket.java:545)
	at java.net.ServerSocket.accept(ServerSocket.java:513)
	at org.apache.catalina.core.StandardServer.await(StandardServer.java:447)
	at org.apache.catalina.startup.Catalina.await(Catalina.java:776)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:722)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)

위에 명령어로 jstack 실행하면 lwp 필드가 추가되었다.

"main" #1 prio=5 os_prio=31 tid=0x00007f9da1009000 lwp=4611 nid=0x1203 runnable [0x0000700010100000]
   java.lang.Thread.State: RUNNABLE
	at java.net.PlainSocketImpl.socketAccept(Native Method)
	at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
	at java.net.ServerSocket.implAccept(ServerSocket.java:545)
	at java.net.ServerSocket.accept(ServerSocket.java:513)
	at org.apache.catalina.core.StandardServer.await(StandardServer.java:447)
	at org.apache.catalina.startup.Catalina.await(Catalina.java:776)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:722)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
Time to create page: 0.101 seconds
Powered by Kunena Forum