1#!/usr/bin/env python3
2# Copyright (C) 2020 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from os import sys, path
17
18import synth_common
19
20trace = synth_common.create_trace()
21trace.add_packet()
22trace.add_process(1, 0, "app_1")
23trace.add_process(2, 0, "app_2")
24trace.add_process(3, 0, "app_2")
25
26trace.add_ftrace_packet(cpu=0)
27
28# max=4, min=1, avg=(2*1+5*2+(10-9)*4)/(10-2)=2
29trace.add_gpu_mem_total_ftrace_event(pid=0, ts=2, size=1)
30trace.add_gpu_mem_total_ftrace_event(pid=0, ts=4, size=2)
31trace.add_gpu_mem_total_ftrace_event(pid=0, ts=9, size=4)
32
33# max=8, min=2, avg=(5*2+(10-9)*8)/(10-4)=3
34trace.add_gpu_mem_total_ftrace_event(pid=1, ts=4, size=2)
35trace.add_gpu_mem_total_ftrace_event(pid=1, ts=9, size=8)
36
37# max=8, min=6, avgxdur=2*6+(10-4)*8=60, dur=2+(10-4)=8
38trace.add_gpu_mem_total_ftrace_event(pid=2, ts=2, size=6)
39trace.add_gpu_mem_total_ftrace_event(pid=2, ts=4, size=8)
40
41# max=10, min=7, avgxdur=1*7+(10-7)*10=37, dur=1+(10-7)=4
42trace.add_gpu_mem_total_ftrace_event(pid=3, ts=6, size=7)
43trace.add_gpu_mem_total_ftrace_event(pid=3, ts=7, size=10)
44
45# app_2 will be aggregated
46# max=10, min=6, avg=(60+37)/(8+4)=8
47
48sys.stdout.buffer.write(trace.trace.SerializeToString())
49