MTHawkeye is a set of debugging AIDS and performance optimization AIDS used by Meitu iOS team, aiming to help iOS developers improve development efficiency and assist in optimizing performance experience.

During the product development cycle, we introduced MTHawkeye to help us find, find, analyze, locate and solve problems faster:

  • In the development phase, it focuses on development and debugging assistance, timely detection of problems, and prompt developers to deal with them in time when necessary
  • The test phase focuses on collecting as much data as possible according to the test scenario for automated test analysis reports
  • In the online phase, it focuses on the performance data that traditional APM components are missing but needs to be collected by its own services

As a basic tool for daily use inside Meitu, it is now open source, and more practical plug-ins are expected to help developers improve efficiency and optimize App performance more conveniently. Star, submit Issue and PR are welcome, and external independent components are also welcome to plug into MTHawkeye.

What features are included in MTHawkeye

MTHawkeye can be simply divided into upper, middle and lower layers. In addition to the bottom basic layer, the middle layer is the UI basic layer. The responsibilities of each plug-in on the top layer are split according to different scenarios, and applications can be accessed according to their own needs.

The basic layer mainly provides plug-in management ability, storage ability and some basic tool classes.

The UI base layer provides the skeleton of the interface layer used in the development and testing phases, including suspension Windows, main interface frames, and Settings panels into which plug-ins can be integrated.

MTHawkeye’s top functional plug-ins are mainly performance detection plug-ins. FLEX is also introduced and improved as a plug-in for debugging assistance. Applications can customize and modify their own plug-ins when accessing MTHawkeye. The built-in plug-ins are divided into Memory, TimeConsuming, Energy, Network, Graphics, Storage, and Utility by focus.

1. Memory Plugins

# LivingObjectSniffer

The LivingObjectSniffer is used to track objects held directly or indirectly by the ViewController, as well as custom View objects, and detect them for unusual occurrences such as memory leaks, untimely releases, or unnecessary memory caches.

During the development and testing phases, detected anomalies can be presented to developers and testers in the form of floating window warnings and Toast. Automatic testing can also be directly extracted from the recorded live objects for further analysis and judgment.

# Allocations

Allocations class, same as Instrument Allocations, tracks memory details actually allocated to an application, and you can troubleshoot memory usage problems based on the recorded memory usage data when application memory usage exceptions (exceptions rise, OOM exits).

Demonstration of use in development and test stage:

The actual memory usage of automated use cases and user scenarios can be continuously tracked after automated testing and online phase access.

2. TimeConsuming Plugins

# UITimeProfiler

UITimeProfiler is used to aid optimization of main-thread time-consuming tasks. Internal divided into VC Life Trace and ObjC CallTrace two parts. VC Life Trace is used to Trace the specific time points in each stage of opening ViewController. ObjC CallTrace can Trace Objective-C methods whose time is greater than the specified threshold. Analogous to Instrument’s Time Profiler feature.

In the interface layer, the data of the two parts are displayed together, which is convenient for developers to find out time-consuming information about the process. The example is as follows:

After automated testing and in-stage access, startup time, page opening time and other key process time can be continuously tracked without burying or inserting other code.

# ANRTrace

ANRTrace is used to catch the lag event and sample the main thread call stack when the lag occurs

# FPSTrace

FPSTrace is used to track interface FPS and OpenGL refresh drawing FPS and display the current value on the floating window

3. Energy Plugins

# CPUTrace

CPUTrace is used to track persistent high CPU usage and record which methods are called during periods of high CPU usage.

4. Network Plugins

# Network Monitor

NetworkMonitor monitors and records the time of HTTP(S) network requests in the App and provides a built-in record viewing interface for developers to troubleshoot and optimize network problems.

  1. Inherited fromFLEXNetwork request log, filter search. At the same time, the listener initialization logic is optimized to greatly reduce the impact on startup time
  2. For iOS 9NSURLSessionRequest to add recordsURLSessionTaskMetricsEasy to view the time of each phase of the request
  3. Based on theURLSessionTaskMetricsAdded a waterfall view similar to Chrome network debugging to facilitate viewing network sequential and concurrent requests
  4. Added detection of repeated network requests
  5. Enhanced search bar to support multi-criteria search (domain name filtering, repeat request, URL filtering, status filtering)
  6. Record Displays complete network request records (add request headers, Request body, response body records).

Examples of development and test phase demonstrations:

# Network Inspect

NetworkInspect plug-in is based on Network Monitor. According to the actual situation of recorded Network requests, it detects whether there are items that can be improved and optimized, and the upper layer can define its own rules.

5. Graphics Plugins

# OpenGLTrace

The OpengGLTrace function is used to trace the usage of OpenGL resources and memory, and to help detect OpenGL API errors and abnormal parameter transfer.

The OpenGL rendering engine is very inconvenient to debug. Although Xcode provides the Frame Capture OpenGL ES debugging tool that allows us to debug every Frame during development, it is difficult to detect resource leaks during operation.

Therefore, OpenGLTrace uses FishHook to Hook the functions of OpenGL ES and CoreVideo on iOS platform to realize the monitoring of Texture/Program and other resources.

6. Storage Plugins

# DirectoryWatcher

DirectoryWatcher is mainly used to track the size of sandbox folders to help you find abnormal file management problems during development tests. It also integrates With FLEX’s sandbox file viewing and extends AirDrop support for files or folders.

7. Utility Plugins

# FLEX

The MTHawkeye plugin extension supports AirDrop functionality for sandbox files

Access to the

Refer to the Readme access instructions

Plug in your own plug-in

If you have a module that needs to avoid a lot of potholes in the development process, or a lot of debugging/optimization related logging code in the development process, you can consider writing a debugging assistant component, and then based on the MTHawkeye foundation framework API, this component can be used in the MTHawkeye framework, so as to unify the interaction and interface.

See the MTHawkeye plug-in development documentation for more details

Performance Impact

Refer to the documentation for each plug-in under the project repository for a description of the performance impact of each plug-in.

Open source address

  • Github.com/meitu/MTHaw…
  • Github.com/meitu/MTGLD…
  • Github.com/meitu/MTApp…