107 if not args.after
and not args.after_relative_to_src:
108 print(
'--after argument or --after-relative-to-src must be specified.')
111 if not args.before
and not args.before_relative_to_src:
112 print(
'--before argument or --before-relative-to-src must be specified.')
117 args.before = (args.before
or os.path.join(BUILD_ROOT_DIR, args.before_relative_to_src))
118 args.after = (args.after
or os.path.join(BUILD_ROOT_DIR, args.after_relative_to_src))
120 if not args.after
or not os.path.isdir(args.after):
121 print(
'The --after argument must refer to a directory.')
123 if not args.before
or (
not args.update
and not os.path.isfile(args.before)):
124 print(
'The --before argument must refer to an existing file.')
132 performance[
'pipelines'] = performance_json[
'pipelines']
134 longest_path_cycles = performance_json[
'longest_path_cycles']
135 performance[
'longest_path_cycles'] = longest_path_cycles[
'cycle_count']
136 performance[
'longest_path_bound_pipelines'] = longest_path_cycles[
'bound_pipelines']
138 shortest_path_cycles = performance_json[
'shortest_path_cycles']
139 performance[
'shortest_path_cycles'] = shortest_path_cycles[
'cycle_count']
140 performance[
'shortest_path_bound_pipelines'] = shortest_path_cycles[
'bound_pipelines']
142 total_cycles = performance_json[
'total_cycles']
143 performance[
'total_cycles'] = total_cycles[
'cycle_count']
144 performance[
'total_bound_pipelines'] = total_cycles[
'bound_pipelines']
151 with open(json_file,
'r')
as file:
152 json_obj = json.load(file)
154 build_gen_dir = os.path.dirname(malioc_tree)
157 for shader
in json_obj[
'shaders']:
159 if shader[
'hardware'][
'core']
not in CORES:
162 filename = os.path.relpath(shader[
'filename'], build_gen_dir)
163 if filename.startswith(
'../..'):
164 filename = filename[6:]
165 if filename.startswith(
'../'):
166 filename = filename[3:]
167 result[
'filename'] = filename
168 result[
'core'] = shader[
'hardware'][
'core']
169 result[
'type'] = shader[
'shader'][
'type']
170 for prop
in shader[
'properties']:
171 result[prop[
'name']] = prop[
'value']
173 result[
'variants'] = {}
174 for variant
in shader[
'variants']:
176 for prop
in variant[
'properties']:
177 variant_result[prop[
'name']] = prop[
'value']
179 performance_json = variant[
'performance']
181 variant_result[
'performance'] = performance
182 result[
'variants'][variant[
'name']] = variant_result
183 results.append(result)
218 cycles = [[
'longest_path_cycles',
'longest_path_bound_pipelines'],
219 [
'shortest_path_cycles',
'shortest_path_bound_pipelines'],
220 [
'total_cycles',
'total_bound_pipelines']]
223 if before[cycle[0]] == after[cycle[0]]:
225 before_cycles = before[cycle[0]]
226 before_bounds = before[cycle[1]]
227 after_cycles = after[cycle[0]]
228 after_bounds = after[cycle[1]]
230 '{} in variant {}\n{}{}\n{:<8}{}{}\n{:<8}{}{}\n'.
format(
248 for variant_name, before_variant
in befores.items():
249 after_variant = afters[variant_name]
250 for variant_key, before_variant_val
in before_variant.items():
251 after_variant_val = after_variant[variant_key]
252 if variant_key ==
'performance':
254 elif before_variant_val != after_variant_val:
256 'In variant {}:\n {vkey}: {} <- before\n {vkey}: {} <- after'.
format(
270 for key, before_val
in before_shader.items():
271 after_val = after_shader[key]
272 if key ==
'variants':
274 elif key ==
'performance':
276 elif before_val != after_val:
277 differences += [
'{}:\n {} <- before\n {} <- after'.
format(key, before_val, after_val)]
279 if bool(differences):
280 build_gen_dir = os.path.dirname(malioc_tree)
281 filename = before_shader[
'filename']
282 core = before_shader[
'core']
283 typ = before_shader[
'type']
284 print(
'Changes found in shader {} on core {}:'.
format(filename, core))
285 for diff
in differences:
288 '\nFor a full report, run:\n $ malioc --{} --core {} {}/{}\n'.
format(
289 typ.lower(), core, build_gen_dir, filename
293 return bool(differences)
302 if not bool(after_json):
303 print(
'Did not find any malioc results under {}.'.
format(args.after))
308 with open(args.before,
'w')
as file:
309 json.dump(after_json, file, sort_keys=
True, indent=2)
312 with open(args.before,
'r')
as file:
313 before_json = json.load(file)
316 for filename, shaders
in before_json.items():
317 if filename
not in after_json.keys():
318 print(
'Shader "{}" has been removed.'.
format(filename))
321 for core, before_shader
in shaders.items():
322 if core
not in after_json[filename].keys():
324 after_shader = after_json[filename][core]
328 for filename, shaders
in after_json.items():
329 if filename
not in before_json:
335 'There are new shaders, shaders have been removed, or performance '
336 'changes to existing shaders. The golden file must be updated after a '
337 'build of android_debug_unopt using the --malioc-path flag to the '
338 'flutter/tools/gn script.\n\n'
339 '$ ./flutter/impeller/tools/malioc_diff.py --before {} --after {} --update'.
format(
340 args.before, args.after
344 before_lines = json.dumps(before_json, sort_keys=
True, indent=2).splitlines(keepends=
True)
345 after_lines = json.dumps(after_json, sort_keys=
True, indent=2).splitlines(keepends=
True)
346 before_path = os.path.relpath(os.path.abspath(args.before), start=SRC_ROOT)
347 diff = difflib.unified_diff(before_lines, after_lines, fromfile=before_path)
348 print(
'\nYou can alternately apply the diff below:')
349 print(
'patch -p0 <<DONE')
353 return 1
if changed
else 0
uint32_t uint32_t * format