GithubHelp home page GithubHelp logo

tdappmonitorkit's Introduction

TDAppMonitorKit

TDAppMonitorKit是一套轻量级的应用性能管理组件,目前集成了UI卡顿检测、CPU占用分析以及Memory占用分析。

Install Required

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0

Install

You can use CocoaPods to install TDAppMonitorKit by adding it to your Podfile:

  • pod "TDAppMonitorKit"

Objective-C项目中使用

TDAppMonitorKit监控任务实现如下:

  • UI卡顿监控 TDAppFluencyMonitor

      [TD_FLUENCYMONITOR startMonitoring];
    
  • FPS监控 TDFPSMonitor

      [TD_FPSMONITOR startMonitoring];
    
  • CPU&Memory监控 TDResourceMonitor

      [TD_RESOURCEMONITOR startMonitoring];
    

Swift项目中使用

  • import TDAppMonitorKit

  • TDAppFluencyMonitor.shared().startMonitoring()

  • TDFPSMonitor.shared().startMonitoring()

  • TDResourceMonitor().startMonitoring()

原理简析

  • 获取栈上下文

  感谢bestswifter的BSBacktraceLogger,这是一个强大且轻量的线程调用栈分析器,它支持现有所有模拟器、真机的 CPU 架构,可以获取任意线程的调用栈,因此可以在检测到 runloop 检测到卡顿时获取卡顿处的代码执行情况。

  • UI卡顿监控   利用RunnLoop机制,通过创建子线程获取标志位flag的变化来检测主线程RunnLoop的event loop事件开始和结束时间段内,是否发生了阻塞。     关于RunnLoop的详情介绍。

  • FPS监控(CADisplayLink监控)

  监听RunLoop无疑会污染主线程。死循环在线程间通信会造成大量的不必要损耗。so,寻找更佳的检测方案变得迫不及待,我们知道从计算机的角度来说,假设屏幕在连续的屏幕刷新周期之内无法刷新屏幕内容,即是发生了卡顿。     FPS方案采用CADisplayLink的方式来处理, 思路是每个屏幕刷新周期派发标记位设置任务到主线程中,如果多次超出16.7ms的刷新阙值(iOS屏幕刷新周期为1/60s),即可看作是发生了卡顿。

  • CPU&Memory监控

  检测当前利用情况,这里监测的Memory占用情况与模拟器差别比较大,参考价值一般。

性能

采用与YYDispatchQueuePool相同的多线程封装技术,实现关键数据采集的异步处理。所有监控数据的展示采用异步渲染方式,对性能几乎无影响。同时数据展示控件和监控实现都只在DEBUG模式下生效,无需关注Release版本移除。

演示效果

tdappmonitorkit's People

Contributors

beckwang0912 avatar

Stargazers

Wilson Tang avatar shupeichen avatar  avatar  avatar xieqi avatar  avatar  avatar 端木 avatar wangjy avatar iRyan avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.