Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb53933

Browse files
authored
Add more info to malioc_diff.py output (#39625)
1 parent a7ec1e5 commit cb53933

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

impeller/tools/malioc.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

impeller/tools/malioc_diff.py

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ def validate_args(args):
8181
return True
8282

8383

84+
# Reads the 'performance' section of the malioc analysis results.
85+
def read_malioc_file_performance(performance_json):
86+
performance = {}
87+
performance['pipelines'] = performance_json['pipelines']
88+
89+
longest_path_cycles = performance_json['longest_path_cycles']
90+
performance['longest_path_cycles'] = longest_path_cycles['cycle_count']
91+
performance['longest_path_bound_pipelines'] = longest_path_cycles[
92+
'bound_pipelines']
93+
94+
shortest_path_cycles = performance_json['shortest_path_cycles']
95+
performance['shortest_path_cycles'] = shortest_path_cycles['cycle_count']
96+
performance['shortest_path_bound_pipelines'] = shortest_path_cycles[
97+
'bound_pipelines']
98+
99+
total_cycles = performance_json['total_cycles']
100+
performance['total_cycles'] = total_cycles['cycle_count']
101+
performance['total_bound_pipelines'] = total_cycles['bound_pipelines']
102+
return performance
103+
104+
84105
# Parses the json output from malioc, which follows the schema defined in
85106
# `mali_offline_compiler/samples/json_schemas/performance-schema.json`.
86107
def read_malioc_file(malioc_tree, json_file):
@@ -107,14 +128,9 @@ def read_malioc_file(malioc_tree, json_file):
107128
for prop in variant['properties']:
108129
variant_result[prop['name']] = prop['value']
109130

110-
performance = variant['performance']
111-
variant_result['pipelines'] = performance['pipelines']
112-
variant_result['longest_path_cycles'] = performance['longest_path_cycles'
113-
]['cycle_count']
114-
variant_result['shortest_path_cycles'] = performance[
115-
'shortest_path_cycles']['cycle_count']
116-
variant_result['total_cycles'] = performance['total_cycles']['cycle_count'
117-
]
131+
performance_json = variant['performance']
132+
performance = read_malioc_file_performance(performance_json)
133+
variant_result['performance'] = performance
118134
result['variants'][variant['name']] = variant_result
119135
results.append(result)
120136

@@ -141,16 +157,62 @@ def read_malioc_tree(malioc_tree):
141157
return results
142158

143159

160+
# Converts a list to a string in which each list element is left-aligned in
161+
# a space of `width` characters, and separated by `sep`. The separator does not
162+
# count against the `width`. If `width` is 0, then the width is unconstrained.
163+
def pretty_list(lst, fmt='s', sep='', width=12):
164+
return (sep.join(['{:<{width}{fmt}}'] * len(lst))).format(
165+
width='' if width == 0 else width, fmt=fmt, *lst
166+
)
167+
168+
169+
def compare_performance(variant, before, after):
170+
cycles = [['longest_path_cycles', 'longest_path_bound_pipelines'],
171+
['shortest_path_cycles', 'shortest_path_bound_pipelines'],
172+
['total_cycles', 'total_bound_pipelines']]
173+
differences = []
174+
for cycle in cycles:
175+
if before[cycle[0]] == after[cycle[0]]:
176+
continue
177+
before_cycles = before[cycle[0]]
178+
before_bounds = before[cycle[1]]
179+
after_cycles = after[cycle[0]]
180+
after_bounds = after[cycle[1]]
181+
differences += [
182+
'{} in variant {}\n{}{}\n{:<8}{}{}\n{:<8}{}{}\n'.format(
183+
cycle[0],
184+
variant,
185+
' ' * 8,
186+
pretty_list(before['pipelines'] + ['bound']), # Column labels.
187+
'before',
188+
pretty_list(before_cycles, fmt='f'),
189+
pretty_list(before_bounds, sep=',', width=0),
190+
'after',
191+
pretty_list(after_cycles, fmt='f'),
192+
pretty_list(after_bounds, sep=',', width=0),
193+
)
194+
]
195+
return differences
196+
197+
144198
def compare_variants(befores, afters):
145199
differences = []
146200
for variant_name, before_variant in befores.items():
147201
after_variant = afters[variant_name]
148202
for variant_key, before_variant_val in before_variant.items():
149203
after_variant_val = after_variant[variant_key]
150-
if before_variant_val != after_variant_val:
204+
if variant_key == 'performance':
205+
differences += compare_performance(
206+
variant_name, before_variant_val, after_variant_val
207+
)
208+
elif before_variant_val != after_variant_val:
151209
differences += [
152-
'{} in variant {}:\n {} <- before\n {} <- after'.format(
153-
variant_key, variant_name, before_variant_val, after_variant_val
210+
'In variant {}:\n {vkey}: {} <- before\n {vkey}: {} <- after'
211+
.format(
212+
variant_name,
213+
before_variant_val,
214+
after_variant_val,
215+
vkey=variant_key,
154216
)
155217
]
156218
return differences
@@ -162,6 +224,8 @@ def compare_shaders(malioc_tree, before_shader, after_shader):
162224
after_val = after_shader[key]
163225
if key == 'variants':
164226
differences += compare_variants(before_val, after_val)
227+
elif key == 'performance':
228+
differences += compare_performance('Default', before_val, after_val)
165229
elif before_val != after_val:
166230
differences += [
167231
'{}:\n {} <- before\n {} <- after'.format(
@@ -178,7 +242,7 @@ def compare_shaders(malioc_tree, before_shader, after_shader):
178242
for diff in differences:
179243
print(diff)
180244
print(
181-
'\nFor a full report, run:\n $ malioc --{} --core {} {}/{}'.format(
245+
'\nFor a full report, run:\n $ malioc --{} --core {} {}/{}\n'.format(
182246
typ.lower(), core, build_gen_dir, filename
183247
)
184248
)

0 commit comments

Comments
 (0)