Skip to content

Commit

Permalink
periodic-sched: fix file leak and reuse a single file (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershafir authored Feb 6, 2024
1 parent e435a88 commit b66c278
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions agent/src/main/java/io/pyroscope/javaagent/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ public final class Profiler {
private final AsyncProfiler instance = PyroscopeAsyncProfiler.getAsyncProfiler();

Profiler(Config config) {
setConfig(config);
reset(config);
}

public void setConfig(final Config config) {
public void reset(final Config config) {
this.config = config;
this.alloc = config.profilingAlloc;
this.lock = config.profilingLock;
this.eventType = config.profilingEvent;
this.interval = config.profilingInterval;
this.format = config.format;

if (format == Format.JFR) {
if (format == Format.JFR && null == tempJFRFile) {
try {
// flight recorder is built on top of a file descriptor, so we need a file.
tempJFRFile = File.createTempFile("pyroscope", ".jfr");
tempJFRFile.deleteOnExit();
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
tempJFRFile = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void start(Profiler 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.setConfig(tmp);
profiler.reset(tmp);
dumpProfile(profiler, samplingDurationMillis, uploadInterval);
}
} :
Expand Down

0 comments on commit b66c278

Please sign in to comment.