其他分享
首页 > 其他分享> > 安卓专项 fps获取

安卓专项 fps获取

作者:互联网

场景

需要实时获取到设备当前fps情况

实现

使用命令:adb shell dumpsys gfxinfo packageName framestats

百度得知在Android 6.0以后为gfxinfo 提供了一个新的参数framestats,其作用可以从最近的帧中提供非常详细的帧信息,以便您可以更准确地跟踪和调试问题。

是不是可以理解成,获取的是最近的帧数

当输出这段命令后得出很多信息

Applications Graphics Acceleration Info:
Uptime: 1106458765 Realtime: 1548873615

** Graphics info for pid 29610 [com.tencent.qqlive] **

Stats since: 1106443053616620ns
Total frames rendered: 12
Janky frames: 3 (25.00%)
50th percentile: 12ms
90th percentile: 18ms
95th percentile: 40ms
99th percentile: 40ms
Number Missed Vsync: 0
Number High input latency: 3
Number Slow UI thread: 1
Number Slow bitmap uploads: 0
Number Slow issue draw commands: 0
Number Frame deadline missed: 2
HISTOGRAM: 5ms=0 6ms=0 7ms=0 8ms=1 9ms=0 10ms=0 11ms=4 12ms=3 13ms=0 14ms=1 15ms=0 16ms=0 17ms=1 18ms=1 19ms=0 20ms=0 21ms=0 22ms=0 23ms=0 24ms=0 25ms=0 26ms=0 27ms=0 28ms=0 29ms=0 30ms=0 31ms=0 32ms=0 34ms=0 36ms=0 38ms=0 40ms=1 42ms=0 44ms=0 46ms=0 48ms=0 53ms=0 57ms=0 61ms=0 65ms=0 69ms=0 73ms=0 77ms=0 81ms=0 85ms=0 89ms=0 93ms=0 97ms=0 101ms=0 105ms=0 109ms=0 113ms=0 117ms=0 121ms=0 125ms=0 129ms=0 133ms=0 150ms=0 200ms=0 250ms=0 300ms=0 350ms=0 400ms=0 450ms=0 500ms=0 550ms=0 600ms=0 650ms=0 700ms=0 750ms=0 800ms=0 850ms=0 900ms=0 950ms=0 1000ms=0 1050ms=0 1100ms=0 1150ms=0 1200ms=0 1250ms=0 1300ms=0 1350ms=0 1400ms=0 1450ms=0 1500ms=0 1550ms=0 1600ms=0 1650ms=0 1700ms=0 1750ms=0 1800ms=0 1850ms=0 1900ms=0 1950ms=0 2000ms=0 2050ms=0 2100ms=0 2150ms=0 2200ms=0 2250ms=0 2300ms=0 2350ms=0 2400ms=0 2450ms=0 2500ms=0 2550ms=0 2600ms=0 2650ms=0 2700ms=0 2750ms=0 2800ms=0 2850ms=0 2900ms=0 2950ms=0 3000ms=0 3050ms=0 3100ms=0 3150ms=0 3200ms=0 3250ms=0 3300ms=0 3350ms=0 3400ms=0 3450ms=0 3500ms=0 3550ms=0 3600ms=0 3650ms=0 3700ms=0 3750ms=0 3800ms=0 3850ms=0 3900ms=0 3950ms=0 4000ms=0 4050ms=0 4100ms=0 4150ms=0 4200ms=0 4250ms=0 4300ms=0 4350ms=0 4400ms=0 4450ms=0 4500ms=0 4550ms=0 4600ms=0 4650ms=0 4700ms=0 4750ms=0 4800ms=0 4850ms=0 4900ms=0 4950ms=0
Font Cache (CPU):
  Size: 13179.49 kB 
  Glyph Count: 249 
CPU Caches:
GPU Caches:
  Other:
    Other: 69.04 KB (1 entry)
    Buffer Object: 41.05 KB (4 entries)
  Image:
    Texture: 57.85 MB (120 entries)
  Scratch:
    RenderTarget: 352.50 KB (6 entries)
    Texture: 14.61 MB (16 entries)
    Buffer Object: 48.00 KB (1 entry)
Other Caches:
                         Current / Maximum
  VectorDrawableAtlas    0.00 kB /   0.00 KB (entries = 0)
  Layer Info:
    GlLayer size 0x0
    GlLayer size 0x0
    GlLayer size 0x0
    GlLayer size 0x0
  Layers Total           0.00 KB (numLayers = 4)
Total GPU memory usage:
  76503456 bytes, 72.96 MB (59.70 MB is purgeable)


Pipeline=Skia (OpenGL)

Layout Cache Info:
  Usage: 5000/5000 entries
  Hit ratio: 484225/491651 (0.984896)
Profile data in ms:

	com.tencent.qqlive/com.tencent.qqlive.ona.activity.SplashHomeActivity/android.view.ViewRootImpl@692c240 (visibility=0)
	Draw	Prepare	Process	Execute
	4.84	0.77	7.15	1.84
	3.27	0.57	3.66	3.81
	2.63	0.54	4.08	1.21
	2.94	0.54	7.37	1.78
	3.50	0.54	5.34	1.68
	3.86	0.62	5.63	1.54
	4.44	0.64	5.67	1.63
	3.28	0.68	5.61	1.72
	4.11	0.63	5.58	2.35
	4.35	2.03	10.28	2.14
	5.26	1.74	8.33	1.81
	29.21	1.91	6.96	2.76

Window: com.tencent.qqlive/com.tencent.qqlive.ona.activity.SplashHomeActivity
Stats since: 1106443053615787ns
Total frames rendered: 12
Janky frames: 3 (25.00%)
50th percentile: 12ms
90th percentile: 18ms
95th percentile: 40ms
99th percentile: 40ms
Number Missed Vsync: 0
Number High input latency: 3
Number Slow UI thread: 1
Number Slow bitmap uploads: 0
Number Slow issue draw commands: 0
Number Frame deadline missed: 2
HISTOGRAM: 5ms=0 6ms=0 7ms=0 8ms=1 9ms=0 10ms=0 11ms=4 12ms=3 13ms=0 14ms=1 15ms=0 16ms=0 17ms=1 18ms=1 19ms=0 20ms=0 21ms=0 22ms=0 23ms=0 24ms=0 25ms=0 26ms=0 27ms=0 28ms=0 29ms=0 30ms=0 31ms=0 32ms=0 34ms=0 36ms=0 38ms=0 40ms=1 42ms=0 44ms=0 46ms=0 48ms=0 53ms=0 57ms=0 61ms=0 65ms=0 69ms=0 73ms=0 77ms=0 81ms=0 85ms=0 89ms=0 93ms=0 97ms=0 101ms=0 105ms=0 109ms=0 113ms=0 117ms=0 121ms=0 125ms=0 129ms=0 133ms=0 150ms=0 200ms=0 250ms=0 300ms=0 350ms=0 400ms=0 450ms=0 500ms=0 550ms=0 600ms=0 650ms=0 700ms=0 750ms=0 800ms=0 850ms=0 900ms=0 950ms=0 1000ms=0 1050ms=0 1100ms=0 1150ms=0 1200ms=0 1250ms=0 1300ms=0 1350ms=0 1400ms=0 1450ms=0 1500ms=0 1550ms=0 1600ms=0 1650ms=0 1700ms=0 1750ms=0 1800ms=0 1850ms=0 1900ms=0 1950ms=0 2000ms=0 2050ms=0 2100ms=0 2150ms=0 2200ms=0 2250ms=0 2300ms=0 2350ms=0 2400ms=0 2450ms=0 2500ms=0 2550ms=0 2600ms=0 2650ms=0 2700ms=0 2750ms=0 2800ms=0 2850ms=0 2900ms=0 2950ms=0 3000ms=0 3050ms=0 3100ms=0 3150ms=0 3200ms=0 3250ms=0 3300ms=0 3350ms=0 3400ms=0 3450ms=0 3500ms=0 3550ms=0 3600ms=0 3650ms=0 3700ms=0 3750ms=0 3800ms=0 3850ms=0 3900ms=0 3950ms=0 4000ms=0 4050ms=0 4100ms=0 4150ms=0 4200ms=0 4250ms=0 4300ms=0 4350ms=0 4400ms=0 4450ms=0 4500ms=0 4550ms=0 4600ms=0 4650ms=0 4700ms=0 4750ms=0 4800ms=0 4850ms=0 4900ms=0 4950ms=0


---PROFILEDATA---
Flags,IntendedVsync,Vsync,OldestInputEvent,NewestInputEvent,HandleInputStart,AnimationStart,PerformTraversalsStart,DrawStart,SyncQueued,SyncStart,IssueDrawCommandsStart,SwapBuffers,FrameCompleted,DequeueBufferDuration,QueueBufferDuration,
0,1106454791794353,1106454791794353,9223372036854775807,0,1106454793276355,1106454793279533,1106454795738751,1106454795936043,1106454796630418,1106454798561355,1106454799331512,1106454806483595,1106454808321876,367000,989000,
0,1106454808472308,1106454808472308,9223372036854775807,0,1106454809211408,1106454809258439,1106454811526095,1106454811689064,1106454811738647,1106454812604428,1106454813169533,1106454816826668,1106454820641616,267000,3001000,
0,1106454825149915,1106454825149915,9223372036854775807,0,1106454825927345,1106454825963439,1106454827630053,1106454827736251,1106454827777449,1106454828408647,1106454828953230,1106454833032866,1106454834244272,353000,447000,
0,1106454841827623,1106454841827623,9223372036854775807,0,1106454842767501,1106454842811199,1106454844602345,1106454844723908,1106454844769689,1106454845828647,1106454846366720,1106454853736720,1106454855519897,441000,530000,
0,1106454858505503,1106454858505503,9223372036854775807,0,1106454859508283,1106454859551460,1106454861826980,1106454861958960,1106454862004376,1106454862930001,1106454863467814,1106454868809428,1106454870487710,325000,738000,
0,1106454884851712,1106454884851712,9223372036854775807,0,1106454886444272,1106454886595626,1106454888517866,1106454888665678,1106454888715678,1106454889441980,1106454890058491,1106454895689480,1106454897231147,672000,635000,
0,1106454901502597,1106454901502597,9223372036854775807,0,1106454903124428,1106454903167085,1106454905746251,1106454905890001,1106454905943283,1106454907237814,1106454907881824,1106454913548803,1106454915181251,427000,675000,
0,1106454918216499,1106454918216499,9223372036854775807,0,1106454919090053,1106454919135158,1106454921092918,1106454921229897,1106454921492085,1106454922366824,1106454923043751,1106454928649376,1106454930365887,368000,752000,
0,1106454934879366,1106454934879366,9223372036854775807,0,1106454936387658,1106454936438803,1106454938797866,1106454938938908,1106454938990626,1106454940358803,1106454940983908,1106454946563439,1106454948917658,388000,1078000,
0,1106454951545668,1106454951545668,9223372036854775807,0,1106454953014064,1106454953114272,1106454955638491,1106454955816460,1106454955897137,1106454956710522,1106454958741720,1106454969018855,1106454971154741,368000,750000,
0,1106454968215212,1106454968215212,9223372036854775807,0,1106454970037658,1106454970112137,1106454973225105,1106454973397032,1106454973473595,1106454974260939,1106454976000366,1106454984332553,1106454986140470,287000,571000,
0,1106454984889037,1106454984889037,9223372036854775807,0,1106454985830887,1106454985882085,1106455012450157,1106455013737710,1106455014100053,1106455014905053,1106455016818543,1106455023774689,1106455026535314,346000,683000,
---PROFILEDATA---


View hierarchy:

  com.tencent.qqlive/com.tencent.qqlive.ona.activity.SplashHomeActivity/android.view.ViewRootImpl@692c240
  1004 views, 1181.50 kB of display lists


Total ViewRootImpl: 1
Total Views:        1004
Total DisplayList:  1181.50 kB

我们只需要拿到---PROFILEDATA--- 之间的值就可以了
文档参考:
https://wizzie.top/Blog/2020/03/31/2020/200330_android_getFPS/
https://blog.csdn.net/cxq234843654/article/details/79914535

一行数据为一帧,所需要消耗的时间,单位是纳秒
我们知道,一秒是60帧是最佳,一帧不得超过16.67,如果超过记为 janky 计数加1
一帧所消耗的时间 = FrameCompleted - IntendedVsync
刚执行获取到大概是120帧

fps = 总帧数/总帧数+jank数量 * 60 就得出一秒的帧率

在每次获取数据后,最好需要清理下
adb shell dumpsys gfxinfo packageName reset

问题

1、在命令中,可能获取道多个PROFILEDATA ,不知道获取哪个之间的数据
这里就需要获取到当前的activity,来进行判断,获取当前activity的值

def fps_data_list():
    info = adb.call("adb shell dumpsys gfxinfo {} framestats ".format(package))
    start_data = False # 控制获取数据
    activity = False # 控制获取当前activity
    data_list = []
    activit = adb.get_activity()
    for i in info:
        if str(activit) in str(i).strip():
            activity = True
        if activity:
            if "PROFILEDATA" in i:
                if start_data:
                    start_data = False
                    activity = False
                    break
                else:
                    start_data = True
        if start_data:
            data_list.append(i)
    total = len(data_list)
    logger.info(total)
    if total<5:
        return 0
    data_list = data_list[2:]
    jank = 0
    for j in data_list:
        data_list = j.split(",")
        times = round((int(data_list[13])-int(data_list[1]))/1000000,2)
        if times>16.67:
            jank+=1
    fps = int(total/(total+jank)*60)

    adb.call("adb shell dumpsys gfxinfo {} reset ".format(package))
    return fps

标签:专项,9223372036854775807,com,安卓,Number,percentile,fps,activity,data
来源: https://www.cnblogs.com/TestingShare/p/16518368.html