Skip to content

Commit

Permalink
rebased latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
kcrimson committed Jun 24, 2024
1 parent 295783a commit 2b7069c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public final class AsyncProfilerDelegate implements ProfilerDelegate {
private final AsyncProfiler instance = PyroscopeAsyncProfiler.getAsyncProfiler();

public AsyncProfilerDelegate(Config config) {
reset(config);
setConfig(config);
}

@Override
public void reset(final Config config) {
public void setConfig(final Config config) {
this.config = config;
this.alloc = config.profilingAlloc;
this.lock = config.profilingLock;
Expand Down
39 changes: 16 additions & 23 deletions agent/src/main/java/io/pyroscope/javaagent/CurrentPidProvider.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
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);
}
public static long getCurrentProcessId() {
return ProcessHandle.current().pid();
// 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);
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.pyroscope.javaagent.impl;

import io.pyroscope.javaagent.AsyncProfilerDelegate;
import io.pyroscope.javaagent.ProfilerDelegate;
import io.pyroscope.javaagent.Snapshot;
import io.pyroscope.javaagent.api.Exporter;
Expand Down Expand Up @@ -30,7 +29,7 @@ public class ContinuousProfilingScheduler implements ProfilingScheduler {
private Instant profilingIntervalStartTime;
private ScheduledFuture<?> job;
private boolean started;
private Profiler profiler;
private ProfilerDelegate profiler;

public ContinuousProfilingScheduler(Config config, Exporter exporter, Logger logger) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void start(ProfilerDelegate profiler) {
final EventType t = config.samplingEventOrder.get(i);
final Config tmp = isolate(t, config);
logger.log(Logger.Level.DEBUG, "Config for %s ordinal %d: %s", t.id, i, tmp);
profiler.reset(tmp);
profiler.setConfig(tmp);
dumpProfile(profiler, samplingDurationMillis, uploadInterval);
}
} :
Expand Down

0 comments on commit 2b7069c

Please sign in to comment.