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, TraceInjector 19from python.generators.diff_tests.testing import TestSuite 20 21 22class SchedParser(TestSuite): 23 # CPU frequency maximum & minimum limits change 24 def test_cpu_frequency_limits(self): 25 return DiffTestBlueprint( 26 trace=Path('cpu_frequency_limits.textproto'), 27 query=""" 28 SELECT 29 ts, 30 value, 31 REPLACE(name, " Freq Limit", "") AS cpu 32 FROM 33 counter AS c 34 LEFT JOIN 35 counter_track AS t 36 ON c.track_id = t.id 37 WHERE 38 name GLOB "* Freq Limit" 39 ORDER BY ts; 40 """, 41 out=Csv(""" 42 "ts","value","cpu" 43 90000000,2800000.000000,"Cpu 6 Max" 44 90000000,500000.000000,"Cpu 6 Min" 45 100000000,1700000.000000,"Cpu 6 Max" 46 100000000,500000.000000,"Cpu 6 Min" 47 110000000,2800000.000000,"Cpu 6 Max" 48 110000000,1400000.000000,"Cpu 6 Min" 49 120000000,1500000.000000,"Cpu 6 Max" 50 120000000,500000.000000,"Cpu 6 Min" 51 120000000,1400000.000000,"Cpu 4 Max" 52 120000000,600000.000000,"Cpu 4 Min" 53 130000000,2200000.000000,"Cpu 4 Max" 54 130000000,800000.000000,"Cpu 4 Min" 55 """)) 56 57 def test_sched_cpu_util_cfs(self): 58 return DiffTestBlueprint( 59 trace=Path('sched_cpu_util_cfs.textproto'), 60 query=Path('sched_cpu_util_cfs_test.sql'), 61 out=Csv(""" 62 "name","ts","value" 63 "Cpu 6 Util",10000,1.000000 64 "Cpu 6 Cap",10000,1004.000000 65 "Cpu 6 Nr Running",10000,0.000000 66 "Cpu 7 Util",11000,1.000000 67 "Cpu 7 Cap",11000,1007.000000 68 "Cpu 7 Nr Running",11000,0.000000 69 "Cpu 4 Util",12000,43.000000 70 "Cpu 4 Cap",12000,760.000000 71 "Cpu 4 Nr Running",12000,0.000000 72 "Cpu 5 Util",13000,125.000000 73 "Cpu 5 Cap",13000,757.000000 74 "Cpu 5 Nr Running",13000,1.000000 75 """)) 76 77 def test_sched_cpu_util_cfs_machine_id(self): 78 return DiffTestBlueprint( 79 trace=Path('sched_cpu_util_cfs.textproto'), 80 trace_modifier=TraceInjector(['ftrace_events'], {'machine_id': 1001}), 81 query=""" 82 SELECT 83 t.name, 84 c.ts, 85 c.value, 86 m.raw_id as raw_machine_id 87 FROM 88 counter AS c 89 JOIN 90 counter_track AS t 91 ON c.track_id = t.id 92 JOIN machine as m on t.machine_id = m.id 93 WHERE 94 name GLOB "Cpu ? Cap" OR name GLOB "Cpu ? Util" OR name GLOB "Cpu ? Nr Running" 95 ORDER BY ts; 96 """, 97 out=Csv(""" 98 "name","ts","value","raw_machine_id" 99 "Cpu 6 Util",10000,1.000000,1001 100 "Cpu 6 Cap",10000,1004.000000,1001 101 "Cpu 6 Nr Running",10000,0.000000,1001 102 "Cpu 7 Util",11000,1.000000,1001 103 "Cpu 7 Cap",11000,1007.000000,1001 104 "Cpu 7 Nr Running",11000,0.000000,1001 105 "Cpu 4 Util",12000,43.000000,1001 106 "Cpu 4 Cap",12000,760.000000,1001 107 "Cpu 4 Nr Running",12000,0.000000,1001 108 "Cpu 5 Util",13000,125.000000,1001 109 "Cpu 5 Cap",13000,757.000000,1001 110 "Cpu 5 Nr Running",13000,1.000000,1001 111 """)) 112