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 handling of the mm_id field in the rss_stat 17# event. 18 19from os import sys, path 20 21import synth_common 22 23trace = synth_common.create_trace() 24 25trace.add_packet(ts=1) 26trace.add_process(10, 0, "process") 27 28trace.add_ftrace_packet(0) 29 30# Create a kernel "thread", which is a single-thread process child of kthreadd. 31trace.add_newtask(ts=50, tid=2, new_tid=3, new_comm="kthreadd_child", flags=0) 32 33# Add an event on tid 3 which affects its own rss. 34trace.add_rss_stat(ts=90, tid=3, member=0, size=9, mm_id=4321, curr=True) 35 36# Try to add an event for tid 10. However, as we've not seen an event 37# with curr == True for tid == 10, this event will be dropped. 38trace.add_rss_stat(ts=91, tid=3, member=0, size=900, mm_id=1234, curr=False) 39 40# Add an event for tid 3 from tid 10. This emulates e.g. direct reclaim 41# where a process reaches into another process' mm struct. 42trace.add_rss_stat(ts=99, tid=10, member=0, size=10, mm_id=4321, curr=False) 43 44# Add an event on tid 10 which affects its own rss. 45trace.add_rss_stat(ts=100, tid=10, member=0, size=1000, mm_id=1234, curr=True) 46 47# Add an event on tid 10 from tid 3. This emulates e.g. background reclaim 48# where kthreadd is cleaning up the mm struct of another process. 49trace.add_rss_stat(ts=101, tid=3, member=0, size=900, mm_id=1234, curr=False) 50 51sys.stdout.buffer.write(trace.trace.SerializeToString()) 52