How To Use Xamarin Profiler With Visual Studio

Introduction

 
Developing mobile apps with Xamarin is easy but it’s not enough to develop a mobile app. To develop a good mobile app, it has to pass certain parameters as an app should be user friendly, UI should be perfect over all the devices and platforms, there should be good memory management, all the exceptions should be handled etc. With Xamarin profiler, the developers will easily find the Memory leaks, resolve the performance issues, exceptions, get to know the application's memory consumption etc. All these parameters are provided by Xamarin profiler, which makes the Application perfect.
 

Solution

 
Xamarin profiler provides various options to measure the performance, as shown below.
  • Allocation
    It gives data about the memory, it gives you data about the memory allocation, object allocation, live objects, private bytes and call tree.

  • Cycles
    To track the memory cycles, here you will get cycles graph and its stack trace, which helps the developers to find the memory leaks.

  • Time Profiler
    It is used to track the performance of the Application.
Here are steps to use Xamarin profiler with Visual Studio.
 
Prerequisites
  • Visual Studio Enterprise Edition.
  • Xamarin
  • Emulator or mobile device (preferred)
Step 1

Download and Install Xamarin profiler in your system. To download, visit here.
 
Step 2

Now, open your solution in Visual Studio and go to Analyze menu. Select Xamarin profiler. For details, refer the screenshot.
 
Note
When you select the project, make sure that you have selected Device / Emulator, which is in running mode because Xamarin profiler will analyze the results on the real app.

 
Step 3

Now, Xamarin profiler opens up, as shown in the screenshot.
 
 
Here, select appropriate option. It is recommended to select All Instruments.
 
 
Step 4

Now, Xamarin profiler gets launched for your Application. Here, you can see various options, as shown in the screenshot.
In the screenshot, it shows the data about the application as total running time, selected device and other statics.
 
Step 5

Now, use app for some time and select allocation option, where you will get the data about the memory, as shown below.
  • Memory Allocation
  • Object Allocation
  • Live objects
  • Private Bytes
  • Working set
  • Virtual Bytes
Here, you can find the data by each screen, the developer will get the data by the screen; i.e., which screen has the memory leaks and how many objects are there, how much memory is consumed by the View Model or the page etc. For details, refer to the screenshot given below.
 
 
Step 6

Now, select the Cycles option. Here, you will get the data, as per the method. It shows the call stack per method, as shown in the screenshot given below.
 
It shows the data about all the compiled methodd and its call tree, which helps the developers to find out the memory leaks by the methods.
 
 
Step 7

Now, select Time profiler, which helps the developers to find out the CPU usage time of the Application and it also helps the developers to understand where the application is taking load on the mobile. For more details, refer to the screenshot given below.
 
It also helps the developers for,
  • CPU usage time.
  • Running time of the page.
  • Details about the threads etc.

Step 8

In Xamarin profiler, there is an option snapshots, which takes the snapshots in your specified time or when GC (Garbage Collector) occurs. It helps the user to get the data about the Application.
 
It shows data inside the Snapshots tab where the developer can get the data by the snapshots.
 

 
Step 9

The snapshots appear as a red line, as shown in the screenshot.
  • It shows the data per snapshots and shows the data in the snapshot tab.
  • In the snapshot tab, it shows Timestamp, object growth and Size Growth.
  • If the GC (Garbage Collector) gets called, it also shows its data.
Step 10

In File option, you can store the profiler data and also use it in future for the reference and you can share it with the respective team members, clients and developers etc.
 
Here, we have learnt how to use Xamarin profiler with Visual Studio.


Similar Articles