-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrumentation for StrictMode #520
Comments
That sounds interesting, though it seems like StrictMode is more targeted as a development tool, so I'm wondering if there's a non-trivial performance overhead caused by enabling it? |
I've done a small analysis on the performance on a Pixel 3a XL, Android 12. At least from here it does look like there is an overhead.
As for the code... val uid = UUID.randomUUID()
val times = 10
val enableSm = true
val executor = ContextCompat.getMainExecutor(applicationContext)
if (enableSm) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyListener(executor) {}
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyListener(executor) {}
.build()
)
}
Debug.startMethodTracing(
getExternalFilesDir(null)!!.absolutePath + "/${times}_strictmode_${enableSm}_$uid.trace"
)
repeat(times) {
getSharedPreferences(it.toString(), MODE_PRIVATE)
.edit()
.apply { repeat(8) { putString(it.toString(), it.toString()) } }
.commit() // ...triggers DiskReadViolation
}
Debug.stopMethodTracing() |
Thank you for taking the time to collect and provide this info 🙏 it helps a lot. Based on what you found I'd say that we shouldn't provide this kind of instrumentation by default to avoid affecting apps' performance unless it's really needed. It's still probably worth creating some opt-in instrumentation for it, though I'd like to get some people to chime in just to get an idea of what's the appetite for it. |
I agree with you. One thing I want to also highlight is that the above example essentially only triggers one type of violation. So in an actual application, there could be an even bigger overhead. That said, in my honest opinion, there is still value to be gained, especially (or perhaps exclusively) in staging environments. Curious to hear what others think as well! 🙌🏽 |
@MrHadiSatrio this is interesting for sure. Is the expected usage for application developers to have additional ways of leveraging I think it's perfectly acceptable for us to have instrumentation in this repo that isn't necessarily enabled by default or included in the topmost agent. Seems like a worthy experiment. Is it also possible to turn these strict mode configurations back off? |
@breedx-splk, yes. StrictMode violations are reported to the listeners as
Yes, it is. StrictMode policies can be changed at any time. One could assign either Come to think of it, the above does mean that users would be able to accidentally turn the instrumentation off without the library being aware of it. :/ |
So I took a quick stab at the idea and did a spike implementation on this branch. I couldn't seem to surface the logs on Jaeger, so I went with grafana/otel-lgtm instead. Here's what a StrictMode dashboard may look like: |
I've found that strict mode violation tend to be the result of structural issues with the code, so deploying it on a beta or dogfood build is usually sufficient when trying to ferret out said issues. If we were add this to the project, I think making this opt-in would be desirable so that it can be enabled for certain flavors or builds, but not in general production. |
Hello. Are there any plans for StrictMode instrumentation?
ThreadPolicy#penaltyListener()
andVmPolicy#penaltyListener()
which were added in API 28 may provide a solid foundation for one.The text was updated successfully, but these errors were encountered: