Performance - Mobile

Only conducting performance testing at the conclusion of system or functional testing is like conducting a diagnostic blood test on a patient who is already dead.

How to?

There are many reasons why app is having performance issues, like bad CPU usage, unnecessary memory consumption, poor implementation of battery resources, etc.

To debug and overcome these issues you can use Android Profiler for Android apps and Instruments for iOS apps.

If testing with these tools and you notice too much CPU is used, battery is draining fast, etc., take a screenshot of profiler and attach it to your task because this will help developer to figure out problem much faster.

Android Profiler and Instruments

Android Profiler

The Android Profiler tools provide real-time data to help you to understand how your app uses CPU, memory, network, and battery resources.

Profiling ("program profiling", "software profiling") is a form of dynamic program analysis that measures, for example, the space (memory) or time complexity of a program, the usage of particular instructions, or the frequency and duration of function calls.

You will need Android Studio for this, go ahead and download it from this link and install it.

The Android Profiler is compatible with Android 5.0 (API level 21) and higher.

There are two ways to start profiling:

  1. You will need debug APK file.
  2. You will need an access to the codebaase.

You want to have debug APK because it is much easier and faster solution. If there is no debug APK, ask developer to build one for you. They always work with debug APK and it's not time consuming or complex for them to do it for you.

Steps:

  1. Open Android Studio.

  2. Select "Start a new Android Studio project".

  3. Select "Add no activity" and click on Next button.

  4. On "Configure your project" step, you can change project name, where to save the project, etc. You can only change Minimum API level to API level 21. Click on Finish button.

    You just created an empty project.

  5. Connect Android device with USB cable to Macbook and make sure USB debugging is enabled.

  6. In Android Studio, the connected device will be shown.

  7. Now you need to set up Profiler by going to File > Profile or debug APK > Select APK File (choose debug APK file you want to profile) > click OK.

  8. After APK file is loaded, go to Run > Profile.

  9. The app will open on your device. Profiler will start with collecting profiling data until you disconnect the device or click End Session.

Android Profiler shared timeline view

  1. Android Profiler shows the process and device currently being profiled.

  2. In the Sessions pane, choose which session to view, or start a new profiling session.

  3. Use the zoom buttons to control how much of the timeline to view, or use the Attach to live button to jump to the real-time updates.

  4. The event timeline shows events related to user input, including keyboard activity, volume control changes, and screen rotations.

  5. The shared timeline view, which includes graphs for CPU, memory, network, and energy usage.

Profilers

Network Profiler - The Network Profiler displays realtime network activity on a timeline, showing data sent and received, as well as the current number of connections

Energy Profiler - The Energy Profiler monitors the use of the CPU, network radio, and GPS sensor, and it displays a visualization of how much energy each of these components uses

Memory Profiler - The Memory Profiler can help you identify memory leaks and memory churn that can lead to stutter, freezes, and even app crashes

CPU Profiler - The CPU Profiler is used to inspect your app’s CPU usage and thread activity in real time while interacting with your app, or you can inspect the details in recorded method traces, function traces, and system traces

Instruments

The Instruments app in Xcode provides a rich set of tools and templates for profiling your app performance.

Although it’s embedded within and may be used with Xcode, Instruments is a separate app, which may be used independently as needed.

To install Xcode, go to App Store and install it from there.

To start using Instruments and profile the app, an iOS developer will need to install a debug build on your device (preferable). There is another option with using any build which doesn't require a developer but has a constraint which is hidden names for all collected data.

The other option is good if you only need to check overall app performance without digging deep into the data.

How to setup everything is explained below on example of non-debug build.

Steps:

  1. Connect an iPhone with Macbook and open the app you want to profile (this is important because it won't work if the app is closed).

  2. In Xcode, choose Xcode > Open Developer Tool > Instruments.

  3. In the profiling template selection dialog that appears, select a target device and find your app in the Running Applications list.

  4. Select a desired profiling template.

  5. Click Choose.

  6. Click the Record button in the toolbar (or press Command-R) to begin recording.

  7. Use your app or the system normally.

  8. Click the Stop button, or press Command-R again, when complete.

A trace document is used to organize and configure instruments for profiling, initiate data collection, and view and analyze the results.

The trace document includes the following main areas:

In the Instruments documentation you can find additional options this tool can give you like tracking CPU core and thread use, find performance bottlenecks and memory leaks, etc. You can even find zombies, I kid you not.


dil-90.jpg