-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8757844
commit 3d3e4f2
Showing
5 changed files
with
98 additions
and
66 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
agent/src/main/java/io/pyroscope/javaagent/CurrentPidProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.pyroscope.javaagent; | ||
|
||
import sun.management.VMManagement; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.RuntimeMXBean; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public class CurrentPidProvider { | ||
public static int getCurrentProcessId() { | ||
|
||
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); | ||
Field jvm = null; | ||
try { | ||
jvm = runtime.getClass().getDeclaredField("jvm"); | ||
jvm.setAccessible(true); | ||
|
||
VMManagement management = (VMManagement) jvm.get(runtime); | ||
Method method = management.getClass().getDeclaredMethod("getProcessId"); | ||
method.setAccessible(true); | ||
|
||
return (Integer) method.invoke(management); | ||
} catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
agent/src/main/java/io/pyroscope/javaagent/config/ProfilerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.pyroscope.javaagent.config; | ||
|
||
public enum ProfilerType { | ||
JFR, ASYNC; | ||
} |