Skip to content

Cache, background threads and data for UnityEventProcessor #267

Closed
@semuserable

Description

@semuserable
  • Singleton GameObject created at startup (SentryUnityOptions) to cache stuff on UI thread (revert from deferred execution)
  • Cache aggressively all values that profiler shows (any timestamps visible in dotTrace)
// Not cached and must be called from UI thread, won't be shown if `SentrySdk.CaptureEvent` called on non-UI thread
SystemInfo.batteryStatus
SystemInfo.batteryLevel
Input.deviceOrientation

// Cached, isn't shown in dotTrace, must be called from UI thread
SystemInfo.processorCount
SystemInfo.processorType
SystemInfo.supportsVibration
// etc

// Cached, shown in dotTrace, must be called from UI thread
new Lazy(() => SystemInfo.deviceUniqueIdentifier)
new Lazy(() => SystemInfo.deviceModel)
new Lazy(() => SystemInfo.graphicsDeviceVendorID.ToString())
// etc
  • Task.Run(() => SentrySdk.CaptureEvent(sentryEvent)); must not fail and send the event
  • If SentrySdk.CaptureEvent is called from non-UI thread, make sure the event processing won't fail (because of calling Unity APIs from non-UI thread). But if SentrySdk.CaptureEvent is called in UI thread and then non-UI thread (Task.Run), populate the data from cached value
// In order to have `SystemInfo.deviceType` set in `SentryEvent.Device.DeviceType`, we must call it from UI thread.

// first call, non-UI thread,  `SentryEvent.Device.DeviceType` is `null`
Task.Run(() => SentrySdk.CaptureEvent(sentryEvent));

// second call, UI thread, `SentryEvent.Device.DeviceType` is NOT `null` and equals to 'Desktop'
SentrySdk.CaptureEvent(sentryEvent);

// third call, non-UI thread, `SentryEvent.Device.DeviceType` is NOT `null` and equals to 'Desktop'
Task.Run(() => SentrySdk.CaptureEvent(sentryEvent));
  • Tests

Metadata

Metadata

Assignees

Labels

FeatureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions