Skip to content

Commit

Permalink
add additional tracing to startup (#1285)
Browse files Browse the repository at this point in the history
I triggered an auto rebase but this was @fractalwrench's PR
  • Loading branch information
fractalwrench authored Aug 21, 2024
1 parent 10a3127 commit 832cf5a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.embrace.android.embracesdk.internal.config
import android.content.res.Resources.NotFoundException
import android.util.Base64
import io.embrace.android.embracesdk.internal.AndroidResourcesService
import io.embrace.android.embracesdk.internal.Systrace
import io.embrace.android.embracesdk.internal.config.local.LocalConfig
import io.embrace.android.embracesdk.internal.config.local.SdkLocalConfig
import io.embrace.android.embracesdk.internal.logging.EmbLogger
Expand Down Expand Up @@ -47,6 +48,7 @@ internal object LocalConfigParser {
logger: EmbLogger
): LocalConfig {
return try {
Systrace.startSynchronous("cfg-resolve-resources")
val appId = resolveAppId(customAppId, resources, packageName)
val ndkEnabledJsonId =
resources.getIdentifier(BUILD_INFO_NDK_ENABLED, "string", packageName)
Expand All @@ -61,16 +63,20 @@ internal object LocalConfigParser {
}
val sdkConfigJsonId =
resources.getIdentifier(BUILD_INFO_SDK_CONFIG, "string", packageName)
Systrace.endSynchronous()

val sdkConfigJson: String? = when {
sdkConfigJsonId != 0 -> {
val encodedConfig = resources.getString(sdkConfigJsonId)
String(Base64.decode(encodedConfig, Base64.DEFAULT))
Systrace.traceSynchronous("base64-decode") {
String(Base64.decode(encodedConfig, Base64.DEFAULT))
}
}

else -> null
}
buildConfig(appId, ndkEnabled, sdkConfigJson, serializer, openTelemetryCfg, logger)
Systrace.traceSynchronous("build-config") {
buildConfig(appId, ndkEnabled, sdkConfigJson, serializer, openTelemetryCfg, logger)
}
} catch (ex: Exception) {
throw IllegalStateException("Failed to load local config from resources.", ex)
}
Expand Down Expand Up @@ -115,18 +121,17 @@ internal object LocalConfigParser {
logger.logInfo("Native crash capture is $enabledStr")
var configs: SdkLocalConfig? = null
if (!sdkConfigs.isNullOrEmpty()) {
try {
configs = serializer.fromJson(sdkConfigs, SdkLocalConfig::class.java)
} catch (ex: Exception) {
logger.logError(
"Failed to parse Embrace config from config json file.",
ex
)
Systrace.traceSynchronous("deserialize-sdk-config") {
try {
configs = serializer.fromJson(sdkConfigs, SdkLocalConfig::class.java)
} catch (ex: Exception) {
logger.logError(
"Failed to parse Embrace config from config json file.",
ex
)
}
}
}
if (configs == null) {
configs = SdkLocalConfig()
}
return LocalConfig(appId, ndkEnabled, configs)
return LocalConfig(appId, ndkEnabled, configs ?: SdkLocalConfig())
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.embrace.android.embracesdk.internal.registry

import io.embrace.android.embracesdk.internal.Systrace
import io.embrace.android.embracesdk.internal.logging.EmbLogger
import io.embrace.android.embracesdk.internal.session.MemoryCleanerListener
import io.embrace.android.embracesdk.internal.session.MemoryCleanerService
Expand Down Expand Up @@ -37,7 +38,9 @@ public class ServiceRegistry(
public val startupListener: List<StartupListener> by lazy { registry.filterIsInstance<StartupListener>() }

public fun registerServices(vararg services: Any?) {
services.forEach(::registerService)
Systrace.trace("register-services") {
services.forEach(::registerService)
}
}

public fun registerService(service: Any?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,17 @@ internal class EmbraceNdkService(
val nativeCrashId: String = unityCrashId ?: Uuid.getEmbUuid()
val is32bit = deviceArchitecture.is32BitDevice
val initialMetaData = Systrace.traceSynchronous("init-native-crash-metadata") {
serializer.toJson(
val metadata = Systrace.traceSynchronous("gather-metadata") {
NativeCrashMetadata(
metadataService.getAppInfo(),
metadataService.getDeviceInfo(),
userService.getUserInfo(),
sessionPropertiesService.getProperties()
)
)
}
Systrace.traceSynchronous("serialize-metadata") {
serializer.toJson(metadata)
}
}
Systrace.traceSynchronous("native-install-handlers") {
delegate._installSignalHandlers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ internal class ModuleInitBootstrapper(

val networkBehavior = configModule.configService.networkBehavior
if (networkBehavior.isNativeNetworkingMonitoringEnabled()) {
registerFactory(networkBehavior.isRequestContentLengthCaptureEnabled())
Systrace.traceSynchronous("network-monitoring-installation") {
registerFactory(networkBehavior.isRequestContentLengthCaptureEnabled())
}
}
Systrace.traceSynchronous("network-connectivity-registration") {
networkConnectivityService.addNetworkConnectivityListener(pendingApiCallsSender)
apiService?.let(networkConnectivityService::addNetworkConnectivityListener)
}
networkConnectivityService.addNetworkConnectivityListener(pendingApiCallsSender)
apiService?.let(networkConnectivityService::addNetworkConnectivityListener)
}
}

Expand Down Expand Up @@ -375,15 +379,18 @@ internal class ModuleInitBootstrapper(
)

if (configModule.configService.autoDataCaptureBehavior.isNdkEnabled()) {
Systrace.startSynchronous("ndk-service-updates")
essentialServiceModule.sessionIdTracker.addListener {
nativeFeatureModule.ndkService.updateSessionId(it ?: "")
}
essentialServiceModule.sessionPropertiesService.addChangeListener(
nativeFeatureModule.ndkService::onSessionPropertiesUpdate
)
Systrace.endSynchronous()
}

if (nativeFeatureModule.nativeThreadSamplerInstaller != null) {
Systrace.startSynchronous("native-thread-sampler-init")
// install the native thread sampler
nativeFeatureModule.nativeThreadSamplerService?.let { nativeThreadSamplerService ->
nativeThreadSamplerService.setupNativeSampler()
Expand Down Expand Up @@ -414,6 +421,7 @@ internal class ModuleInitBootstrapper(
}
}
}
Systrace.endSynchronous()
}
}

Expand Down

0 comments on commit 832cf5a

Please sign in to comment.