From e1e15e8f61a13dcf28ca1ddb1cedd83800a0cf21 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Sat, 24 Nov 2018 22:43:13 +0800 Subject: [PATCH] as.sh support -v options. #130 --- bin/as.sh | 28 +++++++++++++++---- .../com/taobao/arthas/boot/Bootstrap.java | 4 +-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/bin/as.sh b/bin/as.sh index a5c2f9067..42e403a49 100755 --- a/bin/as.sh +++ b/bin/as.sh @@ -53,6 +53,9 @@ ATTACH_ONLY=false # pass debug arguments to the attach java process DEBUG_ATTACH=false +# Verbose, print debug info. +VERBOSE=false + # command to execute COMMAND= # batch file to execute @@ -364,6 +367,15 @@ update_if_necessary() fi } +call_jps() +{ + if [ "${VERBOSE}" = true ] ; then + "${JAVA_HOME}"/bin/jps -l -v + else + "${JAVA_HOME}"/bin/jps -l + fi +} + # the usage usage() { @@ -372,7 +384,7 @@ Usage: $0 [-h] [--target-ip ] [--telnet-port ] [--http-port ] [--session-timeout ] [--arthas-home ] [--use-version ] [--repo-mirror ] [--versions] [--use-http] - [--attach-only] [-c ] [-f ] [pid] + [--attach-only] [-c ] [-f ] [-v] [pid] Options and Arguments: -h,--help Print usage @@ -386,11 +398,13 @@ Options and Arguments: center/aliyun or http repo url. --versions List local and remote arthas versions --use-http Enforce use http to download, default use https - --attach-only attach target process only, do not connect + --attach-only Attach target process only, do not connect + --debug-attach Debug attach agent -c,--command Command to execute, multiple commands separated by ; -f,--batch-file The batch file to execute - target pid + -v,--verbose Verbose, print debug info. + Target pid EXAMPLES: ./as.sh @@ -408,7 +422,7 @@ WIKI: Here is the list of possible java process(es) to attatch: " -"${JAVA_HOME}"/bin/jps -l | grep -v sun.tools.jps.Jps +$(call_jps) | grep -v sun.tools.jps.Jps } @@ -516,6 +530,10 @@ parse_arguments() ARTHAS_OPTS="$JPDA_OPTS $ARTHAS_OPTS" shift # past argument ;; + -v|--verbose) + VERBOSE=true + shift # past argument + ;; --default) DEFAULT=YES shift # past argument @@ -560,7 +578,7 @@ parse_arguments() if [ -z ${TARGET_PID} ] && [ ${BATCH_MODE} = false ]; then # interactive mode local IFS=$'\n' - CANDIDATES=($("${JAVA_HOME}"/bin/jps -l | grep -v sun.tools.jps.Jps | awk '{print $0}')) + CANDIDATES=($(call_jps | grep -v sun.tools.jps.Jps | awk '{print $0}')) if [ ${#CANDIDATES[@]} -eq 0 ]; then echo "Error: no available java process to attach." diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index 3e8617a5a..8eb19defb 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -102,7 +102,7 @@ public class Bootstrap { private String batchFile; @Argument(argName = "pid", index = 0, required = false) - @Description("target pid") + @Description("Target pid") public void setPid(int pid) { this.pid = pid; } @@ -168,7 +168,7 @@ public class Bootstrap { } @Option(longName = "attach-only", flag = true) - @Description("attach target process only, do not connect") + @Description("Attach target process only, do not connect") public void setAttachOnly(boolean attachOnly) { this.attachOnly = attachOnly; }