Skip to content
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

Re-apply NDK init performance improvements for 8.x.x #3914

Merged
merged 3 commits into from
Nov 21, 2024
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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

### Dependencies

- Bump Native SDK from v0.7.5 to v0.7.8 ([#3851](https://github.com/getsentry/sentry-java/pull/3851))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#078)
- [diff](https://github.com/getsentry/sentry-native/compare/0.7.5...0.7.8)
- Bump Native SDK from v0.7.5 to v0.7.14 ([#3851](https://github.com/getsentry/sentry-java/pull/3851)) ([#3914](https://github.com/getsentry/sentry-java/pull/3914))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0714)
- [diff](https://github.com/getsentry/sentry-native/compare/0.7.5...0.7.14)

### Behavioural Changes

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object Config {

val apolloKotlin = "com.apollographql.apollo3:apollo-runtime:3.8.2"

val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.7.8"
val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.7.14"

object OpenTelemetry {
val otelVersion = "1.41.0"
Expand Down
4 changes: 1 addition & 3 deletions scripts/update-sentry-native-ndk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
set -euo pipefail

cd $(dirname "$0")/../
GRADLE_NDK_FILEPATH=sentry-android-ndk/build.gradle.kts
GRADLE_SAMPLE_FILEPATH=sentry-samples/sentry-samples-android/build.gradle.kts
GRADLE_NDK_FILEPATH=buildSrc/src/main/java/Config.kt

case $1 in
get-version)
Expand All @@ -26,7 +25,6 @@ set-version)

PATTERN="io\.sentry:sentry-native-ndk:([0-9.]+)+"
perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_NDK_FILEPATH
perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_SAMPLE_FILEPATH
;;
*)
echo "Unknown argument $1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,84 @@
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.ndk.NativeModuleListLoader;
import io.sentry.ndk.NdkOptions;
import io.sentry.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

@ApiStatus.Internal
public final class SentryNdk {

private static final @NotNull CountDownLatch loadLibraryLatch = new CountDownLatch(1);

private SentryNdk() {}

static {
new Thread(
() -> {
try {
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.loadNativeLibraries();
} finally {
loadLibraryLatch.countDown();
}
},
"SentryNdkLoadLibs")
.start();
}

/**
* Init the NDK integration
*
* @param options the SentryAndroidOptions
*/
public static void init(@NotNull final SentryAndroidOptions options) {
SentryNdkUtil.addPackage(options.getSdkVersion());
try {
if (loadLibraryLatch.await(2000, TimeUnit.MILLISECONDS)) {
final @NotNull NdkOptions ndkOptions =
new NdkOptions(
Objects.requireNonNull(options.getDsn(), "DSN is required for sentry-ndk"),
options.isDebug(),
Objects.requireNonNull(
options.getOutboxPath(), "outbox path is required for sentry-ndk"),
options.getRelease(),
options.getEnvironment(),
options.getDist(),
options.getMaxBreadcrumbs(),
options.getNativeSdkName());

final @NotNull NdkOptions ndkOptions =
new NdkOptions(
options.getDsn(),
options.isDebug(),
options.getOutboxPath(),
options.getRelease(),
options.getEnvironment(),
options.getDist(),
options.getMaxBreadcrumbs(),
options.getNativeSdkName());
io.sentry.ndk.SentryNdk.init(ndkOptions);

// only add scope sync observer if the scope sync is enabled.
if (options.isEnableScopeSync()) {
options.addScopeObserver(new NdkScopeObserver(options));
}
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.init(ndkOptions);

options.setDebugImagesLoader(new DebugImagesLoader(options, new NativeModuleListLoader()));
// only add scope sync observer if the scope sync is enabled.
if (options.isEnableScopeSync()) {
options.addScopeObserver(new NdkScopeObserver(options));
}

options.setDebugImagesLoader(new DebugImagesLoader(options, new NativeModuleListLoader()));
} else {
throw new IllegalStateException("Timeout waiting for Sentry NDK library to load");
}
} catch (InterruptedException e) {
throw new IllegalStateException(
"Thread interrupted while waiting for NDK libs to be loaded", e);
}
}

/** Closes the NDK integration */
public static void close() {
io.sentry.ndk.SentryNdk.close();
try {
if (loadLibraryLatch.await(2000, TimeUnit.MILLISECONDS)) {
//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.close();
} else {
throw new IllegalStateException("Timeout waiting for Sentry NDK library to load");
}
} catch (InterruptedException e) {
throw new IllegalStateException(
"Thread interrupted while waiting for NDK libs to be loaded", e);
}
}
}
5 changes: 4 additions & 1 deletion sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ android {

externalNativeBuild {
cmake {
arguments.add(0, "-DANDROID_STL=c++_shared")
// Android 15: As we're using an older version of AGP / NDK, the STL is not 16kb page aligned yet
// Our example code doesn't use the STL, so we simply disable it
// See https://developer.android.com/guide/practices/page-sizes
arguments.add(0, "-DANDROID_STL=none")
}
}

Expand Down
Loading