Skip to content

Commit 1e998bd

Browse files
committed
change profiler api from Path to String to keep Android Api 21 compatibility
1 parent 3acbd63 commit 1e998bd

File tree

10 files changed

+30
-30
lines changed

10 files changed

+30
-30
lines changed

sentry-async-profiler/api/sentry-async-profiler.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public final class io/sentry/asyncprofiler/BuildConfig {
55

66
public final class io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverter : io/sentry/asyncprofiler/vendor/asyncprofiler/convert/JfrConverter {
77
public fun <init> (Lio/sentry/asyncprofiler/vendor/asyncprofiler/jfr/JfrReader;Lio/sentry/asyncprofiler/vendor/asyncprofiler/convert/Arguments;Lio/sentry/SentryStackTraceFactory;Lio/sentry/ILogger;)V
8-
public static fun convertFromFileStatic (Ljava/nio/file/Path;)Lio/sentry/protocol/profiling/SentryProfile;
8+
public static fun convertFromFileStatic (Ljava/lang/String;)Lio/sentry/protocol/profiling/SentryProfile;
99
}
1010

1111
public final class io/sentry/asyncprofiler/convert/NonAggregatingEventCollector : io/sentry/asyncprofiler/vendor/asyncprofiler/jfr/event/EventCollector {
@@ -41,7 +41,7 @@ public final class io/sentry/asyncprofiler/provider/AsyncProfilerProfileConverte
4141

4242
public final class io/sentry/asyncprofiler/provider/AsyncProfilerProfileConverterProvider$AsyncProfilerProfileConverter : io/sentry/IProfileConverter {
4343
public fun <init> ()V
44-
public fun convertFromFile (Ljava/nio/file/Path;)Lio/sentry/protocol/profiling/SentryProfile;
44+
public fun convertFromFile (Ljava/lang/String;)Lio/sentry/protocol/profiling/SentryProfile;
4545
}
4646

4747
public final class io/sentry/asyncprofiler/vendor/asyncprofiler/convert/Arguments {

sentry-async-profiler/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ plugins {
1212
}
1313

1414
tasks.withType<KotlinCompile>().configureEach {
15-
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
16-
kotlinOptions.languageVersion = libs.versions.kotlin.compatible.version.get()
15+
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
1716
}
1817

1918
kotlin { explicitApi() }

sentry-async-profiler/src/main/java/io/sentry/asyncprofiler/convert/JfrAsyncProfilerToSentryProfileConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.sentry.protocol.profiling.SentrySample;
1717
import io.sentry.protocol.profiling.SentryThreadMetadata;
1818
import java.io.IOException;
19-
import java.nio.file.Path;
2019
import java.util.ArrayList;
2120
import java.util.HashMap;
2221
import java.util.List;
@@ -54,10 +53,10 @@ protected EventCollector createCollector(Arguments args) {
5453
return new NonAggregatingEventCollector();
5554
}
5655

57-
public static @NotNull SentryProfile convertFromFileStatic(@NotNull Path jfrFilePath)
56+
public static @NotNull SentryProfile convertFromFileStatic(@NotNull String jfrFilePath)
5857
throws IOException {
5958
JfrAsyncProfilerToSentryProfileConverter converter;
60-
try (JfrReader jfrReader = new JfrReader(jfrFilePath.toString())) {
59+
try (JfrReader jfrReader = new JfrReader(jfrFilePath)) {
6160
Arguments args = new Arguments();
6261
args.cpu = false;
6362
args.wall = true;

sentry-async-profiler/src/main/java/io/sentry/asyncprofiler/provider/AsyncProfilerProfileConverterProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static final class AsyncProfilerProfileConverter implements IProfileConve
2525

2626
@Override
2727
public @NotNull io.sentry.protocol.profiling.SentryProfile convertFromFile(
28-
@NotNull java.nio.file.Path jfrFilePath) throws java.io.IOException {
28+
@NotNull String jfrFilePath) throws java.io.IOException {
2929
return JfrAsyncProfilerToSentryProfileConverter.convertFromFileStatic(jfrFilePath);
3030
}
3131
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import java.time.LocalDateTime
1717
import java.time.ZoneOffset
1818
import java.time.temporal.ChronoUnit
1919
import java.util.*
20-
import kotlin.io.path.Path
2120
import kotlin.math.absoluteValue
2221
import kotlin.test.AfterTest
2322
import kotlin.test.BeforeTest
@@ -95,7 +94,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
9594

9695
@Test
9796
fun `check number of samples for specific frame`() {
98-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
97+
val file = loadFile("async_profiler_test_sample.jfr")
9998

10099
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
101100
val tracingFilterFrame =
@@ -120,7 +119,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
120119

121120
@Test
122121
fun `check number of samples for specific thread`() {
123-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
122+
val file = loadFile("async_profiler_test_sample.jfr")
124123

125124
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
126125
val mainThread =
@@ -138,7 +137,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
138137

139138
@Test
140139
fun `check no duplicate frames`() {
141-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
140+
val file = loadFile("async_profiler_test_sample.jfr")
142141
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
143142

144143
val frameSet = sentryProfile.frames.toSet()
@@ -148,7 +147,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
148147

149148
@Test
150149
fun `convertFromFile with valid JFR returns populated SentryProfile`() {
151-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
150+
val file = loadFile("async_profiler_test_sample.jfr")
152151

153152
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
154153

@@ -158,7 +157,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
158157

159158
@Test
160159
fun `convertFromFile parses timestamps correctly`() {
161-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
160+
val file = loadFile("async_profiler_test_sample.jfr")
162161

163162
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
164163

@@ -184,7 +183,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
184183

185184
@Test
186185
fun `convertFromFile extracts thread metadata correctly`() {
187-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
186+
val file = loadFile("async_profiler_test_sample.jfr")
188187

189188
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
190189

@@ -211,7 +210,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
211210

212211
@Test
213212
fun `converter processes frames with complete information`() {
214-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
213+
val file = loadFile("async_profiler_test_sample.jfr")
215214

216215
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
217216

@@ -232,7 +231,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
232231

233232
@Test
234233
fun `converter marks in-app frames correctly`() {
235-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
234+
val file = loadFile("async_profiler_test_sample.jfr")
236235

237236
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
238237

@@ -269,7 +268,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
269268

270269
@Test
271270
fun `converter filters native methods`() {
272-
val file = Path(loadFile("async_profiler_test_sample.jfr"))
271+
val file = loadFile("async_profiler_test_sample.jfr")
273272

274273
val sentryProfile = fixture.getSut()!!.convertFromFile(file)
275274

@@ -286,7 +285,7 @@ class JfrAsyncProfilerToSentryProfileConverterTest {
286285

287286
@Test(expected = IOException::class)
288287
fun `convertFromFile with non-existent file throws IOException`() {
289-
val nonExistentFile = Path("/non/existent/file.jfr")
288+
val nonExistentFile = "/non/existent/file.jfr"
290289

291290
JfrAsyncProfilerToSentryProfileConverter.convertFromFileStatic(nonExistentFile)
292291
}

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public abstract interface class io/sentry/IPerformanceSnapshotCollector : io/sen
827827
}
828828

829829
public abstract interface class io/sentry/IProfileConverter {
830-
public abstract fun convertFromFile (Ljava/nio/file/Path;)Lio/sentry/protocol/profiling/SentryProfile;
830+
public abstract fun convertFromFile (Ljava/lang/String;)Lio/sentry/protocol/profiling/SentryProfile;
831831
}
832832

833833
public abstract interface class io/sentry/IReplayApi {

sentry/src/main/java/io/sentry/IProfileConverter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.sentry.protocol.profiling.SentryProfile;
44
import java.io.IOException;
5-
import java.nio.file.Path;
65
import org.jetbrains.annotations.ApiStatus;
76
import org.jetbrains.annotations.NotNull;
87

@@ -22,5 +21,5 @@ public interface IProfileConverter {
2221
* @throws IOException If an error occurs while reading or converting the file
2322
*/
2423
@NotNull
25-
SentryProfile convertFromFile(@NotNull Path jfrFilePath) throws IOException;
24+
SentryProfile convertFromFile(@NotNull String jfrFilePath) throws IOException;
2625
}

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
import java.io.BufferedWriter;
3434
import java.io.File;
3535
import java.io.FileOutputStream;
36-
import java.io.IOException;
3736
import java.io.OutputStream;
3837
import java.io.OutputStreamWriter;
3938
import java.io.Writer;
4039
import java.lang.reflect.InvocationTargetException;
4140
import java.nio.charset.Charset;
42-
import java.nio.file.Files;
4341
import java.util.Arrays;
4442
import java.util.List;
4543
import java.util.Properties;
@@ -698,8 +696,15 @@ private static void initJvmContinuousProfiling(@NotNull SentryOptions options) {
698696
try {
699697
String profilingTracesDirPath = options.getProfilingTracesDirPath();
700698
if (profilingTracesDirPath == null) {
701-
profilingTracesDirPath =
702-
Files.createTempDirectory("profiling_traces").toAbsolutePath().toString();
699+
File tempDir = new File(System.getProperty("java.io.tmpdir"), "sentry_profiling_traces");
700+
boolean createDirectorySuccess = tempDir.mkdirs();
701+
702+
if (!createDirectorySuccess) {
703+
throw new IllegalArgumentException(
704+
"Creating a fallback directory for profiling failed in "
705+
+ tempDir.getAbsolutePath());
706+
}
707+
profilingTracesDirPath = tempDir.getAbsolutePath();
703708
options.setProfilingTracesDirPath(profilingTracesDirPath);
704709
}
705710

@@ -711,7 +716,7 @@ private static void initJvmContinuousProfiling(@NotNull SentryOptions options) {
711716
options.getExecutorService());
712717

713718
options.setContinuousProfiler(continuousProfiler);
714-
} catch (IOException e) {
719+
} catch (Exception e) {
715720
options
716721
.getLogger()
717722
.log(SentryLevel.ERROR, "Failed to create default profiling traces directory", e);

sentry/src/main/java/io/sentry/SentryEnvelopeItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private static void ensureAttachmentSizeLimit(
301301
if (profileConverter != null) {
302302
try {
303303
final SentryProfile profile =
304-
profileConverter.convertFromFile(traceFile.toPath());
304+
profileConverter.convertFromFile(traceFile.getAbsolutePath());
305305
profileChunk.setSentryProfile(profile);
306306
} catch (Exception e) {
307307
throw new SentryEnvelopeException("Profile conversion failed");

sentry/src/test/java/io/sentry/profiling/ProfilingServiceLoaderTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import io.sentry.ProfileLifecycle
88
import io.sentry.TracesSampler
99
import io.sentry.protocol.SentryId
1010
import io.sentry.protocol.profiling.SentryProfile
11-
import java.nio.file.Path
1211
import kotlin.test.Test
1312
import org.mockito.kotlin.mock
1413

@@ -35,7 +34,7 @@ class JavaProfileConverterProviderStub : JavaProfileConverterProvider {
3534
}
3635

3736
class ProfileConverterStub() : IProfileConverter {
38-
override fun convertFromFile(jfrFilePath: Path): SentryProfile {
37+
override fun convertFromFile(jfrFilePath: String): SentryProfile {
3938
TODO("Not yet implemented")
4039
}
4140
}

0 commit comments

Comments
 (0)