From dd7d9d16becf6c91c4fc946b2dae8f8b4328d875 Mon Sep 17 00:00:00 2001 From: "leix.xie" Date: Sat, 24 Aug 2019 04:08:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81spring=20boot=20=E5=9C=A8?= =?UTF-8?q?=E7=BA=BFdebug=E5=92=8C=E5=8A=A8=E6=80=81=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../instrument/InstrumentClientStore.java | 24 +++++---- .../attach/file/JarStorePathUtil.java | 51 +++++++++++++++++++ .../file/impl/JarFileServiceWrapper.java | 12 ++--- .../DefaultAppClassPathSupplier.java | 7 ++- .../classpath/WebAppClassPathSupplier.java | 8 ++- 5 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/JarStorePathUtil.java diff --git a/bistoury-attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas/instrument/InstrumentClientStore.java b/bistoury-attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas/instrument/InstrumentClientStore.java index 67b97f25..47d61172 100644 --- a/bistoury-attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas/instrument/InstrumentClientStore.java +++ b/bistoury-attach-arthas/src/main/java/qunar/tc/bistoury/attach/arthas/instrument/InstrumentClientStore.java @@ -70,34 +70,36 @@ public static synchronized void init(Instrumentation instrumentation) { ImmutableList.Builder builder = new ImmutableList.Builder<>(); + //jar debug放在最前面,因为在里面会对jar包启动的项目进行解压 try { - builder.add(QDebugClients.create(instrumentInfo)); + builder.add(JarDebugClients.create(instrumentInfo)); } catch (Exception e) { - logger.error("", "qdebug client init error", e); + logger.error("", "jar decompiler init error", e); } + try { - builder.add(QMonitorClients.create(instrumentInfo)); + builder.add(AppConfigClients.create(instrumentInfo)); } catch (Exception e) { - logger.error("", "qmonitor client init error", e); + logger.error("", "app config client init error", e); } try { - builder.add(JarInfoClients.create(instrumentInfo)); + builder.add(QDebugClients.create(instrumentInfo)); } catch (Exception e) { - logger.error("", "jar info client init error", e); + logger.error("", "qdebug client init error", e); } - try { - builder.add(AppConfigClients.create(instrumentInfo)); + builder.add(QMonitorClients.create(instrumentInfo)); } catch (Exception e) { - logger.error("", "app config client init error", e); + logger.error("", "qmonitor client init error", e); } try { - builder.add(JarDebugClients.create(instrumentInfo)); + builder.add(JarInfoClients.create(instrumentInfo)); } catch (Exception e) { - logger.error("", "jar decompiler init error", e); + logger.error("", "jar info client init error", e); } + clients = builder.build(); } diff --git a/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/JarStorePathUtil.java b/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/JarStorePathUtil.java new file mode 100644 index 00000000..6a49fc20 --- /dev/null +++ b/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/JarStorePathUtil.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Qunar, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package qunar.tc.bistoury.attach.file; + +import qunar.tc.bistoury.clientside.common.store.BistouryStore; + +import java.io.File; + +/** + * @author leix.xie + * @date 2019/8/24 01:27 + * @describe + */ +public class JarStorePathUtil { + + private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp"); + + static { + File file = new File(STORE_PATH); + if (!file.exists() || !file.isDirectory()) { + file.mkdirs(); + } + } + + public static String getJarStorePath() { + return new File(STORE_PATH).getPath(); + } + + public static String getJarLibPath() { + return System.getProperty("bistoury.jar.lib.path", new File(getJarStorePath(), "BOOT-INF/lib/").getPath()); + } + + public static String getJarSourcePath() { + return System.getProperty("bistoury.jar.source.path", new File(getJarStorePath(), "BOOT-INF/classes/").getPath()); + } +} diff --git a/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/impl/JarFileServiceWrapper.java b/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/impl/JarFileServiceWrapper.java index fa7ca74b..76127c42 100644 --- a/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/impl/JarFileServiceWrapper.java +++ b/bistoury-attach-common/src/main/java/qunar/tc/bistoury/attach/file/impl/JarFileServiceWrapper.java @@ -21,8 +21,8 @@ import com.google.common.io.Files; import com.taobao.middleware.logger.Logger; import qunar.tc.bistoury.attach.common.BistouryLoggger; +import qunar.tc.bistoury.attach.file.JarStorePathUtil; import qunar.tc.bistoury.attach.file.URLUtil; -import qunar.tc.bistoury.clientside.common.store.BistouryStore; import java.io.File; import java.io.InputStream; @@ -40,15 +40,10 @@ public class JarFileServiceWrapper { private static final Logger logger = BistouryLoggger.getLogger(); - private static final String STORE_PATH = BistouryStore.getStorePath("tomcat_webapp"); - private static final AtomicBoolean STARTED = new AtomicBoolean(false); public JarFileServiceWrapper() { - File file = new File(STORE_PATH); - if (!file.exists() || !file.isDirectory()) { - file.mkdirs(); - } + } /** @@ -58,8 +53,7 @@ public JarFileServiceWrapper() { * @return */ public String getJarPath(final String jarFile) { - final String jarFilePath = jarFile.substring(jarFile.lastIndexOf(File.separatorChar) + 1).replace(".jar", ""); - File file = new File(STORE_PATH, jarFilePath); + File file = new File(JarStorePathUtil.getJarStorePath()); if (!file.exists() || !file.isDirectory() || !STARTED.get()) { deleteDirectory(file); unPackJar(jarFile, file); diff --git a/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/DefaultAppClassPathSupplier.java b/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/DefaultAppClassPathSupplier.java index cb72c349..44d0a9be 100644 --- a/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/DefaultAppClassPathSupplier.java +++ b/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/DefaultAppClassPathSupplier.java @@ -19,6 +19,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; +import qunar.tc.bistoury.attach.file.JarStorePathUtil; import java.io.File; import java.util.Iterator; @@ -43,7 +44,11 @@ public DefaultAppClassPathSupplier(AppLibClassSupplier appLibClassSupplier) { String appSourcePath = System.getProperty("bistoury.app.classes.path"); if (!Strings.isNullOrEmpty(appSourcePath)) { - supplier = new SettableAppClassPathSupplier(ImmutableList.of(appLibPath, appSourcePath)); + //这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取 + String jarLibPath = JarStorePathUtil.getJarLibPath(); + String jarSourcePath = JarStorePathUtil.getJarSourcePath(); + ImmutableList list = ImmutableList.of(appLibPath, appSourcePath, jarLibPath, jarSourcePath); + supplier = new SettableAppClassPathSupplier(list); } else { Iterator factoryIterator = ServiceLoader.load(AppClassPathSupplierFactory.class).iterator(); if (factoryIterator.hasNext()) { diff --git a/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/WebAppClassPathSupplier.java b/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/WebAppClassPathSupplier.java index b28edcdd..aad95055 100644 --- a/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/WebAppClassPathSupplier.java +++ b/bistoury-instrument-client/src/main/java/qunar/tc/bistoury/instrument/client/classpath/WebAppClassPathSupplier.java @@ -18,6 +18,7 @@ package qunar.tc.bistoury.instrument.client.classpath; import com.google.common.collect.ImmutableList; +import qunar.tc.bistoury.attach.file.JarStorePathUtil; import java.io.File; import java.util.List; @@ -43,6 +44,11 @@ private List findClassPath(String appLibPath) { final File webRoot = libFile.getParentFile(); String sourcePath = new File(webRoot, "classes").getAbsolutePath(); String libPath = libFile.getAbsolutePath(); - return ImmutableList.of(sourcePath, libPath); + + //这两个路径用于spring boot,springboot会先将文件解压后放在缓存文件夹下,读取时可以从里面读取 + String jarLibPath = JarStorePathUtil.getJarLibPath(); + String jarSourcePath = JarStorePathUtil.getJarSourcePath(); + + return ImmutableList.of(sourcePath, libPath, jarLibPath, jarSourcePath); } } From 8fa5773be61377b0ed555fc241d205ccd807cde7 Mon Sep 17 00:00:00 2001 From: "leix.xie" Date: Sun, 25 Aug 2019 18:53:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9jvm=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E5=88=A0=E9=99=A4PrintGCDateStamps?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=9B=E4=BF=AE=E6=94=B9=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bistoury-dist/bin/bistoury-agent.sh | 2 +- bistoury-proxy/src/bin/bistoury-proxy.sh | 2 +- .../main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java | 1 - bistoury-ui/src/bin/bistoury-ui.sh | 2 +- .../src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bistoury-dist/bin/bistoury-agent.sh b/bistoury-dist/bin/bistoury-agent.sh index d9b912bb..238ddb80 100644 --- a/bistoury-dist/bin/bistoury-agent.sh +++ b/bistoury-dist/bin/bistoury-agent.sh @@ -41,7 +41,7 @@ if [[ -n $APP_PID ]]; then fi CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar" -JAVA_OPTS="$JAVA_OPTS -Dbistoury.app.lib.class=$BISTOURY_APP_LIB_CLASS -Xmx80m -Xmn50m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseCodeCacheFlushing -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" +JAVA_OPTS="$JAVA_OPTS -Dbistoury.app.lib.class=$BISTOURY_APP_LIB_CLASS -Xmx80m -Xmn50m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseCodeCacheFlushing -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-agent.pid" BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-agent.out" diff --git a/bistoury-proxy/src/bin/bistoury-proxy.sh b/bistoury-proxy/src/bin/bistoury-proxy.sh index 0cd0bcd8..90ebc453 100644 --- a/bistoury-proxy/src/bin/bistoury-proxy.sh +++ b/bistoury-proxy/src/bin/bistoury-proxy.sh @@ -25,7 +25,7 @@ else JAVA=java; fi CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar" -JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" +JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-proxy.pid" BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-proxy.out" diff --git a/bistoury-proxy/src/main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java b/bistoury-proxy/src/main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java index 1261c794..5a0533c4 100644 --- a/bistoury-proxy/src/main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java +++ b/bistoury-proxy/src/main/java/qunar/tc/bistoury/proxy/container/Bootstrap.java @@ -76,7 +76,6 @@ public static void main(String[] args) throws Exception { logger.info("Server配置加载完成,正在启动中..."); tomcat.start(); - logger.info("Server启动成功"); tomcat.getServer().await(); } catch (Exception e) { logger.error("Server启动失败...", e); diff --git a/bistoury-ui/src/bin/bistoury-ui.sh b/bistoury-ui/src/bin/bistoury-ui.sh index 54f097d8..05a9899f 100644 --- a/bistoury-ui/src/bin/bistoury-ui.sh +++ b/bistoury-ui/src/bin/bistoury-ui.sh @@ -25,7 +25,7 @@ else JAVA=java; fi CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/sa-jdi.jar" -JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" +JAVA_OPTS="$JAVA_OPTS -Xloggc:${BISTOURY_LOG_DIR}/bistoury-gc-${TIMESTAMP}.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BISTOURY_LOG_DIR}" BISTOURY_PID_FILE="$BISTOURY_PID_DIR/bistoury-ui.pid" BISTOURY_DAEMON_OUT="$BISTOURY_LOG_DIR/bistoury-ui.out" diff --git a/bistoury-ui/src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java b/bistoury-ui/src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java index 8b7d8867..9c06dd71 100644 --- a/bistoury-ui/src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java +++ b/bistoury-ui/src/main/java/qunar/tc/bistoury/ui/container/Bootstrap.java @@ -73,7 +73,6 @@ public static void main(String[] args) { logger.info("Server配置加载完成,正在启动中..."); tomcat.start(); - logger.info("Server启动成功"); tomcat.getServer().await(); } catch (Exception e) { logger.error("Server启动失败...", e);