Skip to content

Commit

Permalink
[GR-54323] Don't log CPUSampler error if the sampler is already closed.
Browse files Browse the repository at this point in the history
PullRequest: graal/17865
  • Loading branch information
jchalou committed May 31, 2024
2 parents a54a2c1 + 1675f2b commit 3c803f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CPUSampler create(Env env) {
private int nextContextIndex;
private final Map<TruffleContext, Integer> activeContexts = new WeakHashMap<>();
private final List<MutableSamplerData> samplerData = new ArrayList<>();
private volatile boolean closed;
volatile boolean closed;
private volatile boolean collecting;
private long period = 10;
private long delay = 0;
Expand Down Expand Up @@ -531,7 +531,7 @@ public Map<Thread, List<StackTraceEntry>> takeSample(long timeout, TimeUnit time
}
if (!contexts.isEmpty()) {
Map<Thread, List<StackTraceEntry>> stacks = new HashMap<>();
List<StackSample> sample = safepointStackSampler.sample(env, contexts, !sampleContextInitialization, timeout, timeoutUnit);
List<StackSample> sample = safepointStackSampler.sample(this, env, contexts, !sampleContextInitialization, timeout, timeoutUnit);
for (StackSample stackSample : sample) {
stacks.put(stackSample.thread, stackSample.stack);
}
Expand Down Expand Up @@ -819,7 +819,7 @@ public void run() {
synchronized (CPUSampler.this) {
data = samplerData.get(activeContexts.get(context));
}
List<StackSample> samples = safepointStackSampler.sample(env, Collections.singletonMap(context, data), !sampleContextInitialization, period,
List<StackSample> samples = safepointStackSampler.sample(CPUSampler.this, env, Collections.singletonMap(context, data), !sampleContextInitialization, period,
TimeUnit.MILLISECONDS);
resultsToProcess.add(new SamplingResult(samples, context, taskStartTime));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private StackVisitor fetchStackVisitor() {
return visitor;
}

List<StackSample> sample(Env env, Map<TruffleContext, CPUSampler.MutableSamplerData> contexts, boolean useSyntheticFrames, long timeout, TimeUnit timeoutUnit) {
List<StackSample> sample(CPUSampler cpuSampler, Env env, Map<TruffleContext, CPUSampler.MutableSamplerData> contexts, boolean useSyntheticFrames, long timeout, TimeUnit timeoutUnit) {
long startNanos = System.nanoTime();
SampleAction action = cachedAction.getAndSet(null);
if (action == null) {
Expand Down Expand Up @@ -120,9 +120,18 @@ List<StackSample> sample(Env env, Map<TruffleContext, CPUSampler.MutableSamplerD
if (!incompleteSample && timeElapsed < timeoutNanos) {
try {
futureEntry.getValue().get(timeout, timeoutUnit);
} catch (InterruptedException | ExecutionException e) {
} catch (ExecutionException e) {
env.getLogger(getClass()).log(Level.SEVERE, "Sampling error", e);
incompleteSample = true;
} catch (InterruptedException e) {
/*
* Closing the CPUSampler during shutdown of the instrument sends interrupt to
* the sampling thread, which is expected, and so we don't log it.
*/
if (!cpuSampler.closed) {
env.getLogger(getClass()).log(Level.SEVERE, "Sampling interrupted", e);
}
incompleteSample = true;
} catch (TimeoutException e) {
future.cancel(false);
contexts.get(context).missedSamples.incrementAndGet();
Expand Down

0 comments on commit 3c803f6

Please sign in to comment.