1#!/usr/bin/env python3
2# Copyright (C) 2019 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()
21
22# kfree:
23# field:unsigned long call_site;        offset:8;       size:8; signed:0;
24# field:const void * ptr;               offset:16;      size:8; signed:0;
25
26# kmalloc:
27# field:unsigned long call_site;        offset:8;       size:8; signed:0;
28# field:const void * ptr;               offset:16;      size:8; signed:0;
29# field:size_t bytes_req;               offset:24;      size:8; signed:0;
30# field:size_t bytes_alloc;             offset:32;      size:8; signed:0;
31# field:gfp_t gfp_flags;                offset:40;      size:4; signed:0;
32
33# Without special-casing, we print everything as unsigned decimal.
34
35trace.add_packet()
36trace.add_process(pid=10, ppid=1, cmdline="perfetto")
37
38trace.add_ftrace_packet(cpu=0)
39trace.add_kfree(ts=100, tid=10, call_site=16, ptr=32)
40trace.add_kfree(ts=101, tid=10, call_site=(1 << 64) - 16, ptr=(1 << 64) - 32)
41trace.add_kmalloc(
42    ts=102,
43    tid=10,
44    bytes_alloc=32,
45    bytes_req=16,
46    call_site=(1 << 64) - 16,
47    gfp_flags=0,
48    ptr=(1 << 64) - 32)
49
50sys.stdout.buffer.write(trace.trace.SerializeToString())
51