Skip to content

Commit 494b0d0

Browse files
jushgithub-actions[bot]
authored andcommitted
[maps-sdk] Add tracing instrumentation for render frame pipeline (#13517)
GitOrigin-RevId: 3f3edc61dd904863024c2ed073b181954eac7775
1 parent 337f459 commit 494b0d0

13 files changed

Lines changed: 280 additions & 161 deletions

File tree

maps-sdk/src/main/java/com/mapbox/maps/MapController.kt

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.annotation.RestrictTo
66
import androidx.annotation.VisibleForTesting
77
import com.mapbox.common.Cancelable
88
import com.mapbox.common.MapboxOptions
9+
import com.mapbox.common.MapboxTracing
910
import com.mapbox.maps.plugin.InvalidViewPluginHostException
1011
import com.mapbox.maps.plugin.MapPlugin
1112
import com.mapbox.maps.plugin.MapPluginRegistry
@@ -384,60 +385,62 @@ internal class MapController : MapPluginProviderDelegate, MapControllable {
384385
mapView: MapView? = null,
385386
) {
386387
for (plugin in options.plugins) {
387-
try {
388-
val pluginObject = when (plugin.id) {
389-
MAPBOX_GESTURES_PLUGIN_ID -> {
390-
createGesturePlugin(options.context, options.attrs, options.mapOptions.pixelRatio)
388+
MapboxTracing.traceSync({ "$MAPS_SDK_TRACE_PREFIX createPlugin: ${plugin.id}" }) {
389+
try {
390+
val pluginObject = when (plugin.id) {
391+
MAPBOX_GESTURES_PLUGIN_ID -> {
392+
createGesturePlugin(options.context, options.attrs, options.mapOptions.pixelRatio)
393+
}
394+
MAPBOX_CAMERA_PLUGIN_ID -> {
395+
createCameraAnimationPlugin()
396+
}
397+
MAPBOX_ANNOTATION_PLUGIN_ID -> {
398+
createAnnotationPlugin()
399+
}
400+
MAPBOX_COMPASS_PLUGIN_ID -> {
401+
createCompassPlugin()
402+
}
403+
MAPBOX_ATTRIBUTION_PLUGIN_ID -> {
404+
createAttributionPlugin()
405+
}
406+
MAPBOX_LIFECYCLE_PLUGIN_ID -> {
407+
createLifecyclePlugin()
408+
}
409+
MAPBOX_LOCATION_COMPONENT_PLUGIN_ID -> {
410+
createLocationComponentPlugin()
411+
}
412+
MAPBOX_LOGO_PLUGIN_ID -> {
413+
createLogoPlugin()
414+
}
415+
MAPBOX_MAP_OVERLAY_PLUGIN_ID -> {
416+
createOverlayPlugin()
417+
}
418+
MAPBOX_SCALEBAR_PLUGIN_ID -> {
419+
createScaleBarPlugin()
420+
}
421+
MAPBOX_VIEWPORT_PLUGIN_ID -> {
422+
createViewportPlugin()
423+
}
424+
MAPBOX_INDOOR_SELECTOR_PLUGIN_ID -> {
425+
createIndoorSelectorPlugin()
426+
}
427+
else -> {
428+
plugin.instance
429+
?: throw MapboxConfigurationException("Custom non Mapbox plugins must have non-null `instance` parameter!")
430+
}
391431
}
392-
MAPBOX_CAMERA_PLUGIN_ID -> {
393-
createCameraAnimationPlugin()
394-
}
395-
MAPBOX_ANNOTATION_PLUGIN_ID -> {
396-
createAnnotationPlugin()
397-
}
398-
MAPBOX_COMPASS_PLUGIN_ID -> {
399-
createCompassPlugin()
400-
}
401-
MAPBOX_ATTRIBUTION_PLUGIN_ID -> {
402-
createAttributionPlugin()
403-
}
404-
MAPBOX_LIFECYCLE_PLUGIN_ID -> {
405-
createLifecyclePlugin()
406-
}
407-
MAPBOX_LOCATION_COMPONENT_PLUGIN_ID -> {
408-
createLocationComponentPlugin()
409-
}
410-
MAPBOX_LOGO_PLUGIN_ID -> {
411-
createLogoPlugin()
412-
}
413-
MAPBOX_MAP_OVERLAY_PLUGIN_ID -> {
414-
createOverlayPlugin()
415-
}
416-
MAPBOX_SCALEBAR_PLUGIN_ID -> {
417-
createScaleBarPlugin()
418-
}
419-
MAPBOX_VIEWPORT_PLUGIN_ID -> {
420-
createViewportPlugin()
421-
}
422-
MAPBOX_INDOOR_SELECTOR_PLUGIN_ID -> {
423-
createIndoorSelectorPlugin()
424-
}
425-
else -> {
426-
plugin.instance
427-
?: throw MapboxConfigurationException("Custom non Mapbox plugins must have non-null `instance` parameter!")
428-
}
429-
}
430-
createPlugin(mapView, Plugin.Custom(plugin.id, pluginObject))
431-
if (plugin is Plugin.Mapbox) {
432-
when (pluginObject) {
433-
is CameraAnimationsPlugin -> mapboxMap.cameraAnimationsPlugin = pluginObject
434-
is GesturesPlugin -> mapboxMap.gesturesPlugin = pluginObject
432+
createPlugin(mapView, Plugin.Custom(plugin.id, pluginObject))
433+
if (plugin is Plugin.Mapbox) {
434+
when (pluginObject) {
435+
is CameraAnimationsPlugin -> mapboxMap.cameraAnimationsPlugin = pluginObject
436+
is GesturesPlugin -> mapboxMap.gesturesPlugin = pluginObject
437+
}
435438
}
439+
} catch (ex: NoClassDefFoundError) {
440+
logI(TAG, PLUGIN_MISSING_TEMPLATE.format(plugin.id))
441+
} catch (ex: InvalidViewPluginHostException) {
442+
logI(TAG, VIEW_HIERARCHY_MISSING_TEMPLATE.format(plugin))
436443
}
437-
} catch (ex: NoClassDefFoundError) {
438-
logI(TAG, PLUGIN_MISSING_TEMPLATE.format(plugin.id))
439-
} catch (ex: InvalidViewPluginHostException) {
440-
logI(TAG, VIEW_HIERARCHY_MISSING_TEMPLATE.format(plugin))
441444
}
442445
}
443446
}

maps-sdk/src/main/java/com/mapbox/maps/MapView.kt

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.annotation.IntRange
1414
import androidx.annotation.MainThread
1515
import androidx.annotation.RestrictTo
1616
import androidx.annotation.VisibleForTesting
17+
import com.mapbox.common.MapboxTracing
1718
import com.mapbox.maps.debugoptions.DebugOptionsController
1819
import com.mapbox.maps.debugoptions.MapViewDebugOptions
1920
import com.mapbox.maps.plugin.MapPlugin
@@ -118,42 +119,46 @@ open class MapView : FrameLayout, MapPluginProviderDelegate, MapControllable {
118119
defStyleRes: Int,
119120
initOptions: MapInitOptions?,
120121
) : super(context, attrs, defStyleAttr, defStyleRes) {
121-
val resolvedMapInitOptions = if (attrs != null) {
122-
parseTypedArray(context, attrs)
123-
} else {
124-
initOptions ?: MapInitOptions(context)
125-
}
126-
if (isInEditMode) {
127-
return
128-
}
129-
val view = if (resolvedMapInitOptions.textureView) {
130-
TextureView(context, attrs)
131-
} else {
132-
SurfaceView(context, attrs)
122+
MapboxTracing.traceSync("$MAPS_SDK_TRACE_PREFIX MapView") {
123+
val resolvedMapInitOptions = if (attrs != null) {
124+
parseTypedArray(context, attrs)
125+
} else {
126+
initOptions ?: MapInitOptions(context)
127+
}
128+
if (isInEditMode) {
129+
return
130+
}
131+
val view = if (resolvedMapInitOptions.textureView) {
132+
TextureView(context, attrs)
133+
} else {
134+
SurfaceView(context, attrs)
135+
}
136+
val contextMode = resolvedMapInitOptions.mapOptions.contextMode ?: ContextMode.UNIQUE
137+
val mapName = resolvedMapInitOptions.mapName
138+
139+
val renderer = MapboxTracing.traceSync({ "$MAPS_SDK_TRACE_PREFIX renderer($mapName)" }) {
140+
when (view) {
141+
is SurfaceView -> MapboxSurfaceHolderRenderer(
142+
view.holder,
143+
resolvedMapInitOptions.antialiasingSampleCount,
144+
contextMode,
145+
resolvedMapInitOptions.mapName,
146+
)
147+
148+
is TextureView -> MapboxTextureViewRenderer(
149+
view,
150+
resolvedMapInitOptions.antialiasingSampleCount,
151+
contextMode,
152+
resolvedMapInitOptions.mapName,
153+
)
154+
155+
else -> throw IllegalArgumentException("Provided view has to be a texture or a surface.")
156+
}
157+
}
158+
mapController = MapController(renderer, resolvedMapInitOptions)
159+
addView(view, 0)
160+
mapController.initializePlugins(resolvedMapInitOptions, this)
133161
}
134-
val contextMode = resolvedMapInitOptions.mapOptions.contextMode ?: ContextMode.UNIQUE
135-
mapController = MapController(
136-
when (view) {
137-
is SurfaceView -> MapboxSurfaceHolderRenderer(
138-
view.holder,
139-
resolvedMapInitOptions.antialiasingSampleCount,
140-
contextMode,
141-
resolvedMapInitOptions.mapName,
142-
)
143-
144-
is TextureView -> MapboxTextureViewRenderer(
145-
view,
146-
resolvedMapInitOptions.antialiasingSampleCount,
147-
contextMode,
148-
resolvedMapInitOptions.mapName,
149-
)
150-
151-
else -> throw IllegalArgumentException("Provided view has to be a texture or a surface.")
152-
},
153-
resolvedMapInitOptions
154-
)
155-
addView(view, 0)
156-
mapController.initializePlugins(resolvedMapInitOptions, this)
157162
}
158163

159164
override fun onAttachedToWindow() {

0 commit comments

Comments
 (0)