Saturday, June 28, 2014

Using PS & JStack to map linux threads to java methods on Linux




    1. Display all currently available Java threads:
      ps -C java -L -o pid,tid,nlwp,pcpu,cputime,psr,pmem --sort pcpu

      • pid - process id (the one of the JVM)
      • tid/lwp - thread id / light weight process
      • nlwp - total number of threads in the process
      • pcpu - cpu utilization
      • cputime - accumulated CPU time, user + system
      • psr - processor that thread is currently assigned to
      • pmem - ratio of the process's resident set size to the physical memory on the machine


    1. Identify the threads that, e.g., utilize most the CPU

    1. Convert their linux thread id (TID) to hexadecimal and note it down

    1. Use JStack to get the stack traces of all threads that belong to the Java process
      jstack |less

  1. The nid of each stack trace represents the hexadecimal value of linux thread id (TID)

No comments: