Operations 17 min read

Essential Linux and Java Debugging Tools for Efficient Operations

This article compiles a practical cheat‑sheet of Linux commands, Java diagnostic utilities, and third‑party tools such as btrace, Greys, Arthas, and JProfiler, offering concise examples and usage tips to help engineers quickly troubleshoot performance and stability issues in production environments.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Essential Linux and Java Debugging Tools for Efficient Operations

Linux Command Cheatsheet

Commonly used commands for log inspection and file searching:

tail

tail -300f shopbase.log # show last 300 lines and follow

grep

grep forest f.txt               # search in a file
grep forest f.txt cpf.txt       # search in multiple files
grep 'log' /home/admin -r -n   # recursive search for a keyword
cat f.txt | grep -i shopbase
grep 'shopbase' /home/admin -r -n --include *.{vm,java}
grep 'shopbase' /home/admin -r -n --exclude *.{vm,java}
seq 10 | grep 5 -A 3          # after‑match
seq 10 | grep 5 -B 3          # before‑match
seq 10 | grep 5 -C 3          # context
cat f.txt | grep -c 'SHOPBASE'

awk

Basic printing and field selection:

awk '{print $4,$6}' f.txt
awk '{print NR,$0}' f.txt cpf.txt
awk '{print FNR,$0}' f.txt cpf.txt
awk '{print FNR,FILENAME,$0}' f.txt cpf.txt
awk '{print FILENAME,"NR="NR,"FNR="FNR,"$"NF"="$NF}' f.txt cpf.txt
echo 1:2:3:4 | awk -F: '{print $1,$2,$3,$4}'

Pattern matching examples:

awk '/ldb/ {print}' f.txt               # match ldb
awk '!/ldb/ {print}' f.txt              # not match ldb
awk '/ldb/ && /LISTEN/ {print}' f.txt  # match both
awk '$5 ~ /ldb/ {print}' f.txt          # match column 5

find

sudo -u admin find /home/admin /tmp /usr -name *.log
find . -iname *.txt
find . -type d
find /usr -type l
find /usr -type l -name "z*" -ls
find /home/admin -size +250000k
find /home/admin -perm 777 -exec ls -l {} \;
find /home/admin -atime -1
find /home/admin -ctime -1
find /home/admin -mtime -1
find /home/admin -amin -1
find /home/admin -cmin -1
find /home/admin -mmin -1

pgm

Batch query example:

pgm -A -f vm-shopbase 'cat /home/admin/shopbase/logs/shopbase.log.2017-01-17|grep 2069861630'

tsar

Alibaba's own metrics collector, useful for historical and real‑time data:

tsar          # view recent day metrics
tsar --live   # live view, refresh every 5 seconds
tsar -d 20161218   # query a specific day (up to ~4 months)
tsar --memtsar --loadtsar --cpu   # query single metric, can combine with -d
tsar screenshot
tsar screenshot

Java Runtime Debugging Tools

btrace

Dynamic bytecode injection for tracing:

@OnMethod(clazz = "java.util.ArrayList", method = "add", location = @Location(value = Kind.CALL, clazz = "/.*/", method = "/.*/"))
public static void m(@ProbeClassName String probeClass, @ProbeMethodName String probeMethod, @TargetInstance Object instance, @TargetMethodOrField String method) {
    if (getInt(field("java.util.ArrayList", "size"), instance) > 479) {
        println("check who ArrayList.add method:" + probeClass + "#" + probeMethod + ", method:" + method + ", size:" + getInt(field("java.util.ArrayList", "size"), instance));
        jstack();
        println();
        println("===========================");
        println();
    }
}

Monitor method parameters and return values:

@OnMethod(clazz = "com.taobao.sellerhome.transfer.biz.impl.C2CApplyerServiceImpl", method = "nav", location = @Location(value = Kind.RETURN))
public static void mt(long userId, int current, int relation, String check, String redirectUrl, @Return AnyType result) {
    println("parameter# userId:" + userId + ", current:" + current + ", relation:" + relation + ", check:" + check + ", redirectUrl:" + redirectUrl + ", result:" + result);
}

Greys

Utility for class inspection and tracing (some commands overlap with btrace):

sc -df xxx               # show class details, source location, classloader
trace class method       # print method call times and breakdown

Related tools: Arthas (built on Greys).

javOSize

Injects bytecode to modify class content at runtime, e.g., adding temporary logging:

classes   # modify class to add logging instantly

Arthas

Alibaba's open‑source troubleshooting tool. See GitHub for details.

JProfiler

Commercial profiler, now often replaced by Greys and btrace for production debugging.

Additional Java Diagnostic Utilities

eclipse MAT

Memory analyzer tool, available as an Eclipse plugin or standalone application.

zprofiler

Internal Alibaba profiler widely used within the company.

Core JDK Tools

jps

sudo -u admin /opt/taobao/java/bin/jps -mlvV

jstack

sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jstack 2815
sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jstack -m 2815

jinfo

sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jinfo -flags 2815

jmap

Heap inspection and dump:

sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jmap -heap 2815
sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jmap -dump:live,format=b,file=/tmp/heap2.bin 2815
sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jmap -histo 2815 | head -10

jstat

sudo -u admin /opt/taobao/install/ajdk-8_1_1_fp1-b52/bin/jstat -gcutil 2815 1000

jdb

sudo -u admin /opt/taobao/java/bin/jdb -attach 8000

CHLSDB

sudo -u admin /opt/taobao/java/bin/java -classpath /opt/taobao/java/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB

IntelliJ IDEA Plugins

Key Promoter

Helps you learn keyboard shortcuts by prompting the corresponding shortcut when you use a menu action.

Maven Helper

Analyzes Maven dependencies and visualizes conflicts.

VM Options and Tips

-XX:+TraceClassLoading   # shows which JAR a class is loaded from
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/admin/logs/java.hprof

Resolving Jar Conflicts

Common commands to locate and list class‑loader information:

mvn dependency:tree > ~/dependency.txt
mvn dependency:tree -Dverbose -Dincludes=groupId:artifactId
-XX:+TraceClassLoading   # add to startup script
-verbose                 # show class loading details
greys:sc                # Greys command to locate class source
curl http://localhost:8006/classloader/locate?class=org.apache.xerces.xs.XSObject
curl http://localhost:8006/classloader/jars

Other Useful Tools

gpref

Reference: http://www.atatech.org/articles/33317

dmesg

Check kernel messages for OOM killer events:

sudo dmesg | grep -i kill | less

Example OOM‑killer log snippet and conversion formula for timestamps are provided.

Images

ALI‑TOMCAT classloader info
ALI‑TOMCAT classloader info
jps output
jps output
jstack output
jstack output
jstack -m output
jstack -m output
jinfo flags
jinfo flags
jmap heap
jmap heap
jmap histogram
jmap histogram
jstat gcutil
jstat gcutil
jdb attach
jdb attach
dmesg OOM killer
dmesg OOM killer

}

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.