{"id":629,"date":"2013-02-21T00:23:13","date_gmt":"2013-02-21T00:23:13","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=629"},"modified":"2013-04-07T23:43:23","modified_gmt":"2013-04-07T23:43:23","slug":"correlating-linux-top-output-with-java-stack-trace-from-a-thread-dump","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2013\/02\/21\/correlating-linux-top-output-with-java-stack-trace-from-a-thread-dump\/","title":{"rendered":"Correlating Linux top output with java stack trace from a thread dump"},"content":{"rendered":"<p>Using the <strong>top -H<\/strong> command to show you the thread ids, and from the <a href=\"http:\/\/http:\/\/shivdev.com\/blog\/2011\/05\/06\/generating-thread-dumps-in-java-on-linux\/\">thread dump<\/a>, you can correlate the thread that&#8217;s taking CPU time.<\/p>\n<p>For example the stack trace will show you the ID in hex format and the top will show you the thread PID in decimal format.<\/p>\n<p>Notice that <strong>nid=0x6c21<\/strong> (top -H) is the same as <strong>27681<\/strong> (from the thread dump).<\/p>\n<p>Here&#8217;s a thread dump snippet<\/p>\n<blockquote><p>&#8220;http-bio-\/127.0.0.1-9090-exec-7&#8221; daemon prio=10 tid=0x000000004c433800 <strong>nid=0x6c21<\/strong> runnable [0x00000000644b9000]<br \/>\nINFO | jvm 1 | 2013\/02\/20 11:51:57 | java.lang.Thread.State: RUNNABLE<br \/>\nINFO | jvm 1 | 2013\/02\/20 11:51:57 | at java.util.HashMap.put(HashMap.java:374)<\/p><\/blockquote>\n<p>Here&#8217;s the output of top -H<\/p>\n<blockquote><p>[root@myserver bin]# <strong>top -H<\/strong><\/p>\n<p>top &#8211; 15:56:17 up 5 days, 5:16, 8 users, load average: 2.16, 2.25, 3.28<br \/>\nTasks: 1038 total, 3 running, 1035 sleeping, 0 stopped, 0 zombie<br \/>\nCpu(s): 12.8%us, 0.1%sy, 0.0%ni, 87.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st<br \/>\nMem: 37043972k total, 35569196k used, 1474776k free, 45720k buffers<br \/>\nSwap: 12586916k total, 228k used, 12586688k free, 18998952k cached<br \/>\n3.00\t00:04:50<br \/>\nPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND<br \/>\n27409 shivdev 25 0 11.6g 10g 16m R 99.9 30.7 1305:02 java<br \/>\n<strong>27681 <\/strong>shivdev 25 0 11.6g 10g 16m R 99.9 30.7 1304:37 java<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Using the top -H command to show you the thread ids, and from the thread dump, you can correlate the thread that&#8217;s taking CPU time. For example the stack trace will show you the ID in hex format and the top will show you the thread PID in decimal format. Notice that nid=0x6c21 (top -H) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,13],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/629"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=629"}],"version-history":[{"count":4,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/629\/revisions"}],"predecessor-version":[{"id":643,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/629\/revisions\/643"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}