Analyze or collect Xamarin stack traces for ANR in

2019-08-24 15:40发布

问题:

We are getting some stack traces for "background" (on broadcast reciever) ANR's in google play console. But there are all looking something like this:

"main" prio=5 tid=1 Native
  | group="main" sCount=1 dsCount=0 obj=0x7523b718 self=0xec085400
  | sysTid=13422 nice=0 cgrp=bg_non_interactive sched=0/0 handle=0xef6bb534
  | state=S schedstat=( 0 0 0 ) utm=74 stm=24 core=7 HZ=100
  | stack=0xff1ec000-0xff1ee000 stackSize=8MB
  | held mutexes=
  #00  pc 0000000000017520  /system/lib/libc.so (syscall+28)
  #01  pc 0000000000047cbd  /system/lib/libc.so (_ZL33__pthread_mutex_lock_with_timeoutP24pthread_mutex_internal_tbPK8timespec+520)
  #02  pc 000000000017e45c  /data/app/com.company.package-2/lib/arm/libmonosgen-2.0.so (???)

so we cannot get any useful information of what happens - analysis of code gives nothing. Is there any way of collecting C# stacks on ANR event?

回答1:

There is a package named Xamarin.ANRWatchDog that detects Android ANR errors (Application Not Responding) available via Nuget or from Github. It is a thread that watches for ANRs and then raises an error with stack traces for all of the threads. It was ported to Xamarin from Salomon Brys's ANR-WatchDog.