MoonLight open Source project author Agora Echoo J

What is MoonLight?

MoonLight is a lightweight performance test component for iOS/Mac that can be independently integrated into any App to automate the collection of performance data. You can easily access App CPU, System CPU, App Memory, System GPU, and GPU Info data. MoonLight was developed by Agora and has been open-source to Github.

Open source: github.com/AgoraIO-Com…

MoonLight vision

MoonLight, its Chinese name is MoonLight. It is peaceful and natural for moonlight to spread over the earth, and it will give guidance to people on the earth. The moral of moonlight is exactly the same as our starting point for developing performance test components.

We want iOS/Mac performance testing to be as easy and natural as moonlight. MoonLight has lower performance costs, easier to use, and more accurate performance data. It helps development teams locate performance problems faster and more accurately, leading to performance optimization and improvement. Help test team to obtain performance data faster and more accurately, improve test efficiency.

Compare other performance testing tools

Instruments

The performance data collected by MoonLight is basically consistent with Instruments. The specific comparison of advantages and disadvantages is as follows:

  1. Instruments does not automate performance and cannot extract performance data for analysis, resulting in poor accuracy and human error. MoonLight can solve this problem.

  2. Instruments does not allow for remote performance testing, nor does it allow for high-concurrency performance testing, which typically requires one device to be connected to a USB cable, and then the next. MoonLight can test many units at one time, and there is no requirement to connect data lines.

  3. While higher versions of Instruments cannot test the performance of some low-end systems, MoonLight supports them perfectly.

  4. For Apps on macOS, Instruments does not support GPU output, MoonLight is supported. After testing, the output of the GPU is consistent with the output of the macOS built-in activity manager GPU.

  5. The advantages of Instruments are data visualization and memory leak testing. MoonLight does not provide data visualization for the time being, but since MoonLight is programmable, developers can implement data reporting or visualization when they get the relevant performance data.

GT

  1. GT does not support macOS, MoonLight is supported.

  2. The App Memory data collected by GT is inconsistent with that of Instruments. GT cannot output GPU and System CPU, but MoonLight can.

  3. GT integration into App requires a lot of dependent libraries to be added and the Bitcode support to be cancelled. It is also quite large and will increase the package size of App. MoonLight is lighter, only need to add one system library for iOS, no need to add any system library for Mac.

Perfdog

  1. Perfdog does not support performance testing of apps on macOS.

  2. Perfdog is not an automated performance testing tool, but has the advantage of data visualization.

  3. Perfdog is not an open source testing tool. There was a Bug of inaccurate App CPU in iOS 14 before, and we do not know the principle and code of its implementation. In the future, there may still be inaccurate performance items in some systems.

Requirements

  • IOS 8.0 +
  • MacOS 10.11 +

Installation

Cocoapods

  • iOS:

Warning! For iOS, do not use it on AppStore release. Recommend use it on debug mode.

pod 'MoonLight_iOS', :configurations => ['Debug']
Copy the code
  • macOS:
pod 'MoonLight_macOS'
Copy the code

Usage

// Step1: create MoonLight instance and set sampling interval. _moonLight = [[MoonLight alloc]initWithDelegate:self timeInterval:1]; // Step2: start timer. [_moonLight startTimer]; // Step3: through the callback, you can get all the performance data per interval. - (void)captureOutputAppCPU:(float)appCPU systemCPU:(float)systemCPU appMemory:(float)appMemory gpuUsage:(float)gpuUsage gpuInfo:(NSString *)gpuInfo { NSLog(@"appMemory:%f", appMemory); NSLog(@"appCPU:%f", appCPU); NSLog(@"gpuUsage:%f", gpuUsage); NSLog(@"systemCPU:%f", systemCPU); NSLog(@"gpuInfo:%@", gpuInfo); } // Step4: If you want to stop capturing the performance data, use "stopTimer". [_moonLight stopTimer];Copy the code

MoonLight self-test results

The performance cost of iOS/Mac MoonLight itself is very low and almost negligible; During the test, the performance output was stable. App CPU, System CPU, App Memory, and GPU can be consistent with Instruments or activity monitor results.

MoonLight VS Instruments

  • iOS

  • macOS

Note: MoonLight normalizes processing for the CPU. CPU(MoonLight) = CPU(Instruments)/Number of cores

Second, MoonLight itself performance consumption

Test case:

Step1: open App, open MoonLight detection, and test performance data1.

Step2: Open App, do not open MoonLight detection, and test performance data2. Performance cost = datA1 – data2

  • iOS

App Memory consumption = 7.38-7.34 = 0.04Mb; App CPU consumption = (2.1-0.1%)/(6 cores) = 0.33%; GPU = 0%, and during the whole performance test phase, data fluctuated steadily, and there was no unstable change in performance caused by the opening of MoonLight.

Test device: iPhone XS iOS 14.2 six core

  • macOS

App Memory consumption = 14.42-14.36 = 0.06Mb; App CPU consumption = (0.08%-0.0%)/(4 cores) = 0.02%; GPU = 0%, and during the whole performance test phase, data fluctuated steadily, and there was no unstable change in performance caused by the opening of MoonLight.

Test device: Macbook Pro 2017 13.3 Intel I5, System: BigSur 11.0.1

— — — — — — — — — — — — — —

Write in the last

MoonLight is an open source tool from our daily development. We hope it can help development teams locate performance problems faster and more accurately, thus driving performance optimization and improvement. Help test team to obtain performance data faster and more accurately, improve test efficiency. Welcome to use it.

MoonLight open source address: github.com/AgoraIO-Com…