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 SmokeComputeMetrics(TestSuite): 23 # Contains smoke tests which test the most fundamentally important features 24 # trace processor Note: new tests here should only be added by the Perfetto 25 # Compute CPU time metric testing several core tables. 26 def test_thread_cpu_time_example_android_trace_30s(self): 27 return DiffTestBlueprint( 28 trace=DataPath('example_android_trace_30s.pb'), 29 query=""" 30 SELECT 31 tid, 32 pid, 33 thread.name AS threadName, 34 process.name AS processName, 35 total_dur AS totalDur 36 FROM 37 thread 38 LEFT JOIN process USING(upid) 39 LEFT JOIN 40 (SELECT upid, sum(dur) AS total_dur 41 FROM sched JOIN thread USING(utid) 42 WHERE dur != -1 43 GROUP BY upid 44 ) USING(upid) 45 WHERE utid != 0 46 ORDER BY total_dur DESC, pid, tid; 47 """, 48 out=Path('thread_cpu_time_example_android_trace_30s.out')) 49 50 # Compute power proxy metric 51 def test_proxy_power(self): 52 return DiffTestBlueprint( 53 trace=DataPath('cpu_counters.pb'), 54 query=""" 55 SELECT RUN_METRIC('android/android_proxy_power.sql'); 56 57 DROP VIEW device; 58 59 CREATE TABLE device (name STRING); 60 61 INSERT INTO device VALUES ('walleye'); 62 63 SELECT 64 tid, 65 SUM(dur * COALESCE(power_ma, 0) / 1e9) AS power_mas 66 FROM power_per_thread 67 JOIN thread USING (utid) 68 GROUP BY utid 69 ORDER BY power_mas DESC 70 LIMIT 10; 71 """, 72 out=Path('proxy_power.out')) 73