1-- 2-- Copyright 2022 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 at 7-- 8-- https://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 16INCLUDE PERFETTO MODULE time.conversion; 17 18CREATE PERFETTO FUNCTION is_spans_overlapping( 19 ts1 LONG, 20 ts_end1 LONG, 21 ts2 LONG, 22 ts_end2 LONG) 23RETURNS BOOL AS 24SELECT (IIF($ts1 < $ts2, $ts2, $ts1) 25 < IIF($ts_end1 < $ts_end2, $ts_end1, $ts_end2)); 26 27CREATE PERFETTO FUNCTION spans_overlapping_dur( 28 ts1 LONG, 29 dur1 LONG, 30 ts2 LONG, 31 dur2 LONG 32) 33RETURNS INT AS 34SELECT 35 CASE 36 WHEN $dur1 = -1 OR $dur2 = -1 THEN 0 37 WHEN $ts1 + $dur1 < $ts2 OR $ts2 + $dur2 < $ts1 THEN 0 38 WHEN ($ts1 >= $ts2) AND ($ts1 + $dur1 <= $ts2 + $dur2) THEN $dur1 39 WHEN ($ts1 < $ts2) AND ($ts1 + $dur1 < $ts2 + $dur2) THEN $ts1 + $dur1 - $ts2 40 WHEN ($ts1 > $ts2) AND ($ts1 + $dur1 > $ts2 + $dur2) THEN $ts2 + $dur2 - $ts1 41 ELSE $dur2 42 END; 43 44-- Renames 45 46CREATE PERFETTO FUNCTION ns(nanos INT) 47RETURNS INT AS 48SELECT time_from_ns($nanos); 49 50CREATE PERFETTO FUNCTION us(micros INT) 51RETURNS INT AS 52SELECT time_from_us($micros); 53 54CREATE PERFETTO FUNCTION ms(millis INT) 55RETURNS INT AS 56SELECT time_from_ms($millis); 57 58CREATE PERFETTO FUNCTION seconds(seconds INT) 59RETURNS INT AS 60SELECT time_from_s($seconds); 61 62CREATE PERFETTO FUNCTION minutes(minutes INT) 63RETURNS INT AS 64SELECT time_from_min($minutes); 65 66CREATE PERFETTO FUNCTION hours(hours INT) 67RETURNS INT AS 68SELECT time_from_hours($hours); 69 70CREATE PERFETTO FUNCTION days(days INT) 71RETURNS INT AS 72SELECT time_from_days($days); 73