Xamarin Profiler is a tool which is used by the developers to keep an eye on the information about the particular App inside the Visual Studio. With the help of Xamarin Profiler, developers can easily analyze the App's behavior. We can use the profiler to track the application's memory information and can sample its statistics.
Profiling is an important and often overlooked step in application development. Profiling is a form of dynamic program analysis - it analyzes the program while it is running and in use. A profiler is a data mining tool that collects information about time complexity, the usage of particular methods, and the memory being allocated. A profiler enables you to drill deep and analyze these metrics to pinpoint problem areas in code.
Profiling is about finding resource usage that is out of place. Resources can include, network traffic, CPU, GPU, storage and/or memory usage. Because every app can behave differently, there is no set profile on how resource usage should look for your app, only guidelines.
There are 2 profilers you can use. The Xamarin Profiler for iOS and Android, and the Performance Profiler for UWP apps. The Xamarin Profiler is only available on Enterprise licensing. However the Performance Profiler is available on lower versions. Just another reason, it’s always handy to have a UWP app, for your Xamarin Forms application. More ....
Xamarin Profiler Setup
First you must download the Xamarin Profiler, and install the application.
But before we do that we need to ensure our iOS and Android apps are setup to be profiled.
Android
Go into the Properties of your Android project, then the Android Options tab, and ensure that Debugging is switched on and the debugger set to Xamarin.
iOS
Go into the Properties of your iOS project, ensure you enable Debugging and Enable Profiling.
Next, go to the Advanced Tab in the same window, and enable the SGen Generational Garbage Collector.
Running Xamarin Profiler
Next, if we run the Profiler, we get to choose which instruments we will use to be profiled, over time. One of the most common metrics you will look at, are the allocations, which also detail the total memory usage.
Once chosen, you will next be presented with the screen that shows the profiling in real time.
At the bottom of the screen, if you selected Allocations, are a list of allocations made. If you are looking at this and not understanding how you are meant to action this data, there is only one thing you really need to look for, and that is anomalies. You look at these details later. But what is an anomaly?
Noticing Anomalies
Anomalies normally come in different trends depending on what is happening. They are something that looks, out of place.
Memory
Memory can have 2 types of anomalies. First is the continuous upward trend. Where every page, or action taken, leads to more memory being consumed, but never released. Second, is large spikes, even if they are being released. This may be due to a large image, particularly in Android, being loaded.
CPU
CPU can show 2 types of patterns. Prolonged 100% CPU usage, or prolonged high CPU usage. This is normally anything above 2-3 seconds would be a concern. 2-3 seconds of 100% CPU usage would be a large concern as this will impact your UI responsiveness.
Second are spikes but you have to look closely. CPU spikes will be common as you move around your app, however if your aren’t interacting with your app and you continuously see spikes still occurring, it may mean a background thread is up to something it shouldn’t be.
App responsiveness and battery life are the two major impacts of CPU usage.
Performance Profiler
The performance profiler comes with Visual Studio and is great to profile UWP apps. I really love having a UWP project, in my Xamarin Forms app, if only for this reason. While it can’t pick out platform specific issues with your native Android and iOS code, it does give a great picture on your non-framework, Xamarin Forms code.
To profile and app, go to Analyze > Performance Profiler
So sadly you can't use the great features of Xamarin Profiler using Visual Studio Community, you need Enterprise. You can also get a trial for 30/90 days if I remember, so consider it.
If you want to profile iOS version of your app, I think you should be able to use Instruments tool from XCode, please follow this instructions: Profiling Xamarin.iOS Applications with Instruments. To open it, go for Tools → Instruments in Visual Studio for Mac.
If you want to profile Android app, check out Profiling Android Apps, it describes how to do it from Android Studio.
No comments:
Post a Comment