-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfps.py
More file actions
89 lines (76 loc) · 3.11 KB
/
Copy pathfps.py
File metadata and controls
89 lines (76 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
import threading
import time
from utils.pylib.perf import surface_stats_collector
from utils import androiddebug
from utils.pylib import android_commands
class RootFpsData(threading.Thread):
def __init__(self):
super(RootFpsData, self).__init__()
self.time_before = None
self.time_after = None
self.surface_before = None
self.surface_after = None
self.ls = []
def get_frame_data(self):
"""
获取帧数据及时间戳
:return:字典
"""
result = androiddebug.shell("su -c 'service call SurfaceFlinger 1013'").stdout.readline()
cur_surface = int(result.split("(")[1].split()[0], 16)
return {"surface": cur_surface, "timestamp": time.time()}
def run(self):
user = androiddebug.shell("su -c 'ls'").stdout.readline() # 检查手机是否可以ROOT用户执行命令
if "not found" in user: # 非ROOT手机执行该方式
serial_number = androiddebug.get_serialno()
command = android_commands.AndroidCommands(serial_number)
collector = surface_stats_collector.SurfaceStatsCollector(command)
collector.DisableWarningAboutEmptyData()
collector.Start()
while True:
if androiddebug.stop != True:
break
tm = androiddebug.timestamp()
results = collector.SampleResults()
fpsdata = []
if not results:
pass
else:
for i in results:
if i.name == "avg_surface_fps":
if i.value == None:
fpsdata.insert(0, tm)
fpsdata.append(0)
else:
fpsdata.insert(0, tm)
fpsdata.append(i.value)
self.ls.append(fpsdata)
collector.Stop()
else: # ROOT手机执行该方式
value1 = self.get_frame_data()
self.time_before = value1["timestamp"]
self.surface_before = value1["surface"]
while True:
if androiddebug.stop != True:
break
y = []
time.sleep(1)
value2 = self.get_frame_data()
self.time_after = value2["timestamp"]
self.surface_after = value2["surface"]
time_difference = int(round((self.time_after - self.time_before), 2))
frame_count = (self.surface_after - self.surface_before)
tm = androiddebug.timestamp()
fps = int(frame_count / time_difference)
y.append(fps)
self.time_before = self.time_after
self.surface_before = self.surface_after
y.insert(0, tm)
self.ls.append(y)
# print "refresh:%ss " % time_difference, "FPS:%s" % fps
def get_fps(self):
return self.ls
if __name__ == '__main__':
fps = RootFpsData(10)
fps.run()