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 ParsingMemoryCounters(TestSuite): 23 24 def test_memory_counters_args_string_filter_null(self): 25 return DiffTestBlueprint( 26 trace=DataPath('memory_counters.pb'), 27 query=Path('args_string_filter_null_test.sql'), 28 out=Csv(""" 29 "string_value" 30 """)) 31 32 def test_memory_counters_args_string_is_null(self): 33 return DiffTestBlueprint( 34 trace=DataPath('memory_counters.pb'), 35 query=""" 36 SELECT string_value 37 FROM args 38 WHERE string_value IS NULL 39 LIMIT 10; 40 """, 41 out=Csv(""" 42 "string_value" 43 "[NULL]" 44 "[NULL]" 45 "[NULL]" 46 "[NULL]" 47 "[NULL]" 48 "[NULL]" 49 "[NULL]" 50 "[NULL]" 51 "[NULL]" 52 "[NULL]" 53 """)) 54 55 def test_memory_counters_args_string_is_not_null(self): 56 return DiffTestBlueprint( 57 trace=DataPath('memory_counters.pb'), 58 query=""" 59 SELECT string_value 60 FROM args 61 WHERE string_value IS NOT NULL 62 LIMIT 10; 63 """, 64 out=Csv(""" 65 "string_value" 66 "traced_probes" 67 "rcuos/0" 68 "rcuos/0" 69 "rcu_sched" 70 "rcu_sched" 71 "atrace" 72 "atrace" 73 "traced_probes" 74 "swapper/1" 75 "rcu_preempt" 76 """)) 77 78 def test_memory_counters_b120605557(self): 79 return DiffTestBlueprint( 80 trace=DataPath('memory_counters.pb'), 81 query=""" 82 SELECT count(*) 83 FROM counter 84 JOIN counter_track ON counter_track.id = counter.track_id; 85 """, 86 out=Csv(""" 87 "count(*)" 88 98688 89 """)) 90 91 def test_global_memory_counter_memory_counters(self): 92 return DiffTestBlueprint( 93 trace=DataPath('memory_counters.pb'), 94 query=""" 95 SELECT ts, value, name 96 FROM counter 97 JOIN counter_track ON counter.track_id = counter_track.id 98 WHERE name = 'MemAvailable' 99 LIMIT 10; 100 """, 101 out=Csv(""" 102 "ts","value","name" 103 22240334823167,2696392704.000000,"MemAvailable" 104 22240356169836,2696392704.000000,"MemAvailable" 105 22240468594483,2696392704.000000,"MemAvailable" 106 22240566948190,2696392704.000000,"MemAvailable" 107 22240667383304,2696392704.000000,"MemAvailable" 108 22240766505085,2696392704.000000,"MemAvailable" 109 22240866794106,2696392704.000000,"MemAvailable" 110 22240968271928,2696392704.000000,"MemAvailable" 111 22241065777407,2696392704.000000,"MemAvailable" 112 22241165839708,2696392704.000000,"MemAvailable" 113 """)) 114 115 def test_ion_stat(self): 116 return DiffTestBlueprint( 117 trace=TextProto(r""" 118 packet { 119 ftrace_events { 120 cpu: 4 121 event { 122 timestamp: 1234 123 pid: 4321 124 ion_stat { 125 buffer_id: 101010 126 len: 100 127 total_allocated: 200 128 } 129 } 130 } 131 } 132 """), 133 query=""" 134 SELECT t.name, c.ts, c.value 135 FROM counter c 136 JOIN track t ON c.track_id = t.id 137 WHERE t.name GLOB 'mem.ion*'; 138 """, 139 out=Csv(""" 140 "name","ts","value" 141 "mem.ion",1234,200.000000 142 "mem.ion_change",1234,100.000000 143 """)) 144