From b401020f1de7aea36b3c28c82b78a330dd5b9034 Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 27 Dec 2024 18:32:50 +0900 Subject: [PATCH] [#noissue] Cleanup Agent boot log --- .../pinpoint/bootstrap/PinpointBootStrap.java | 5 +++- .../pinpoint/bootstrap/PinpointStarter.java | 5 +++- .../AgentDirBaseClassPathResolver.java | 2 +- .../pinpoint/bootstrap/agentdir/BootDir.java | 2 +- .../bootstrap/agentdir/FileUtils.java | 13 ++++++++- .../bootstrap/agentdir/FileUtilsTest.java | 27 +++++++++++++++++++ 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtilsTest.java diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java index 282d62b1a258..68d75512593e 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java @@ -21,12 +21,14 @@ import com.navercorp.pinpoint.bootstrap.agentdir.AgentDirectory; import com.navercorp.pinpoint.bootstrap.agentdir.BootDir; import com.navercorp.pinpoint.bootstrap.agentdir.ClassPathResolver; +import com.navercorp.pinpoint.bootstrap.agentdir.FileUtils; import com.navercorp.pinpoint.bootstrap.agentdir.JavaAgentPathResolver; import com.navercorp.pinpoint.bootstrap.config.DisableOptions; import java.lang.instrument.Instrumentation; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Objects; @@ -146,7 +148,8 @@ private Map argsToMap(String agentArgs) { private void appendToBootstrapClassLoader(Instrumentation instrumentation, BootDir bootDir) { List jarFiles = bootDir.openJarFiles(); for (JarFile jarFile : jarFiles) { - logger.info("appendToBootstrapClassLoader:" + jarFile.getName()); + Path path = FileUtils.subpathAfter(Paths.get(jarFile.getName()), 2); + logger.info("appendToBootstrapClassLoader:" + path); instrumentation.appendToBootstrapClassLoaderSearch(jarFile); } } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java index f73f151dadfc..2b40fdcbd18e 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java @@ -16,6 +16,7 @@ import com.navercorp.pinpoint.ProductInfo; import com.navercorp.pinpoint.bootstrap.agentdir.AgentDirectory; +import com.navercorp.pinpoint.bootstrap.agentdir.FileUtils; import com.navercorp.pinpoint.bootstrap.classloader.PinpointClassLoaderFactory; import com.navercorp.pinpoint.bootstrap.classloader.ProfilerLibs; import com.navercorp.pinpoint.bootstrap.config.AgentSystemConfig; @@ -237,8 +238,10 @@ private URL[] resolveLib(AgentDirectory classPathResolver) { if (logger.isInfoEnabled()) { logger.info(String.format("agent JarPath:%s", agentJarFullPath)); logger.info(String.format("agent LibDir:%s", agentLibPath)); + int agentLibNameCount = agentLibPath.getNameCount() - 1; for (Path url : libUrlList) { - logger.info(String.format("agent Lib:%s", url)); + Path subpath = FileUtils.subpath(url, agentLibNameCount); + logger.info(String.format("agent lib:%s", subpath)); } logger.info(String.format("agent config:%s", agentConfigPath)); } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/AgentDirBaseClassPathResolver.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/AgentDirBaseClassPathResolver.java index 7e8b4ab25b16..c7216475e8ad 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/AgentDirBaseClassPathResolver.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/AgentDirBaseClassPathResolver.java @@ -162,7 +162,7 @@ private List resolvePlugins(Path agentPluginPath) { List pluginFileList = filterReadPermission(jars); for (Path pluginJar : pluginFileList) { - logger.info("Found plugins:" + pluginJar); + logger.info("plugin path:" + FileUtils.subpathAfter(pluginJar, 2)); } return pluginFileList; } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/BootDir.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/BootDir.java index abb0323884f4..44b038e613ee 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/BootDir.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/BootDir.java @@ -74,7 +74,7 @@ private Path find(List jarFiles, final JarDescription jarDescription) { } if (jarPathList.size() == 1) { final Path file = jarPathList.get(0); - logger.info("found " + jarName + " path:" + file); + logger.info("boot path:" + FileUtils.subpathAfter(file, 2)); return FileUtils.toRealPath(file); } diff --git a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtils.java b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtils.java index 9fbadcca3b61..9f294d0fa658 100644 --- a/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtils.java +++ b/agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtils.java @@ -30,7 +30,7 @@ /** * @author Woonduk Kang(emeroad) */ -final class FileUtils { +public final class FileUtils { private static final BootLogger logger = BootLogger.getLogger(FileUtils.class); @@ -52,6 +52,17 @@ public static List listFiles(Path dirPath, String glob) { } } + public static Path subpathAfter(Path path, int lastIndex) { + int end = path.getNameCount(); + int begin = end - Math.min(end, lastIndex); + return path.subpath(begin, end); + } + + public static Path subpath(Path path, int beginIndex) { + int end = path.getNameCount(); + int begin = Math.min(beginIndex, end); + return path.subpath(begin, end); + } public static Path toRealPath(Path path) { try { diff --git a/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtilsTest.java b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtilsTest.java new file mode 100644 index 000000000000..98b893e56a2a --- /dev/null +++ b/agent-module/bootstraps/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/agentdir/FileUtilsTest.java @@ -0,0 +1,27 @@ +package com.navercorp.pinpoint.bootstrap.agentdir; + +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class FileUtilsTest { + + @Test + void subpathAfter() { + Path path = Paths.get("a", "b", "c", "d", "e"); + Path lastPath = FileUtils.subpathAfter(path, 2); + assertEquals(Paths.get("d", "e"), lastPath); + } + + @Test + void subpath() { + Path path = Paths.get("a", "b", "c", "d", "e"); + String str = "a/b/c/d/e"; + Path lastPath = FileUtils.subpath(path, 2); + assertEquals(Paths.get("c", "d", "e"), lastPath); + + } +} \ No newline at end of file