Sampling Profiler & Rogue case of App Profiling | by Akash Khunt | Mar, 2023 | Path Tech

almost Sampling Profiler & Rogue case of App Profiling | by Akash Khunt | Mar, 2023 will cowl the most recent and most present suggestion as regards the world. proper to make use of slowly correspondingly you comprehend capably and accurately. will mass your information dexterously and reliably

This can be a publish on how a false constructive efficiency problem (i.e. Most important thread idle for ~1 second throughout software startup) brought on me to spend many days debugging and figuring out the basis trigger. This problem was solely seen when profiling a launch construct, and that too is on a tool that was restricted in reminiscence (RAM) and CPU energy.

Background

First let’s cowl some background. In case you’ve just lately tried profiling an Android app to determine/debug some efficiency points or simply to seize startup time metrics, you is likely to be accustomed to a quite common however very helpful suggestion that it’s best to at all times create a profile. profile. launch construct

The explanation behind the use launch is constructed whereas it’s outlined is that debug The builds incur important and assorted efficiency degradation, and should not helpful for timing precisely. This efficiency degradation might be attributed to one of many many debugging construct capabilities that permits builders to connect a debugger at any time, which requires monitoring of many issues, equivalent to reminiscence and stack traces.

However since launch builds are supposed to be non-debuggable and better performing, they do not observe something out of the field and are due to this fact not profilerable. To handle this problem, the Android staff launched profileable manifest configuration in API 29, which is secure to maintain even throughout launch builds, permitting us to profile a launch construct with a lot much less efficiency overhead and minimal concern about information publicity, as construct instruments Host profiles and the shell course of can’t learn information from reminiscence.

The query

I confronted this fundamental thread idle problem once I was profiling our app on totally different units of units to cut back chilly begin time. To get the beginning time (i.e., TTID & TTFD) I created a macro reference level module in my app. The great thing about macrobenchmark testing is that it additionally generates systrace recordsdata that you should utilize to grasp what totally different threads are doing at any given time. From the take a look at outcomes, I discovered a number of the bottlenecks, one of many greatest ones was the consumer attribution callback, which concerned a community name that contributed 20%-25% of the TTFD time. .

The issue right here was that we have been making the Person wait till we received the decision attribution information from the community. From systrace information at a low stage (2GB RAM) we additionally noticed that the primary thread was idle for ~1 second 😲 as you’ll be able to see within the screenshot beneath.

Word: The title of the primary thread will likely be hidden for confidentiality of the applying.

systrace demonstration Main sleeping yarn for ~1s

This appeared like a simple win to cut back chilly begin time, so we began dialogue with our product staff and received approval to proceed with deferred dealing with of the attribution callback, i.e., enable the consumer to proceed to our house web page with out blocking it.

Very attentive eyes might need additionally observed from the systrace screenshot above that Jit Thread Pool it is also working for an honest period of time which might be considerably diminished by integrating Reference profiles. πŸ™‚

After making the suitable change, we ran the exams once more and noticed that our TTFD time was diminished by ~20% on a high-end machine (8 GB RAM and Android 13), however on a lower-end machine (2 GB RAM and Android 10) it was nonetheless very comparable. As a primary troubleshooting step, we ran the startup time take a look at once more (like many issues in life, the primary troubleshooting step is at all times to retry the failed step πŸ˜‰) however the outcome was the identical πŸ˜….

I then ended up spending a number of days figuring out the problem that is likely to be inflicting the primary thread to hold for 1 second, however discovered nothing. Then at some point, I used to be randomly what every of the threads spawned by our software was doing when the primary thread went to sleep and I lastly discovered the wrongdoer. he was the Sampling Profiler the thread that for some cause solely appeared alive for 1 second (precisely on the similar time the primary thread went to sleep), the place more often than not it was additionally sleeping, as proven within the screenshot beneath.

Sampling Profiler thread to be alive and sleeping for 1s similtaneously Main yarn goes to sleep

By reviewing the traces of the Sampling Profiler thread, I found that it was primarily performing two operations which have been Connect present thread & Detach CurrentThread As proven beneath.

Observe Information Sampling Profiler thread

I additionally tried transferring a whole lot of code right here and there to see if there have been any particular situations that might result in beginning this Sampling Profiler thread, a really imprecise correlation I noticed was each time the primary thread appeared idle for a number of hundred milliseconds. , the Sampling Profiler was spawning to do its job.

Just like the title β€œSampling Profiler” means that it gave the impression to be performing some profiling associated work, so we concluded that it should not have an effect on precise consumer periods. However since we nonetheless needed to make sure, I eliminated the <profileable> ingredient of the Manifest file to make sure that the applying just isn’t even profileable when capturing the traces. And the way did I take away the ingredient? I could not run benchmarking exams accurately anymore, so I ended up utilizing Seize/Log Observe choice current in developer choices to seize the hint file. And after trying on the hint recordsdata, we confirmed that the 1s fundamental thread hold problem is lastly gone πŸ™Œ.

Conclusion

Though it was including 1 second delay on many of the macro timing metrics i.e. TTID and TTFD, it isn’t doable to maintain it eliminated as it is extremely a lot wanted to run the benchmarking exams. So we lastly got here to the conclusion that earlier than utilizing any type of macro time metric on low-end units, we’ll take away 1s from the reported time (after parsing the hint recordsdata).

I hope this publish saves you a number of hours if not days debugging an issue that does not even have an effect on actual customers πŸ™‚.

I want the article almost Sampling Profiler & Rogue case of App Profiling | by Akash Khunt | Mar, 2023 provides sharpness to you and is beneficial for complement to your information

Sampling Profiler & Rogue case of App Profiling | by Akash Khunt | Mar, 2023

x