mirror of
https://gitee.com/arthas/arthas.git
synced 2024-12-02 04:08:34 +08:00
Upgrade Async Profiler API to v2.9 (#2608)
This commit is contained in:
parent
4dc65baf7f
commit
ede902329d
3
.gitignore
vendored
3
.gitignore
vendored
@ -25,3 +25,6 @@ pom.xml.versionsBackup
|
|||||||
**/.flattened-pom.xml
|
**/.flattened-pom.xml
|
||||||
**/.idea/**
|
**/.idea/**
|
||||||
**/cmake-build-debug/**
|
**/cmake-build-debug/**
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode/
|
@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package one.profiler;
|
package one.profiler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java API for in-process profiling. Serves as a wrapper around
|
* Java API for in-process profiling. Serves as a wrapper around
|
||||||
@ -39,14 +42,79 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libPath == null) {
|
AsyncProfiler profiler = new AsyncProfiler();
|
||||||
System.loadLibrary("asyncProfiler");
|
if (libPath != null) {
|
||||||
} else {
|
|
||||||
System.load(libPath);
|
System.load(libPath);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
// No need to load library, if it has been preloaded with -agentpath
|
||||||
|
profiler.getVersion();
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
File file = extractEmbeddedLib();
|
||||||
|
if (file != null) {
|
||||||
|
try {
|
||||||
|
System.load(file.getPath());
|
||||||
|
} finally {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.loadLibrary("asyncProfiler");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = new AsyncProfiler();
|
instance = profiler;
|
||||||
return instance;
|
return profiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File extractEmbeddedLib() {
|
||||||
|
String resourceName = "/" + getPlatformTag() + "/libasyncProfiler.so";
|
||||||
|
InputStream in = AsyncProfiler.class.getResourceAsStream(resourceName);
|
||||||
|
if (in == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String extractPath = System.getProperty("one.profiler.extractPath");
|
||||||
|
File file = File.createTempFile("libasyncProfiler-", ".so",
|
||||||
|
extractPath == null || extractPath.isEmpty() ? null : new File(extractPath));
|
||||||
|
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||||
|
byte[] buf = new byte[32000];
|
||||||
|
for (int bytes; (bytes = in.read(buf)) >= 0; ) {
|
||||||
|
out.write(buf, 0, bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPlatformTag() {
|
||||||
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
|
String arch = System.getProperty("os.arch").toLowerCase();
|
||||||
|
if (os.contains("linux")) {
|
||||||
|
if (arch.equals("amd64") || arch.equals("x86_64") || arch.contains("x64")) {
|
||||||
|
return "linux-x64";
|
||||||
|
} else if (arch.equals("aarch64") || arch.contains("arm64")) {
|
||||||
|
return "linux-arm64";
|
||||||
|
} else if (arch.equals("aarch32") || arch.contains("arm")) {
|
||||||
|
return "linux-arm32";
|
||||||
|
} else if (arch.contains("86")) {
|
||||||
|
return "linux-x86";
|
||||||
|
} else if (arch.contains("ppc64")) {
|
||||||
|
return "linux-ppc64le";
|
||||||
|
}
|
||||||
|
} else if (os.contains("mac")) {
|
||||||
|
return "macos";
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException("Unsupported platform: " + os + "-" + arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,7 +277,10 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private native void start0(String event, long interval, boolean reset) throws IllegalStateException;
|
private native void start0(String event, long interval, boolean reset) throws IllegalStateException;
|
||||||
|
|
||||||
private native void stop0() throws IllegalStateException;
|
private native void stop0() throws IllegalStateException;
|
||||||
|
|
||||||
private native String execute0(String command) throws IllegalArgumentException, IllegalStateException, IOException;
|
private native String execute0(String command) throws IllegalArgumentException, IllegalStateException, IOException;
|
||||||
|
|
||||||
private native void filterThread0(Thread thread, boolean enable);
|
private native void filterThread0(Thread thread, boolean enable);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* from https://github.com/jvm-profiling-tools/async-profiler
|
* This package is from https://github.com/async-profiler/async-profiler/
|
||||||
|
* tag v2.9 commit 32601bc
|
||||||
*/
|
*/
|
||||||
package one.profiler;
|
package one.profiler;
|
Loading…
Reference in New Issue
Block a user