简体   繁体   中英

What's the nid in jstack on MacOS

On Linux/HotSpot VM, top -H can list all threads of some java process, hence the thread id of busy thread can be spotted, so I can use that thread id to find the java thread in jstack output (the nid in jstack is the hex translation of thread id in top -H).

While Hotspot VM implementation on MacOS platform uses pthread_t as nid when using jstack to get Java threads stats, and there is nothing similar to top -H on MacOS. So is there any way to find the "busy" Java thread without MXBean?

Or can anyone tell me on MacOS how I can find the busy Java thread's 'nid', according to which I can find corresponding Java thread by jstack?

A small correction: on macOS, nid is not pthread_t , but rather a thread port as obtained by pthread_mach_thread_np(pthread_t) .

Anyway, there is no an equivalent of top -H on macOS, unfortunately. But you don't need one, if you just want to find a busy Java thread. Use a Java profiler instead.

Here is how to do this with async-profiler :

./profiler.sh -d 10 -t -f profile.svg PID

This means: profile the Java process PID for ten seconds ( -d 10 ) in threaded mode ( -t ) and save the output as a Flame Graph to profile.svg . You won't even need jstack - the profile will already highlight the hottest thread(s) with their Java stack traces.

火焰图

As an alternative to a Flame Graph, you may choose a "traditional" tree view
by specifying -f profile.html instead of -f profile.svg .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM