1#!/usr/bin/env python3 2# Copyright (C) 2023 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 a 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 python.generators.diff_tests.testing import Path, DataPath, Metric 17from python.generators.diff_tests.testing import Csv, Json, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class ParsingRssStats(TestSuite): 23 24 def test_rss_stat_mm_id(self): 25 return DiffTestBlueprint( 26 trace=Path('rss_stat_mm_id.py'), 27 query=""" 28 SELECT c.ts, t.name, p.pid, p.name, c.value 29 FROM counter c 30 JOIN process_counter_track t ON c.track_id = t.id 31 JOIN process p USING (upid) 32 ORDER BY ts, pid; 33 """, 34 out=Csv(""" 35 "ts","name","pid","name","value" 36 90,"mem.rss.file",3,"kthreadd_child",9.000000 37 99,"mem.rss.file",3,"kthreadd_child",10.000000 38 100,"mem.rss.file",10,"process",1000.000000 39 101,"mem.rss.file",10,"process",900.000000 40 """)) 41 42 def test_rss_stat_mm_id_clone(self): 43 return DiffTestBlueprint( 44 trace=Path('rss_stat_mm_id_clone.py'), 45 query=""" 46 SELECT c.ts, t.name, p.pid, p.name, c.value 47 FROM counter c 48 JOIN process_counter_track t ON c.track_id = t.id 49 JOIN process p USING (upid) 50 ORDER BY ts, pid; 51 """, 52 out=Csv(""" 53 "ts","name","pid","name","value" 54 100,"mem.rss.file",3,"kernel_thread",10.000000 55 100,"mem.rss.file",10,"parent_process",100.000000 56 102,"mem.rss.file",4,"kernel_thread2",20.000000 57 102,"mem.rss.file",11,"child_process",90.000000 58 104,"mem.rss.file",11,"child_process",10.000000 59 105,"mem.rss.file",10,"parent_process",95.000000 60 107,"mem.rss.file",10,"parent_process",105.000000 61 108,"mem.rss.file",10,"parent_process",110.000000 62 """)) 63 64 def test_rss_stat_mm_id_reuse(self): 65 return DiffTestBlueprint( 66 trace=Path('rss_stat_mm_id_reuse.py'), 67 query=""" 68 SELECT c.ts, t.name, p.pid, p.name, c.value 69 FROM counter c 70 JOIN process_counter_track t ON c.track_id = t.id 71 JOIN process p USING (upid) 72 ORDER BY ts, pid; 73 """, 74 out=Csv(""" 75 "ts","name","pid","name","value" 76 100,"mem.rss.file",10,"parent_process",100.000000 77 103,"mem.rss.file",10,"new_process",10.000000 78 """)) 79 80 def test_rss_stat_legacy(self): 81 return DiffTestBlueprint( 82 trace=Path('rss_stat_legacy.py'), 83 query=""" 84 SELECT c.ts, t.name, p.pid, p.name, c.value 85 FROM counter c 86 JOIN process_counter_track t ON c.track_id = t.id 87 JOIN process p USING (upid) 88 ORDER BY ts, pid; 89 """, 90 out=Csv(""" 91 "ts","name","pid","name","value" 92 90,"mem.rss.file",3,"kthreadd_child",9.000000 93 91,"mem.rss.file",3,"kthreadd_child",900.000000 94 99,"mem.rss.file",10,"process",10.000000 95 100,"mem.rss.file",10,"process",1000.000000 96 101,"mem.rss.file",3,"kthreadd_child",900.000000 97 """)) 98 99 def test_rss_stat_after_free(self): 100 return DiffTestBlueprint( 101 trace=Path('rss_stat_after_free.py'), 102 query=""" 103 SELECT 104 pid, 105 max(c.ts) AS last_rss, 106 p.end_ts AS process_end 107 FROM counter c 108 JOIN process_counter_track t ON c.track_id = t.id 109 JOIN process p USING(upid) 110 GROUP BY upid; 111 """, 112 out=Csv(""" 113 "pid","last_rss","process_end" 114 10,100,101 115 11,90,"[NULL]" 116 """)) 117