diff --git a/common/src/main/java/com/taobao/arthas/common/PidUtils.java b/common/src/main/java/com/taobao/arthas/common/PidUtils.java index 41322e61..f13facd7 100644 --- a/common/src/main/java/com/taobao/arthas/common/PidUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/PidUtils.java @@ -1,6 +1,7 @@ package com.taobao.arthas.common; import java.lang.management.ManagementFactory; +import java.util.Map; /** * @@ -11,6 +12,8 @@ public class PidUtils { private static String PID = "-1"; private static long pid = -1; + private static String MAIN_CLASS = ""; + static { // https://stackoverflow.com/a/7690178 try { @@ -24,6 +27,16 @@ public class PidUtils { } catch (Throwable e) { // ignore } + + try { + for (final Map.Entry entry : System.getenv().entrySet()) { + if (entry.getKey().startsWith("JAVA_MAIN_CLASS")) // like JAVA_MAIN_CLASS_13328 + MAIN_CLASS = entry.getValue(); + } + } catch (Throwable e) { + // ignore + } + } private PidUtils() { @@ -36,4 +49,8 @@ public class PidUtils { public static long currentLongPid() { return pid; } + + public static String mainClass() { + return MAIN_CLASS; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java index 11bafd57..7147b5ce 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java @@ -10,6 +10,7 @@ public class WelcomeModel extends ResultModel { private String version; private String wiki; private String tutorials; + private String mainClass; public WelcomeModel() { } @@ -58,4 +59,12 @@ public class WelcomeModel extends ResultModel { public void setTutorials(String tutorials) { this.tutorials = tutorials; } + + public String getMainClass() { + return mainClass; + } + + public void setMainClass(String mainClass) { + this.mainClass = mainClass; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java index 23c3a8ae..38879460 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java @@ -286,6 +286,7 @@ public class HttpApiHandler { welcomeModel.setVersion(ArthasBanner.version()); welcomeModel.setWiki(ArthasBanner.wiki()); welcomeModel.setTutorials(ArthasBanner.tutorials()); + welcomeModel.setMainClass(PidUtils.mainClass()); welcomeModel.setPid(PidUtils.currentPid()); welcomeModel.setTime(DateUtils.getCurrentDate()); resultDistributor.appendResult(welcomeModel); diff --git a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java index 41b4dd04..1970ad05 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java @@ -114,6 +114,7 @@ public class ArthasBanner { .row("wiki", wiki()) .row("tutorials", tutorials()) .row("version", version()) + .row("main_class", PidUtils.mainClass()) .row("pid", PidUtils.currentPid()) .row("time", DateUtils.getCurrentDate()); for (Entry entry : infos.entrySet()) {