• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
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
21sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
22import synth_common
23
24trace = synth_common.create_trace()
25
26trace.add_packet(ts=1)
27trace.add_process(10, 0, "process")
28
29trace.add_ftrace_packet(0)
30
31# Create a new child process (treated internally as a thread) of kthreadd.
32trace.add_newtask(ts=50, tid=2, new_tid=3, new_comm="kthread_child", flags=0)
33
34# Add an event on tid 3 which affects its own rss.
35trace.add_rss_stat(ts=90, tid=3, member=0, size=9, mm_id=4321, curr=True)
36
37# Try to add an event for tid 10. However, as we've not seen an event
38# with curr == True for tid == 10, this event will be dropped.
39trace.add_rss_stat(ts=91, tid=3, member=0, size=900, mm_id=1234, curr=False)
40
41# Add an event for tid 3 from tid 10. This emulates e.g. direct reclaim
42# where a process reaches into another process' mm struct.
43trace.add_rss_stat(ts=99, tid=10, member=0, size=10, mm_id=4321, curr=False)
44
45# Add an event on tid 10 which affects its own rss.
46trace.add_rss_stat(ts=100, tid=10, member=0, size=1000, mm_id=1234, curr=True)
47
48# Add an event on tid 10 from tid 3. This emlates e.g. background reclaim
49# where kthreadd is cleaning up the mm struct of another process.
50trace.add_rss_stat(ts=101, tid=3, member=0, size=900, mm_id=1234, curr=False)
51
52print(trace.trace.SerializeToString())
53