Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -16,14 +16,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 +36,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,7 +45,7 @@ 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.splunk.opentelemetry.profiler.exporter.PprofCpuEventExporter;
import io.opentelemetry.api.logs.Logger;
import java.time.Duration;
import java.util.List;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
Expand All @@ -42,11 +42,11 @@ class AsyncStackTraceExporter implements StackTraceExporter {
}

@Override
public void export(List<StackTrace> stackTraces) {
public void export(Collection<StackTrace> stackTraces) {
executor.submit(pprofExporter(otelLogger, stackTraces));
}

private Runnable pprofExporter(Logger otelLogger, List<StackTrace> stackTraces) {
private Runnable pprofExporter(Logger otelLogger, Collection<StackTrace> stackTraces) {
return () -> {
try {
CpuEventExporter cpuEventExporter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.splunk.opentelemetry.profiler.snapshot;

import java.util.List;
import java.util.Collection;

/** Works in concert with the {@link StagingArea} to export a batch of {@link StackTrace}s */
interface StackTraceExporter {
StackTraceExporter NOOP = stackTraces -> {};

void export(List<StackTrace> stackTraces);
void export(Collection<StackTrace> stackTraces);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.splunk.opentelemetry.profiler.snapshot;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand All @@ -28,7 +29,7 @@ class InMemoryStackTraceExporter implements StackTraceExporter {
private final List<StackTrace> stackTraces = new ArrayList<>();

@Override
public void export(List<StackTrace> stackTraces) {
public void export(Collection<StackTrace> stackTraces) {
this.stackTraces.addAll(stackTraces);
}

Expand Down