Flutter Engine
The Flutter Engine
parse_skottie_trace.py
Go to the documentation of this file.
1# Copyright 2024 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import json
7import sys
8
9trace_output = sys.argv[1]
10trace_json = json.loads(trace_output)
11lottie_filename = sys.argv[2]
12output_json_file = sys.argv[3]
13seek_trace_name = sys.argv[4]
14render_trace_name = sys.argv[5]
15expected_dm_frames = int(sys.argv[6])
16
17perf_results = {}
18frame_max = 0
19frame_min = 0
20frame_cumulative = 0
21current_frame_duration = 0
22total_frames = 0
23frame_start = False
24for trace in trace_json:
25 if seek_trace_name in trace['name']:
26 if frame_start:
27 raise Exception('We got consecutive Animation::seek without a ' +
28 'render. Something is wrong.')
29 frame_start = True
30 current_frame_duration = trace['dur']
31 elif render_trace_name in trace['name']:
32 if not frame_start:
33 raise Exception('We got an Animation::render without a seek first. ' +
34 'Something is wrong.')
35
36 current_frame_duration += trace['dur']
37 frame_start = False
38 total_frames += 1
39 frame_max = max(frame_max, current_frame_duration)
40 frame_min = (min(frame_min, current_frame_duration)
41 if frame_min else current_frame_duration)
42 frame_cumulative += current_frame_duration
43
44expected_dm_frames = expected_dm_frames
45if total_frames != expected_dm_frames:
46 raise Exception(
47 'Got ' + str(total_frames) + ' frames instead of ' +
48 str(expected_dm_frames))
49perf_results['frame_max_us'] = frame_max
50perf_results['frame_min_us'] = frame_min
51perf_results['frame_avg_us'] = frame_cumulative/total_frames
52
53# Write perf_results to the output json.
54with open(output_json_file, 'w') as f:
55 f.write(json.dumps(perf_results))
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48