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)

Squeezing white space in Linux Bash

http://www.linuxjournal.com/article/2563
For instance, we can squeeze all standard white space to a single space by specifying:
tr -s   \n [ *]
This will remove all spaces ...
echo " test test test " | tr -d ' '
so this results in
testtesttest
This will remove leading spaces...
echo " test test test " | sed 's/^ *//'
which results in
test test test
This will remove both trailing and leading spaces
echo " test test test " | sed -e 's/^ *//' -e 's/ *$//'
which results in
test test test
 
echo "   lol  " | xargs
Xargs will do the trimming for you, it's one command/program, no parameters, returns the trimmed string, easy as that!
WARNING:
echo " test    test " | xargs
gives
test test
not
 test    test
  
  
 var1=$(echo $STR | cut -f1 -d-)
var2=$(echo $STR | cut -f2 -d-)

Finding Limits for a Linux Process

cat /proc//limits