A Real-time Fps Tool for Android

Overview

fpsviewer

A Real-time Fps Tool for Android,

一个能实时显示fps,一段时间的平均帧率,以及帧率范围占比,并能获取卡顿堆栈的可视化工具。侵入性低,通过在异步线程采样获取堆栈,无代码侵入,性能消耗可忽略,对性能监控项的异常数据进行采集和分析,整理输出展示相应的堆栈,从而帮助开发者开发出更高质量的应用。

常见分析、定位卡顿的方案

系统工具

1. TraceView

目前一般是用现在AndroidStudio里的cpu-profile工具或者TraceCompat.beginSection()生成trace日志, 准确性高,这种分析方式只适合定性分析,因为工具很消耗cpu,有很多假jank,非常影响性能,显示耗时和实际耗时偏差很大,平常开发过程中也不易用,不可能实时开着,没法查看fps。

2. Systrace Systrace用来检测android系统各个组件随着时间的运行状态,并能提示该如何有效地修复问题,主要偏向于分析一段时间整个系统所处的状态,无法定位到具体代码。

3. 命令行adb shell dumpsys SurfaceFlinger --latency com...包名 用来计算一段时间的帧率,无法获取卡顿栈,只能一段时间

以上几种系统提供的方案一般只能在比较短的时间进行分析,平常开发过程中也很不方便。

第三方库方案

  • Matrix-TraceCanary 微信的卡顿检测方案,采用的ASM插桩的方式,支持fps和堆栈获取的定位,但是需要自己根据asm插桩的方法id来自己分析堆栈,定位精确度高,性能消耗小,比较可惜的是目前没有界面展示,对代码有一定的侵入性。如果线上使用可以考虑。

  • BlockCanaryEx 主要原理是利用loop()中打印的日志,loop()中打印的日志可以看鸿洋的这篇博客Android UI性能优化 检测应用中的UI卡顿,支持方法采样,知道主线程中所有方法的执行时间和执行次数,因为需要获取cpu以及一些系统的状态,性能消耗大,不支持fps展示,尤其检测到卡顿的时候,会让界面卡顿很久。之前我们项目用的就是这个工具。

  • fpsviewer 利用Choreographer.FrameCallback来监控卡顿和Fps的计算,异步线程进行周期采样,当前的帧耗时超过自定义的阈值时,将帧进行分析保存,不影响正常流程的进行,待需要的时候进行展示,定位。

fpsviewer 特点

  1. 无损FPS实时显示,一段时间的平均帧率和帧率占比 利用Choreographer.FrameCallback的fun doFrame(frameTimeNanos: Long)方法回调里获取数据计算每帧消耗的时长,实时性高且不需要额外的数据获取无其他性能消耗,开启和关闭fpsviewer对帧率的影响远小于1帧。支持一段时间的平均帧率和帧率占比显示,可用于性能优化前后的对比。

  2. 更详细的堆栈信息,便于定位卡顿源,采样的方式或者堆栈,而不是卡顿发生的瞬间获取堆栈可能造成堆栈偏移从而影响准确性,异步线程在自定义的采样时间(一般>30ms)进行堆栈获取,每次的耗时很小,只有发送卡顿才需要存储分析,也是在异步线程,对主线程无影响,对整体cpu的影响也可忽略不计。一般得到的是多个堆栈信息,按照这段时间的发生次数排序

  3. 支持自定义的堆栈标记,类似于 TraceCompat.beginSection(),方便分析具体业务的卡顿,比如某个列表,某次Activity或者App的启动过程中的卡顿耗时。

效果图

[实时fps]

image

[功能选择]

image

点击分析图标显示:

image

上图折现里点击具体的卡顿点可查看详细的堆栈信息如下: [详细堆栈图] image

首页或者上图点击bug图标可展示一段时间的卡顿列表 image

可长按删除或者进入详细堆栈界面标记为已解决,点击可进入详细的堆栈信息界面,TestSection就是自定义的TAG。

引入

Step1.Add it in your root add build.gradle at the end of repositories:

allprojects {
	repositories {
		..
		maven { url 'https://jitpack.io' }
	}
}

Step2. Add the dependency:

dependencies {
    debugImplementation "com.github.silencedut.fpsviewer:fpsviewer:latestVersion"
    releaseImplementation "com.github.silencedut.fpsviewer:fpsviewer-no-op:latestVersion"
}

初始化,按需添加Section

interface IViewer {
    fun initViewer(application: Application,fpsConfig: FpsConfig? = null)
    fun fpsConfig():FpsConfig
    fun appendSection(sectionName:String)
    fun removeSection(sectionName:String)
}

License

Copyright 2018-2019 SilenceDut

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Emotion recognition by speech in android.
Emotion recognition by speech in android.

Vokaturi - Android Library Android port of the Vokaturi emotion recognition API. Overview Vokaturi is an emotion recognition software, that can unders

Free p2p cdn android github sdk to reduce video streaming costs  of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀
Free p2p cdn android github sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀

Android p2p cdn sdk to distribute load and reduce costs(https://peervadoo.com) Vadootv is a p2p sdk integration to reduce your video streaming costs b

A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView
A better Android VideoView with more Media Controller customization. 一个更好用的Android VideoView

Android UniversalVideoView 中文版说明请点击这里 UniversalVideoView is a Android widget helps playing video easier, which is similar with the Android system nati

Android Texture VideoView having a variety of scale types like the scale types of ImageView such as fitCenter, centerCrop, centerTopCrop and more
Android Texture VideoView having a variety of scale types like the scale types of ImageView such as fitCenter, centerCrop, centerTopCrop and more

Android-ScalableVideoView Looking for the extra scale types of ImageView? Check out ScalableImageView. Android Texture VideoView having a variety of s

Android Video Crop
Android Video Crop

🔺 Before using this library, read information below 🔺 This library is not more supported. If you want to add new feature or fix a bug, grab source

Android music player example.
Android music player example.

Android music player example.

A elegant and light weight music player for android
A elegant and light weight music player for android

A elegant and light weight music player for android

NOVA is an open source video player for Android

NOVA: opeN sOurce Video plAyer Overview NOVA is an open source video player for Android. It consists in a fork of the original Archos Video Player Com

Simple and lightweight, yet polished and powerful Android video player based on ExoPlayer
Simple and lightweight, yet polished and powerful Android video player based on ExoPlayer

Just (Video) Player Android video player based on ExoPlayer It uses ExoPlayer's extension-ffmpeg with all its audio formats enabled (it can handle eve

Owner
Talk is cheap ,here's my code
null
:sound: [Android Library] Easily generate pure audio tone of any frequency in android

Android library to easily generate audio tone in android. Generating pure tone of an specific frequency was never that easy. ZenTone does all the heav

Nishant Srivastava 102 Dec 19, 2022
mpv-android is a video player for Android based on libmpv.

mpv-android is a video player for Android based on libmpv.

null 1.1k Jan 6, 2023
FFmpeg compiled for Android. Execute FFmpeg commands with ease in your Android app.

FFMPEG video operations FFmpeg compiled for Android. Execute FFmpeg commands with ease in your Android app. Getting Started This project is provide in

Simform Solutions 277 Jan 2, 2023
Echo is a lightweight and minimal music player for Android, built with Android Studio and written in Kotlin

Echo - Echo, A light-weight, minimal music player for Android, with shuffle, favorites and audio visualization

Divins Mathew 0 Feb 7, 2022
Youtube Android Clone 🚀an Android Youtube Clone made out of XML and Kotlin

Youtube Android Clone ?? This app consumes The Youtube Api to fetch and display a list of popular videos, The app uses MVVM design pattern to allow se

Breens Robert 38 Dec 13, 2022
An extensible media player for Android

ExoPlayer ExoPlayer is an application level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and vi

Google 20.2k Jan 1, 2023
Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.

ijkplayer Platform Build Status Android iOS Video player based on ffplay Download Android: Gradle # required allprojects { repositories {

bilibili 31k Jan 3, 2023
Custom Android view with video player, loader and placeholder image

VideoPlayerView Custom Android view with video player, loader and placeholder image. To stay up-to-date with news about the library Usage Here is an e

Marcin Moskała 89 Nov 18, 2022
[] FFmpeg build for android random architectures with example jni

AndroidFFmpegLibrary This project aims to create working library providing playing video files in android via ffmpeg libraries. With some effort and N

AppUnite Sp. z o.o. Spk. 1.1k Dec 27, 2022