-
-
Notifications
You must be signed in to change notification settings - Fork 459
Profiling - OTEL profiling fix, Stabilization, Logging #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1cb3cad
d9790e3
b86145b
9b4d2e1
732894f
cde0eb1
c694f0c
9f941dd
e45ee44
797f468
b882020
d9fc89e
ecc0215
ab9b950
16ad3ac
eb6a942
0b1ea35
802e79e
2295cba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package io.sentry.asyncprofiler.convert; | ||
|
||
import io.sentry.DateUtils; | ||
import io.sentry.ILogger; | ||
import io.sentry.Sentry; | ||
import io.sentry.SentryLevel; | ||
import io.sentry.SentryStackTraceFactory; | ||
import io.sentry.asyncprofiler.vendor.asyncprofiler.convert.Arguments; | ||
import io.sentry.asyncprofiler.vendor.asyncprofiler.convert.JfrConverter; | ||
|
@@ -24,16 +26,22 @@ | |
|
||
public final class JfrAsyncProfilerToSentryProfileConverter extends JfrConverter { | ||
private static final double NANOS_PER_SECOND = 1_000_000_000.0; | ||
private static final long UNKNOWN_THREAD_ID = -1; | ||
|
||
private final @NotNull SentryProfile sentryProfile = new SentryProfile(); | ||
private final @NotNull SentryStackTraceFactory stackTraceFactory; | ||
private final @NotNull ILogger logger; | ||
private final @NotNull Map<SentryStackFrame, Integer> frameDeduplicationMap = new HashMap<>(); | ||
private final @NotNull Map<List<Integer>, Integer> stackDeduplicationMap = new HashMap<>(); | ||
|
||
public JfrAsyncProfilerToSentryProfileConverter( | ||
JfrReader jfr, Arguments args, @NotNull SentryStackTraceFactory stackTraceFactory) { | ||
JfrReader jfr, | ||
Arguments args, | ||
@NotNull SentryStackTraceFactory stackTraceFactory, | ||
@NotNull ILogger logger) { | ||
super(jfr, args); | ||
this.stackTraceFactory = stackTraceFactory; | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
|
@@ -60,7 +68,9 @@ protected EventCollector createCollector(Arguments args) { | |
|
||
SentryStackTraceFactory stackTraceFactory = | ||
new SentryStackTraceFactory(Sentry.getGlobalScope().getOptions()); | ||
converter = new JfrAsyncProfilerToSentryProfileConverter(jfrReader, args, stackTraceFactory); | ||
ILogger logger = Sentry.getGlobalScope().getOptions().getLogger(); | ||
converter = | ||
new JfrAsyncProfilerToSentryProfileConverter(jfrReader, args, stackTraceFactory, logger); | ||
converter.convert(); | ||
} | ||
|
||
|
@@ -88,25 +98,32 @@ public ProfileEventVisitor( | |
|
||
@Override | ||
public void visit(Event event, long samples, long value) { | ||
StackTrace stackTrace = jfr.stackTraces.get(event.stackTraceId); | ||
long threadId = resolveThreadId(event.tid); | ||
try { | ||
StackTrace stackTrace = jfr.stackTraces.get(event.stackTraceId); | ||
long threadId = resolveThreadId(event.tid); | ||
|
||
if (stackTrace != null) { | ||
if (args.threads) { | ||
processThreadMetadata(event, threadId); | ||
} | ||
if (stackTrace != null) { | ||
if (args.threads) { | ||
processThreadMetadata(event, threadId); | ||
} | ||
|
||
processSampleWithStack(event, threadId, stackTrace); | ||
processSampleWithStack(event, threadId, stackTrace); | ||
} | ||
} catch (Exception e) { | ||
logger.log(SentryLevel.WARNING, "Failed to process JFR event " + event, e); | ||
} | ||
} | ||
|
||
private long resolveThreadId(int eventThreadId) { | ||
return jfr.threads.get(eventThreadId) != null | ||
? jfr.javaThreads.get(eventThreadId) | ||
: eventThreadId; | ||
private long resolveThreadId(int eventId) { | ||
Long javaThreadId = jfr.javaThreads.get(eventId); | ||
return javaThreadId != null ? javaThreadId : UNKNOWN_THREAD_ID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Thread ID Resolution IssueThe |
||
} | ||
|
||
private void processThreadMetadata(Event event, long threadId) { | ||
if (threadId == UNKNOWN_THREAD_ID) { | ||
return; | ||
} | ||
|
||
final String threadName = getPlainThreadName(event.tid); | ||
sentryProfile | ||
.getThreadMetadata() | ||
|
@@ -167,7 +184,6 @@ private List<Integer> createFramesAndCallStack(StackTrace stackTrace) { | |
} | ||
|
||
SentryStackFrame frame = createStackFrame(element); | ||
frame.setNative(isNativeFrame(types[i])); | ||
int frameIndex = getOrAddFrame(frame); | ||
callStack.add(frameIndex); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Vendored AsyncProfiler code for converting JFR Files | ||
- Vendored-in from commit fe1bc66d4b6181413847f6bbe5c0db805f3e9194 of repository: git@github.com:async-profiler/async-profiler.git | ||
- Vendored-in from commit https://github.com/async-profiler/async-profiler/tree/fe1bc66d4b6181413847f6bbe5c0db805f3e9194 | ||
- Only the code related to JFR conversion is included. | ||
- The `AsyncProfiler` itself is included as a dependency in the Maven project. |
Uh oh!
There was an error while loading. Please reload this page.