This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprofile.py
executable file
·140 lines (99 loc) · 4.57 KB
/
profile.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
import sys
import fileinput
def parse_framestats(line, valid_only=False):
# http://developer.android.com/preview/testing/performance.html#fs-data-format
# Strip trailing comma
framestats = list(map(int, line[:len(line) - 1].split(",")))
# Default values. This keeps the data aligned with gfxinfo.
start = 0
handle_input = 0
animations = 0
traversals = 0
draw = 0
sync = 0
gpu = 0
if framestats[0] == 0 and len(framestats) == 14:
# HANDLE_INPUT_START - INTENDED_VSYNC
start = (framestats[5] - framestats[1]) / 1000000
# ANIMATION_START - HANDLE_INPUT_START
handle_input = (framestats[6] - framestats[5]) / 1000000
# PERFORM_TRAVERSALS_START - ANIMATION_START
animations = (framestats[7] - framestats[6]) / 1000000
# DRAW_START - PERFORM_TRAVERSALS_START
traversals = (framestats[8] - framestats[7]) / 1000000
# SYNC_START - DRAW_START
draw = (framestats[10] - framestats[8]) / 1000000
# ISSUE_DRAW_COMMANDS_START - SYNC_START
sync = (framestats[11] - framestats[10]) / 1000000
# FRAME_COMPLETED - ISSUE_DRAW_COMMANDS_START
gpu = (framestats[13] - framestats[11]) / 1000000
elif valid_only:
raise ValueError("Invalid frame.")
return start, handle_input, animations, traversals, draw, sync, gpu
# Globals
has_header = False
in_profile_section = False
in_activity = False
in_table = False
in_framestats = False
gfxinfo = []
framestats = []
num_cols = 0
# Parse input
for line in fileinput.input():
stripped_line = line.strip()
if in_profile_section:
if stripped_line == "View hierarchy:":
in_profile_section = False
in_activity = False
in_table = False
if len(gfxinfo) == 0 and len(framestats) > 0: # only framestats
if not has_header:
print("start", "input", "animations", "traversals", "draw", "sync", "gpu", sep="\t")
has_header = True
list(map(lambda frame: print(*frame, sep="\t"), map(parse_framestats, framestats)))
elif len(gfxinfo) > 0 and len(framestats) == 0: # only gfxinfo
if not has_header:
# https://io2015codelabs.appspot.com/codelabs/android-performance-profile-gpu-rendering#5
if gfxinfo[0].count("\t") == 2:
print("draw", "execute", "process", sep="\t")
elif gfxinfo[0].count("\t") == 3: # Prepare only exists on Lollipop and above
print("draw", "prepare", "execute", "process", sep="\t")
has_header = True
list(map(print, gfxinfo))
elif len(gfxinfo) > 0 and len(gfxinfo) == len(framestats): # both
if not has_header:
print("start", "input", "animations", "traversals", "draw", "sync", "execute", "process", sep="\t")
has_header = True
for gfx, cpu in zip(gfxinfo, framestats):
try:
# ignore "gpu" and append "execute" and "process"
print(*(parse_framestats(cpu, True)[:-2] + tuple(list(map(float, gfx.split("\t")))[-3:])), sep="\t")
except ValueError:
# only use gfx data if framestats is invalid
print(*([0, 0, 0, 0] + map(float, gfx.split("\t"))), sep="\t")
gfxinfo = []
framestats = []
else:
if stripped_line.count("/") == 2:
if in_activity:
in_activity = False
elif "visibility=0" in stripped_line or "visibility" not in stripped_line:
# Choose the activity that is visible or all activities
in_activity = True
elif in_activity:
table_cols = stripped_line.count("\t")
if in_table and table_cols == num_cols and "Execute" not in stripped_line:
gfxinfo.append(stripped_line)
elif "Execute" in stripped_line:
in_table = True
num_cols = table_cols
elif stripped_line == "---PROFILEDATA---":
in_framestats = not in_framestats
elif in_framestats and "Flags" not in stripped_line:
framestats.append(stripped_line)
elif stripped_line == "Profile data in ms:":
in_profile_section = True