|
12 | 12 | import io.sentry.ILogger; |
13 | 13 | import io.sentry.IScopes; |
14 | 14 | import io.sentry.Integration; |
15 | | -import io.sentry.ProfileChunk; |
16 | | -import io.sentry.ProfileContext; |
17 | 15 | import io.sentry.SentryEvent; |
18 | | -import io.sentry.SentryExceptionFactory; |
19 | 16 | import io.sentry.SentryLevel; |
20 | 17 | import io.sentry.SentryOptions; |
21 | | -import io.sentry.SentryStackTraceFactory; |
22 | | -import io.sentry.android.core.anr.AggregatedStackTrace; |
23 | | -import io.sentry.android.core.anr.AnrCulpritIdentifier; |
24 | | -import io.sentry.android.core.anr.AnrException; |
25 | | -import io.sentry.android.core.anr.AnrProfile; |
26 | | -import io.sentry.android.core.anr.AnrProfileManager; |
27 | | -import io.sentry.android.core.anr.AnrProfileRotationHelper; |
28 | | -import io.sentry.android.core.anr.StackTraceConverter; |
29 | 18 | import io.sentry.android.core.cache.AndroidEnvelopeCache; |
30 | 19 | import io.sentry.android.core.internal.threaddump.Lines; |
31 | 20 | import io.sentry.android.core.internal.threaddump.ThreadDumpParser; |
|
35 | 24 | import io.sentry.protocol.DebugImage; |
36 | 25 | import io.sentry.protocol.DebugMeta; |
37 | 26 | import io.sentry.protocol.Message; |
38 | | -import io.sentry.protocol.SentryException; |
39 | 27 | import io.sentry.protocol.SentryId; |
40 | | -import io.sentry.protocol.SentryStackFrame; |
41 | | -import io.sentry.protocol.SentryStackTrace; |
42 | 28 | import io.sentry.protocol.SentryThread; |
43 | | -import io.sentry.protocol.profiling.SentryProfile; |
44 | 29 | import io.sentry.transport.CurrentDateProvider; |
45 | 30 | import io.sentry.transport.ICurrentDateProvider; |
46 | 31 | import io.sentry.util.HintUtils; |
|
49 | 34 | import java.io.ByteArrayInputStream; |
50 | 35 | import java.io.ByteArrayOutputStream; |
51 | 36 | import java.io.Closeable; |
52 | | -import java.io.File; |
53 | 37 | import java.io.IOException; |
54 | 38 | import java.io.InputStream; |
55 | 39 | import java.io.InputStreamReader; |
56 | | -import java.util.Arrays; |
57 | | -import java.util.HashMap; |
58 | 40 | import java.util.List; |
59 | 41 | import org.jetbrains.annotations.ApiStatus; |
60 | 42 | import org.jetbrains.annotations.NotNull; |
@@ -207,111 +189,9 @@ public boolean shouldReportHistorical() { |
207 | 189 | } |
208 | 190 | } |
209 | 191 |
|
210 | | - if (options.isEnableAnrProfiling()) { |
211 | | - applyAnrProfile(isBackground, anrTimestamp, event); |
212 | | - // TODO: maybe move to AnrV2EventProcessor instead |
213 | | - if (hasOnlySystemFrames(event)) { |
214 | | - // By omitting the {{ default }} fingerprint, the stacktrace will be completely ignored |
215 | | - // and all events will be grouped |
216 | | - // into the same issue |
217 | | - event.setFingerprints( |
218 | | - Arrays.asList( |
219 | | - "{{ system-frames-only-anr }}", |
220 | | - isBackground ? "background-anr" : "foreground-anr")); |
221 | | - } |
222 | | - } |
223 | | - |
224 | 192 | return new ApplicationExitInfoHistoryDispatcher.Report(event, hint, anrHint); |
225 | 193 | } |
226 | 194 |
|
227 | | - private void applyAnrProfile( |
228 | | - final boolean isBackground, final long anrTimestamp, final @NotNull SentryEvent event) { |
229 | | - |
230 | | - // as of now AnrProfilingIntegration only generates profiles in foreground |
231 | | - if (isBackground) { |
232 | | - return; |
233 | | - } |
234 | | - |
235 | | - final @Nullable String cacheDirPath = options.getCacheDirPath(); |
236 | | - if (cacheDirPath == null) { |
237 | | - return; |
238 | | - } |
239 | | - final @NotNull File cacheDir = new File(cacheDirPath); |
240 | | - |
241 | | - @Nullable AnrProfile anrProfile = null; |
242 | | - |
243 | | - try { |
244 | | - final File lastFile = AnrProfileRotationHelper.getLastFile(cacheDir); |
245 | | - |
246 | | - if (lastFile.exists()) { |
247 | | - options.getLogger().log(SentryLevel.DEBUG, "Reading ANR profile"); |
248 | | - try (final AnrProfileManager provider = new AnrProfileManager(options, lastFile)) { |
249 | | - anrProfile = provider.load(); |
250 | | - } |
251 | | - } else { |
252 | | - options.getLogger().log(SentryLevel.DEBUG, "No ANR profile file found"); |
253 | | - } |
254 | | - } catch (Throwable t) { |
255 | | - options.getLogger().log(SentryLevel.INFO, "Could not retrieve ANR profile", t); |
256 | | - } finally { |
257 | | - if (!AnrProfileRotationHelper.deleteLastFile(cacheDir)) { |
258 | | - options.getLogger().log(SentryLevel.INFO, "Could not delete ANR profile file"); |
259 | | - } |
260 | | - } |
261 | | - |
262 | | - if (anrProfile != null) { |
263 | | - options.getLogger().log(SentryLevel.INFO, "ANR profile found"); |
264 | | - if (anrTimestamp >= anrProfile.startTimeMs && anrTimestamp <= anrProfile.endtimeMs) { |
265 | | - final @Nullable AggregatedStackTrace culprit = |
266 | | - AnrCulpritIdentifier.identify(anrProfile.stacks); |
267 | | - if (culprit != null) { |
268 | | - final @Nullable SentryId profilerId = captureAnrProfile(anrTimestamp, anrProfile); |
269 | | - |
270 | | - final @NotNull StackTraceElement[] stack = culprit.getStack(); |
271 | | - if (stack.length > 0) { |
272 | | - final StackTraceElement stackTraceElement = culprit.getStack()[0]; |
273 | | - final String message = |
274 | | - stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName(); |
275 | | - final AnrException exception = new AnrException(message); |
276 | | - exception.setStackTrace(stack); |
277 | | - |
278 | | - // TODO should this be re-used from somewhere else? |
279 | | - final SentryExceptionFactory factory = |
280 | | - new SentryExceptionFactory(new SentryStackTraceFactory(options)); |
281 | | - event.setExceptions(factory.getSentryExceptions(exception)); |
282 | | - if (profilerId != null) { |
283 | | - event.getContexts().setProfile(new ProfileContext(profilerId)); |
284 | | - } |
285 | | - } |
286 | | - } |
287 | | - } else { |
288 | | - options.getLogger().log(SentryLevel.DEBUG, "ANR profile found, but doesn't match"); |
289 | | - } |
290 | | - } |
291 | | - } |
292 | | - |
293 | | - @Nullable |
294 | | - private SentryId captureAnrProfile( |
295 | | - final long anrTimestamp, final @NotNull AnrProfile anrProfile) { |
296 | | - final SentryProfile profile = StackTraceConverter.convert(anrProfile); |
297 | | - final ProfileChunk chunk = |
298 | | - new ProfileChunk( |
299 | | - new SentryId(), |
300 | | - new SentryId(), |
301 | | - null, |
302 | | - new HashMap<>(0), |
303 | | - anrTimestamp / 1000.0d, |
304 | | - ProfileChunk.PLATFORM_JAVA, |
305 | | - options); |
306 | | - chunk.setSentryProfile(profile); |
307 | | - final SentryId profilerId = scopes.captureProfileChunk(chunk); |
308 | | - if (SentryId.EMPTY_ID.equals(profilerId)) { |
309 | | - return null; |
310 | | - } else { |
311 | | - return chunk.getProfilerId(); |
312 | | - } |
313 | | - } |
314 | | - |
315 | 195 | private @NotNull ParseResult parseThreadDump( |
316 | 196 | final @NotNull ApplicationExitInfo exitInfo, final boolean isBackground) { |
317 | 197 | final byte[] dump; |
@@ -365,33 +245,6 @@ private byte[] getDumpBytes(final @NotNull InputStream trace) throws IOException |
365 | 245 | } |
366 | 246 | } |
367 | 247 |
|
368 | | - private static boolean hasOnlySystemFrames(final @NotNull SentryEvent event) { |
369 | | - final List<SentryException> exceptions = event.getExceptions(); |
370 | | - if (exceptions == null || exceptions.isEmpty()) { |
371 | | - // No exceptions means we haven't verified frames - don't apply special fingerprinting |
372 | | - return false; |
373 | | - } |
374 | | - |
375 | | - for (final SentryException exception : exceptions) { |
376 | | - final @Nullable SentryStackTrace stacktrace = exception.getStacktrace(); |
377 | | - if (stacktrace != null) { |
378 | | - final @Nullable List<SentryStackFrame> frames = stacktrace.getFrames(); |
379 | | - if (frames != null && !frames.isEmpty()) { |
380 | | - for (final SentryStackFrame frame : frames) { |
381 | | - if (frame.isInApp() != null && frame.isInApp()) { |
382 | | - return false; |
383 | | - } |
384 | | - final @Nullable String module = frame.getModule(); |
385 | | - if (module != null && !AnrCulpritIdentifier.isSystemFrame(frame.getModule())) { |
386 | | - return false; |
387 | | - } |
388 | | - } |
389 | | - } |
390 | | - } |
391 | | - } |
392 | | - return true; |
393 | | - } |
394 | | - |
395 | 248 | @ApiStatus.Internal |
396 | 249 | public static final class AnrV2Hint extends BlockingFlushHint |
397 | 250 | implements Backfillable, AbnormalExit { |
|
0 commit comments