|
51 | 51 | import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader; |
52 | 52 | import io.sentry.android.core.internal.util.SentryFrameMetricsCollector; |
53 | 53 | import io.sentry.android.core.performance.AppStartMetrics; |
| 54 | +import io.sentry.profilemeasurements.ProfileMeasurement; |
| 55 | +import io.sentry.profilemeasurements.ProfileMeasurementValue; |
54 | 56 | import io.sentry.protocol.Geo; |
55 | 57 | import io.sentry.protocol.SdkVersion; |
56 | 58 | import io.sentry.protocol.SentryId; |
@@ -823,11 +825,23 @@ private void initializeAndroidProfiler() { |
823 | 825 | } |
824 | 826 | final String tracesFilesDirPath = getProfilingTracesDirPath(); |
825 | 827 |
|
| 828 | + SentryFrameMetricsCollector collector = null; |
| 829 | + try { |
| 830 | + final SentryOptions options = Sentry.getCurrentScopes().getOptions(); |
| 831 | + if (options instanceof SentryAndroidOptions) { |
| 832 | + collector = ((SentryAndroidOptions) options).getFrameMetricsCollector(); |
| 833 | + } |
| 834 | + } catch (Throwable ignored) { // NOPMD - Best-effort |
| 835 | + } |
| 836 | + if (collector == null) { |
| 837 | + collector = new SentryFrameMetricsCollector(reactApplicationContext, logger, buildInfo); |
| 838 | + } |
| 839 | + |
826 | 840 | androidProfiler.set( |
827 | 841 | new AndroidProfiler( |
828 | 842 | tracesFilesDirPath, |
829 | 843 | (int) SECONDS.toMicros(1) / profilingTracesHz, |
830 | | - new SentryFrameMetricsCollector(reactApplicationContext, logger, buildInfo), |
| 844 | + collector, |
831 | 845 | () -> executorService, |
832 | 846 | logger)); |
833 | 847 | } |
@@ -908,6 +922,27 @@ public WritableMap stopProfiling() { |
908 | 922 | androidProfile.putString("sampled_profile", base64AndroidProfile); |
909 | 923 | androidProfile.putInt("android_api_level", buildInfo.getSdkInfoVersion()); |
910 | 924 | androidProfile.putString("build_id", getProguardUuid()); |
| 925 | + |
| 926 | + if (end.measurementsMap != null && !end.measurementsMap.isEmpty()) { |
| 927 | + WritableMap measurements = new WritableNativeMap(); |
| 928 | + for (Map.Entry<String, ProfileMeasurement> entry : end.measurementsMap.entrySet()) { |
| 929 | + WritableMap measurement = new WritableNativeMap(); |
| 930 | + measurement.putString("unit", entry.getValue().getUnit()); |
| 931 | + WritableArray values = new WritableNativeArray(); |
| 932 | + if (entry.getValue().getValues() != null) { |
| 933 | + for (ProfileMeasurementValue pmv : entry.getValue().getValues()) { |
| 934 | + WritableMap value = new WritableNativeMap(); |
| 935 | + value.putString("elapsed_since_start_ns", pmv.getRelativeStartNs()); |
| 936 | + value.putDouble("value", pmv.getValue()); |
| 937 | + values.pushMap(value); |
| 938 | + } |
| 939 | + } |
| 940 | + measurement.putArray("values", values); |
| 941 | + measurements.putMap(entry.getKey(), measurement); |
| 942 | + } |
| 943 | + androidProfile.putMap("measurements", measurements); |
| 944 | + } |
| 945 | + |
911 | 946 | result.putMap("androidProfile", androidProfile); |
912 | 947 | } |
913 | 948 | } catch (Throwable e) { // NOPMD - We don't want to crash in any case |
|
0 commit comments