Skip to content

Commit

Permalink
[#noissue] Cleanup Agent boot log
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Dec 27, 2024
1 parent d137565 commit b401020
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,7 +148,8 @@ private Map<String, String> argsToMap(String agentArgs) {
private void appendToBootstrapClassLoader(Instrumentation instrumentation, BootDir bootDir) {
List<JarFile> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private List<Path> resolvePlugins(Path agentPluginPath) {

List<Path> pluginFileList = filterReadPermission(jars);
for (Path pluginJar : pluginFileList) {
logger.info("Found plugins:" + pluginJar);
logger.info("plugin path:" + FileUtils.subpathAfter(pluginJar, 2));
}
return pluginFileList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private Path find(List<Path> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* @author Woonduk Kang(emeroad)
*/
final class FileUtils {
public final class FileUtils {

private static final BootLogger logger = BootLogger.getLogger(FileUtils.class);

Expand All @@ -52,6 +52,17 @@ public static List<Path> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
}

0 comments on commit b401020

Please sign in to comment.