Caton optimization

Caton optimization

Caton optimization and optimization tools

  • Caton

    Caton easily intuitive feelings, and difficult to locate

    The reason Caton produce complex: Code, memory, drawing, IO, is difficult to reproduce

  • tool

    • CPU Profiler

      Graphically display the execution time, call stack, and so on; informative, containing all the threads; however runtime overhead is serious, as a whole will slow Debug.startMethodTracing ( "filename"); Debug.startMethodTracing ();

    • systrace

    • StrictMode

      When the detection mechanism harsh operating mode, Android provided to help developers to automatically detect code violations case, the reaction and gives a response in accordance with our configuration. Easy powerful, easily overlooked, two main problems detected thread policy and VM Strategies detection.

      Thread strategies: (1) time-consuming custom calling, detectCustomSlowCalls (); (2) disk reads, detectDiskReads, detectDiskWrites (); (3) network operations, detectNetwork ().

      VM strategy: (1) Activity disclosure, use detectActivityLeaks () is turned on; (2) is not closed Closable subject disclosure, use detectLeakedClosableObjects () is turned on; (3) Sqlite objects leaked use detectLeakedSqlLiteObjects () is turned on; (4) Detection Example the number of use setClassInstanceLimit () open.
      Development environment to start demanding mode, published applications must be disabled.

      reference

Caton automation and optimization testing program

  • Automatic detection scheme Caton principle

    System Tools targeted for offline analysis of the problem, but can not use the line; and Caton phenomenon very closely with the actual scene, so it is necessary to test aspects of online and automated testing programs while recording scenes of Caton occurred.

    Principle: message handling mechanism. A thread no matter how many Handler, Looper there is only one main thread to perform any of the methods which will be executed by the loop method Looper; the loop method has a mLogging objects are called before and after each Message processing; occur if the main thread Caton, that is to perform time-consuming operation, you can monitor the execution time of this method of operation used in mLogging in dispatchMessage.

    Specific realization: Looper.getMainLooper () setMessageLogging () to set its own logging, so before each massage will be handled after the call logging and set up their own; match to >>>>> Dispatching, after acquiring stack information and perform tasks Some current scenario information, such as memory size, power consumption, network status and the like; matched <<<<< Finished, described within the threshold of execution, message is processed, Caton does not occur, this task will cancel .

  • AndroidPerformanceMonitor practice

    AndroidPerformanceMonitor is a non-intrusive performance monitoring open assembly, a pop-up notification information Caton, positioning accuracy may be specific to a line. But there are some problems, indeed Caton, but Caton stack may not be accurate, and OOM, the final stack is only appearance, not the real problem. So, you can get multiple stacks within the monitoring period, not just the last one.

    startMonitor -> High Frequency Acquisition Stack -> endMonitor

    Record multiple stacks -> reporting server

    Caton is able to know during those methods in the implementation of those methods is time-consuming.

  • Problems and Optimization

    Caton related to the massive stack processing, high-frequency Caton reported amount is too large, the server will be pressure.

ANR Analysis and Practice

  • ANR

    ANR execution flow: ANR occur; abnormal termination process receives a signal to start writing process ANR information; ANR prompt pop-up box.

    ANR Solutions:

    (Offline) adb pull data / anr / traces.txt storage path (export); detailed analysis is ANR CPU, IO, etc. due to the lock.

    (Online) by FileObserver monitor file changes, there will be high version rights issues.

  • ANR-WatchDog Principles and Practice

    ANR-WatchDog is a non-invasive monitoring component ANR (open source), to make up for the higher version do not have permission to read the file traces.txt problem.

    Principle: start -> post message value change -> SLEEP -> detection of whether to modify -> ANR occurs Analyzing

Caton single-point problem detection

  • About Caton single-point problem

    Caton automatic detection scheme does not meet the requirements of all the scenes, and system solutions sure to expose the problem as soon as possible, a number of single-point issues that need attention are: the main thread IPC, DB, and so on.

  • IPC Monitoring

    • Detection Indicator: IPC call types, each called a number of times and time-consuming, call stack and the occurrence of thread.

    • General program: IPC buried around the point. Just enough elegance, a large maintenance costs.

    • Detection techniques: adb command "adb shell am trace-ipc start" to monitor; "adb shell am trace-ipc stop" detection end, and export the file to a data / local / tmp / ipc-trace.txt in.

    • Elegant solution:

      ARTHook: Hook systems approach can

      AspectJ: Non-system approach

    • Monitoring Latitude: IPC, IO, DB, View Draw

  • Of a single point detection scheme

Realization seconds on interface

  • Interface seconds on realization

    Seconds on the interface is a small start-up optimization, related to the startup optimization and layout optimization.

    SysTrace, elegant asynchronous elegant lazy initialization +

    Asynchronous Inflate, X2C, rendering optimization

    Page data acquired in advance.

  • Seconds on the interface rate statistics

    onCreate到onWindowFocusChanged

    Specific interface

  • Lancet

    Lightweight Android AOP framework (open source). Compilation speed, support for incremental compilation, simple API, without any extra code is inserted.

Blind spot monitoring time-consuming

Caton Optimization Tips

  • Consuming operations: asynchronous, delayed
  • Layout optimization: Asynchronous Inflate, X2C, redraw solve
  • Memory: reduced memory footprint, reduce time GC

System Tools: SysTrace, TraceView

Automated monitoring and optimization: AndroidPerformanceMonitor, ANR-WatchDog. Acquisition frequency, high stack find duplicate.

Caton monitoring tools: single-point problem AOP, Hook; blind spot monitoring gradle compiled replacement

Caton monitoring indicators: Caton rate, ANR rate, open rate second interface, interaction time, the statement cycle time reporting environment, scene information.

Caton optimization related issues

Caton optimization phase change:

The first stage: tool positioning system to solve

The second stage: the automation and optimization solutions Caton

The third stage: online monitoring and detection tool for building offline

Guess you like

Origin www.cnblogs.com/chen-ying/p/12549718.html