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 16# This synthetic trace tests legacy rss_stat events on old kernels which 17# do not have the mm_id change and thus we cannot accurately track 18# rss changes when one process changes another's mm struct. 19 20from os import sys, path 21 22 23import synth_common 24 25trace = synth_common.create_trace() 26 27trace.add_packet(ts=1) 28trace.add_process(10, 0, "process") 29 30trace.add_ftrace_packet(0) 31 32# Create a new child process (treated internally as a thread) of kthreadd. 33trace.add_newtask(ts=50, tid=2, new_tid=3, new_comm="kthread_child", flags=0) 34 35# Add an event on tid 3 which affects its own rss. 36trace.add_rss_stat(ts=90, tid=3, member=0, size=9) 37 38# Add an event on tid 10 from tid 3. This emlates e.g. background reclaim 39# where kthreadd is cleaning up the mm struct of another process. 40trace.add_rss_stat(ts=91, tid=3, member=0, size=900) 41 42# Add an event for tid 3 from tid 10. This emulates e.g. direct reclaim 43# where a process reaches into another process' mm struct. 44trace.add_rss_stat(ts=99, tid=10, member=0, size=10) 45 46# Add an event on tid 10 which affects its own rss. 47trace.add_rss_stat(ts=100, tid=10, member=0, size=1000) 48 49# Add an event on tid 10 from tid 3. 50trace.add_rss_stat(ts=101, tid=3, member=0, size=900) 51 52sys.stdout.buffer.write(trace.trace.SerializeToString()) 53