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
20# Since we do various time based conversions to build cycles/sec, ensure that
21# the timestamps look a bit realistic so they don't make those results look
22# weird.
23SEC = 1000000000
24
25trace = synth_common.create_trace()
26
27# Use fake fingerprint to simulate big/little cores.
28trace.add_system_info(arch='aarch64', fingerprint='crosshatch')
29trace.packet.system_info.hz = 1
30
31trace.add_packet(1)
32# little cores: cpu0 - cpu3
33trace.add_cpu([100, 200])
34trace.add_cpu([100, 200])
35trace.add_cpu([100, 200])
36trace.add_cpu([100, 200])
37# big cores: cpu4 - cpu5
38trace.add_cpu([1000, 2000])
39trace.add_cpu([1000, 2000])
40
41trace.add_packet(1 * SEC)
42trace.add_process_stats(pid=1, freqs={1: 1, 2: 1, 9: 1, 10: 1})
43trace.add_process_stats(pid=2, freqs={1: 1, 2: 1, 9: 1, 10: 1})
44trace.add_process_stats(pid=3, freqs={1: 1, 2: 1, 9: 1, 10: 1})
45trace.add_process_stats(pid=4, freqs={1: 1, 2: 1, 9: 1, 10: 1})
46
47trace.add_packet(2 * SEC)
48trace.add_process_stats(pid=1, freqs={1: 2, 9: 2})
49# Don't log anything for pid=2 thread, test that the packet at t=3 is based
50# against t=2 anyway.
51
52trace.add_packet(3 * SEC)
53trace.add_process_stats(pid=1, freqs={2: 11, 10: 11})
54trace.add_process_stats(pid=2, freqs={1: 11, 9: 11})
55# pid=3 did not record any change in time_in_state, test that it does not
56# appear in events.
57trace.add_process_stats(pid=3, freqs={1: 1})
58# pid=4 recorded a change only on the little core, test that it shows track for
59# the little core but not the big one.
60trace.add_process_stats(pid=4, freqs={1: 2, 9: 1})
61
62sys.stdout.buffer.write(trace.trace.SerializeToString())
63