diff options
author | Anna Mayzner <mayzner@google.com> | 2024-04-04 21:23:17 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-04 21:23:17 +0000 |
commit | 06e06f27960359725c994daba1229401a3cb6d23 (patch) | |
tree | aa06ea0d60993813caf3891ad2160d0c757f0871 | |
parent | 29c68a3312c2d07d7a57e4f40348cfff364bdf34 (diff) | |
parent | 6e71d94abab709cb5e5659875eae8a2788169b60 (diff) | |
download | perfetto-06e06f27960359725c994daba1229401a3cb6d23.tar.gz |
Merge "tp: Add intervals_overlap_in_table macro" into main
3 files changed, 57 insertions, 2 deletions
diff --git a/src/trace_processor/perfetto_sql/stdlib/intervals/overlap.sql b/src/trace_processor/perfetto_sql/stdlib/intervals/overlap.sql index 151d43813..3db21d427 100644 --- a/src/trace_processor/perfetto_sql/stdlib/intervals/overlap.sql +++ b/src/trace_processor/perfetto_sql/stdlib/intervals/overlap.sql @@ -65,4 +65,29 @@ SELECT ) as value FROM _merged_events ORDER BY ts +); + +-- Returns whether |intervals| contains any overlapping intervals. Useful for +-- checking if provided table/subquery can be used for intervals_intersect +-- macro. +CREATE PERFETTO MACRO _intervals_overlap_in_table( + -- Table/subquery of intervals with |ts| and |dur| columns. + intervals TableOrSubquery) +-- Returns 1 if table contains overlapping intervals. Otherwise returns 0. +RETURNS Expr AS ( +WITH ts_with_next AS ( + SELECT + ts + dur AS ts_end, + -- The last slice will have |next_ts == NULL|, but it's not an issue as if + -- it's the last slice we know that it will not overlap with the next one. + LEAD(ts) OVER (ORDER BY ts) AS next_ts + FROM $intervals + WHERE dur != -1 +), filtered AS ( + SELECT * FROM ts_with_next + WHERE ts_end > next_ts + LIMIT 1 +) +SELECT count() AS has_overlaps +FROM filtered );
\ No newline at end of file diff --git a/test/trace_processor/diff_tests/include_index.py b/test/trace_processor/diff_tests/include_index.py index 36872ed6f..b65f15848 100644 --- a/test/trace_processor/diff_tests/include_index.py +++ b/test/trace_processor/diff_tests/include_index.py @@ -273,9 +273,9 @@ def fetch_all_diff_tests(index_path: str) -> List['testing.TestCase']: *SpanJoinSmoke(index_path, 'stdlib/span_join', 'SpanJoinSmoke').fetch(), *StdlibCommon(index_path, 'stdlib/common', 'StdlibCommon').fetch(), *StdlibIntervals(index_path, 'stdlib/intervals', - 'StdlibIntervalsIntersect').fetch(), + 'StdlibIntervals').fetch(), *IntervalsIntersect(index_path, 'stdlib/intervals', - 'StdlibIntervals').fetch(), + 'StdlibIntervalsIntersect').fetch(), *Timestamps(index_path, 'stdlib/timestamps', 'Timestamps').fetch(), ] + chrome_stdlib_tests diff --git a/test/trace_processor/diff_tests/stdlib/intervals/tests.py b/test/trace_processor/diff_tests/stdlib/intervals/tests.py index cbc34cc82..c00eca8f8 100644 --- a/test/trace_processor/diff_tests/stdlib/intervals/tests.py +++ b/test/trace_processor/diff_tests/stdlib/intervals/tests.py @@ -51,4 +51,34 @@ class StdlibIntervals(TestSuite): 70,1 80,2 90,1 + """)) + + def test_intervals_overlap_in_table(self): + return DiffTestBlueprint( + trace=TextProto(""), + query=""" + INCLUDE PERFETTO MODULE intervals.overlap; + + WITH data_no_overlaps(ts, dur) AS ( + VALUES + (10, 10), + (30, 10) + ), + data_with_overlaps(ts, dur) AS ( + VALUES + (10, 10), + (15, 10) + ) + SELECT * FROM ( + SELECT * + FROM _intervals_overlap_in_table!(data_no_overlaps) + UNION + SELECT * + FROM _intervals_overlap_in_table!(data_with_overlaps) + ) + """, + out=Csv(""" + "has_overlaps" + 0 + 1 """))
\ No newline at end of file |