Skip to content

Commit 885f0ab

Browse files
committed
adapt converter tests to new non-aggregated converter
1 parent 451f191 commit 885f0ab

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

sentry-async-profiler/src/main/java/io/sentry/asyncprofiler/profiling/JavaContinuousProfiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ private void start() {
220220
try {
221221
final String profilingIntervalMicros =
222222
String.format("%dus", (int) SECONDS.toMicros(1) / profilingTracesHz);
223+
// Example command: start,jfr,event=wall,interval=9900us,file=/path/to/trace.jfr
223224
final String command =
224-
String.format("start,jfr,wall=%s,file=%s", profilingIntervalMicros, filename);
225+
String.format("start,jfr,event=wall,interval=%s,file=%s", profilingIntervalMicros, filename);
225226

226227
profiler.execute(command);
227228

sentry-async-profiler/src/test/java/io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverterTest.kt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ import io.sentry.ILogger
44
import io.sentry.IProfileConverter
55
import io.sentry.IScope
66
import io.sentry.IScopes
7-
import io.sentry.JsonObjectReader
8-
import io.sentry.JsonObjectWriter
9-
import io.sentry.JsonSerializable
107
import io.sentry.Sentry
118
import io.sentry.SentryOptions
129
import io.sentry.SentryStackTraceFactory
1310
import io.sentry.TracesSampler
1411
import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
15-
import io.sentry.protocol.SentryStackFrame
1612
import io.sentry.protocol.profiling.SentryProfile
1713
import io.sentry.test.DeferredExecutorService
18-
import java.io.File
1914
import java.io.IOException
20-
import java.io.StringReader
21-
import java.io.StringWriter
2215
import kotlin.io.path.Path
2316
import kotlin.test.AfterTest
2417
import kotlin.test.BeforeTest
@@ -101,8 +94,8 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
10194
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
10295
val tracingFilterFrame =
10396
sentryProfile.frames.filter {
104-
it.function == "doFilterInternal" &&
105-
it.module == "io.sentry.spring.jakarta.tracing.SentryTracingFilter"
97+
it.function == "slowFunction" &&
98+
it.module == "io.sentry.samples.console.Main"
10699
}
107100

108101
val tracingFilterFrameIndexes = tracingFilterFrame.map { sentryProfile.frames.indexOf(it) }
@@ -112,8 +105,23 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
112105
val tracingFilterSamples =
113106
sentryProfile.samples.filter { tracingFilterStackIds.contains(it.stackId) }
114107

115-
// Sample Size 22 taken from intellij profiler with the JFR file
116-
assertEquals(22, tracingFilterSamples.size)
108+
// Sample size base on 101 samples/sec and 10 sec of profiling
109+
// So expected around 1010 samples (with some margin)
110+
assertTrue(tracingFilterSamples.count() >= 1000 && tracingFilterSamples.count() <= 1120, "Expected sample count between 1000 and 1120, but was ${tracingFilterSamples.count()}")
111+
}
112+
113+
@Test
114+
fun `check number of samples for specific thread`() {
115+
val file = Path(loadFile("async_profiler_test_sample.jfr"))
116+
117+
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
118+
val mainThread = sentryProfile.threadMetadata.entries.firstOrNull { it.value.name == "main" }?.key
119+
120+
val samples = sentryProfile.samples.filter { it.threadId == mainThread }
121+
122+
// Sample size base on 101 samples/sec and 10 sec of profiling
123+
// So expected around 1010 samples (with some margin)
124+
assertTrue(samples.count() >= 1000 && samples.count() <= 1120, "Expected sample count between 1000 and 1120, but was ${samples.count()}")
117125
}
118126

119127
@Test
@@ -202,7 +210,10 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
202210
// Find frames with complete information
203211
val completeFrames =
204212
frames.filter { frame ->
205-
frame.function != null && frame.module != null && frame.lineno != null && frame.filename != null
213+
frame.function != null &&
214+
frame.module != null &&
215+
frame.lineno != null &&
216+
frame.filename != null
206217
}
207218

208219
assertTrue(completeFrames.isNotEmpty(), "Should have frames with complete information")
Binary file not shown.

0 commit comments

Comments
 (0)