fix: Use correct parsing for stackframes
Fixes https://github.com/getsentry/sentry-cocoa/issues/4040
The problem was that for some events such as app hangs and CPUDiagnostics the metric kit payload contains an entire flamegraph. This change parses the flame graph into samples, and then picks the longest duration sample as the one we use for a stack trace. It also fixes over-counting the CPUDiagnostics which was emitting more than one event per exception. This is also fixed by identifying the longest duration sample.
Eventually we should support showing the full flame graph on the frontend, but with this PR the bug is fixed and we can consider that a future improvement.
I tested this on test flight by triggering crashes and verifying they are still correct, as well as manually replaying hang reports received in production
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 84.895%. Comparing base (6c20265) to head (ac40ad2).
:warning: Report is 7 commits behind head on main.
:white_check_mark: All tests successful. No failed tests found.
Additional details and impacted files
@@ Coverage Diff @@
## main #6908 +/- ##
=============================================
- Coverage 84.968% 84.895% -0.073%
=============================================
Files 457 459 +2
Lines 27608 27575 -33
Branches 12142 12145 +3
=============================================
- Hits 23458 23410 -48
- Misses 4109 4126 +17
+ Partials 41 39 -2
| Files with missing lines | Coverage Δ | |
|---|---|---|
| Sources/Sentry/SentryFormatterSwift.m | 100.000% <100.000%> (ø) |
|
| Sources/Sentry/SentryMetricKitIntegration.m | 100.000% <100.000%> (ø) |
|
| ...Core/MetricKit/SentryMXCallStackTree+Parsing.swift | 100.000% <100.000%> (ø) |
|
| ...s/Swift/Core/MetricKit/SentryMXCallStackTree.swift | 100.000% <ø> (+25.000%) |
:arrow_up: |
| Sources/Swift/Core/MetricKit/SentryMXManager.swift | 100.000% <100.000%> (ø) |
... and 18 files with indirect coverage changes
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 6c20265...ac40ad2. Read the comment docs.
Performance metrics :rocket:
| Plain | With Sentry | Diff | |
|---|---|---|---|
| Startup time | 1192.81 ms | 1220.30 ms | 27.49 ms |
| Size | 24.14 KiB | 1.03 MiB | 1.01 MiB |
Baseline results on branch: main
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| af848c439ac97ab7850767f9f49d7a935b511cd9 | 1224.02 ms | 1251.00 ms | 26.98 ms |
| 2ec27000f0f0c2e2b99104488c080e9b6ea6fea2 | 1238.28 ms | 1258.82 ms | 20.53 ms |
| b358363efd7e81b5a9e0ecb3ee7daf003dba6754 | 1228.33 ms | 1262.34 ms | 34.01 ms |
| dcaec4e4f4f31a02aa5c5c409308dcc9eb9c7a0c | 1209.06 ms | 1246.02 ms | 36.96 ms |
| 5ff1b04b314290120c468597d0d1add73e15bf04 | 1226.00 ms | 1259.98 ms | 33.98 ms |
| 1b9991e062e58b3eca64ce9b3a4ced2a8ca0aae2 | 1233.45 ms | 1256.61 ms | 23.17 ms |
| f8cad3cab6dfd77a717640313a4208d27fc41b54 | 1217.94 ms | 1257.96 ms | 40.02 ms |
| 5cfc76877e04e23aca2f156286738a33882cd485 | 1220.74 ms | 1245.06 ms | 24.32 ms |
| 650d8026fd8bf70270211b709910dfe2454660a4 | 1231.86 ms | 1255.64 ms | 23.78 ms |
| 5ec90e0df18400cbc7615eb74351d1c74216ed59 | 1235.57 ms | 1258.45 ms | 22.88 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| af848c439ac97ab7850767f9f49d7a935b511cd9 | 24.14 KiB | 1.01 MiB | 1012.94 KiB |
| 2ec27000f0f0c2e2b99104488c080e9b6ea6fea2 | 23.75 KiB | 980.80 KiB | 957.05 KiB |
| b358363efd7e81b5a9e0ecb3ee7daf003dba6754 | 23.75 KiB | 987.92 KiB | 964.18 KiB |
| dcaec4e4f4f31a02aa5c5c409308dcc9eb9c7a0c | 24.15 KiB | 1.01 MiB | 1014.80 KiB |
| 5ff1b04b314290120c468597d0d1add73e15bf04 | 23.75 KiB | 1.01 MiB | 1016.24 KiB |
| 1b9991e062e58b3eca64ce9b3a4ced2a8ca0aae2 | 23.75 KiB | 908.01 KiB | 884.26 KiB |
| f8cad3cab6dfd77a717640313a4208d27fc41b54 | 23.75 KiB | 1.01 MiB | 1016.13 KiB |
| 5cfc76877e04e23aca2f156286738a33882cd485 | 23.75 KiB | 850.73 KiB | 826.98 KiB |
| 650d8026fd8bf70270211b709910dfe2454660a4 | 23.74 KiB | 913.13 KiB | 889.39 KiB |
| 5ec90e0df18400cbc7615eb74351d1c74216ed59 | 23.74 KiB | 872.67 KiB | 848.92 KiB |
Previous results on branch: mxRewriting
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c20c3c1f7ebc95d803b37d1eff568f5cd84a68a8 | 1209.08 ms | 1237.69 ms | 28.61 ms |
| d0cf095ad820ba9dbe4396a4edff95dd803fbd8b | 1225.92 ms | 1255.11 ms | 29.20 ms |
| 44da6c5a9de2260920863120d24ab1b21dab708c | 1234.22 ms | 1266.02 ms | 31.80 ms |
| bf3e24564ad2afafb07f1064d327a0fbe64e8d9b | 1222.17 ms | 1257.09 ms | 34.92 ms |
| 793ffeaa475333263edbabfadf1bff06fbf0252f | 1229.79 ms | 1264.65 ms | 34.86 ms |
| c5b3f7a87064b019b3bd371c44a595ef4661f184 | 1220.18 ms | 1259.44 ms | 39.25 ms |
| f3b889c5cc28f02df8c3fee53c2e06a4bd5efeea | 1221.57 ms | 1252.77 ms | 31.20 ms |
| 8824c94ec3da9a676607b441f388cab6a1913f56 | 1226.98 ms | 1262.65 ms | 35.67 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c20c3c1f7ebc95d803b37d1eff568f5cd84a68a8 | 24.14 KiB | 1.03 MiB | 1.01 MiB |
| d0cf095ad820ba9dbe4396a4edff95dd803fbd8b | 24.14 KiB | 1.03 MiB | 1.01 MiB |
| 44da6c5a9de2260920863120d24ab1b21dab708c | 24.14 KiB | 1.03 MiB | 1.00 MiB |
| bf3e24564ad2afafb07f1064d327a0fbe64e8d9b | 24.14 KiB | 1.03 MiB | 1.00 MiB |
| 793ffeaa475333263edbabfadf1bff06fbf0252f | 24.14 KiB | 1.03 MiB | 1.00 MiB |
| c5b3f7a87064b019b3bd371c44a595ef4661f184 | 24.14 KiB | 1.01 MiB | 1013.45 KiB |
| f3b889c5cc28f02df8c3fee53c2e06a4bd5efeea | 24.14 KiB | 1.03 MiB | 1.01 MiB |
| 8824c94ec3da9a676607b441f388cab6a1913f56 | 24.14 KiB | 1.01 MiB | 1014.88 KiB |
Thanks @philipphofmann this is ready for another look!