1#!/usr/bin/env python3 2# Copyright (C) 2024 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 DataPath 17from python.generators.diff_tests.testing import Csv 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21class CriticalPathTests(TestSuite): 22 23 def test_critical_path_empty(self): 24 return DiffTestBlueprint( 25 trace=DataPath('counters.json'), 26 query=""" 27 INCLUDE PERFETTO MODULE graphs.critical_path; 28 29 WITH edge AS ( 30 SELECT 0 as source_node_id, 0 AS dest_node_id 31 WHERE FALSE 32 ), root AS ( 33 SELECT 0 as root_node_id, 0 AS capacity 34 WHERE FALSE 35 ) 36 SELECT * FROM _critical_path!( 37 (SELECT *, source_node_id - dest_node_id AS edge_weight FROM edge), 38 root 39 ); 40 """, 41 out=Csv(""" 42 "root_id","parent_id","id" 43 """)) 44 45 def test_critical_path(self): 46 return DiffTestBlueprint( 47 trace=DataPath('counters.json'), 48 query=""" 49 INCLUDE PERFETTO MODULE graphs.critical_path; 50 51 WITH edge(source_node_id, dest_node_id) AS ( 52 values(8, 7), (7, 6), (6, 5), (6, 4), (4, 1), (5, 3), (3, 0) 53 ), root(root_node_id, capacity) AS ( 54 values(8, 6) 55 ) 56 SELECT * FROM _critical_path!( 57 (SELECT *, source_node_id - dest_node_id AS edge_weight FROM edge), 58 root 59 ); 60 """, 61 out=Csv(""" 62 "root_id","parent_id","id" 63 8,"[NULL]",8 64 8,3,0 65 8,5,3 66 8,6,5 67 8,7,6 68 8,8,7 69 """)) 70 71 def test_critical_path_intervals(self): 72 return DiffTestBlueprint( 73 trace=DataPath('counters.json'), 74 query=""" 75 INCLUDE PERFETTO MODULE graphs.critical_path; 76 77 WITH edge(source_node_id, dest_node_id) AS ( 78 values(8, 7), (7, 6), (6, 5), (6, 4), (4, 1), (5, 3), (3, 0) 79 ), root(root_node_id, capacity) AS ( 80 values(8, 6) 81 ), interval(id, ts, dur, idle_dur) AS ( 82 values(8, 8, 1, 6), 83 (7, 7, 1, 1), 84 (6, 6, 1, 1), 85 (5, 5, 1, 1), 86 (4, 4, 1, 1), 87 (3, 3, 1, 1), 88 (2, 2, 1, 1), 89 (1, 1, 1, 1) 90 ) 91 SELECT * FROM _critical_path_intervals!( 92 (SELECT *, source_node_id - dest_node_id AS edge_weight FROM edge), 93 root, 94 interval 95 ); 96 """, 97 out=Csv(""" 98 "root_id","id","ts","dur" 99 8,3,3,2 100 8,5,5,1 101 8,6,6,1 102 8,7,7,1 103 8,8,8,1 104 """)) 105