Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package com.splunk.opentelemetry.profiler.snapshot;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;

class AccumulatingStagingArea implements StagingArea {
private final ConcurrentMap<String, List<StackTrace>> stackTraces = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Queue<StackTrace>> stackTraces = new ConcurrentHashMap<>();
private final Supplier<StackTraceExporter> exporter;

AccumulatingStagingArea(Supplier<StackTraceExporter> exporter) {
Expand All @@ -36,7 +37,7 @@ public void stage(String traceId, StackTrace stackTrace) {
traceId,
(id, stackTraces) -> {
if (stackTraces == null) {
stackTraces = new ArrayList<>();
stackTraces = new ConcurrentLinkedQueue<>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When empty is called before the last stage from the schedule then you will end up leaking a map entry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurit yes, though not a thread-safety issue and not introduced by this PR.

}
stackTraces.add(stackTrace);
return stackTraces;
Expand All @@ -45,9 +46,9 @@ public void stage(String traceId, StackTrace stackTrace) {

@Override
public void empty(String traceId) {
List<StackTrace> stackTraces = this.stackTraces.remove(traceId);
Queue<StackTrace> stackTraces = this.stackTraces.remove(traceId);
if (stackTraces != null) {
exporter.get().export(stackTraces);
exporter.get().export(new ArrayList<>(stackTraces));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you made the StackTraceExporter accept a Collection than you could skip the copy.

}
}
}