stdlib: Add CPU cycles calculation for specified slices

Change-Id: I86d73a2f4024a8fad3aae71aecf4f42d562b1452
diff --git a/Android.bp b/Android.bp
index 187e36c..a2bc070 100644
--- a/Android.bp
+++ b/Android.bp
@@ -13565,6 +13565,7 @@
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle_time_in_state.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/process.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/slice.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/thread.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/memory/general.sql",
diff --git a/BUILD b/BUILD
index d3b61e7..918da3d 100644
--- a/BUILD
+++ b/BUILD
@@ -2836,6 +2836,7 @@
     srcs = [
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/process.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/slice.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/thread.sql",
     ],
diff --git a/python/generators/sql_processing/utils.py b/python/generators/sql_processing/utils.py
index 092ec6a..1163897 100644
--- a/python/generators/sql_processing/utils.py
+++ b/python/generators/sql_processing/utils.py
@@ -125,7 +125,7 @@
 OBJECT_NAME_ALLOWLIST = {
     'graphs/partition.sql': ['tree_structural_partition_by_group'],
     'slices/with_context.sql': ['process_slice', 'thread_slice'],
-    'slices/cpu_time.sql': ['thread_slice_cpu_time']
+    'slices/cpu_time.sql': ['thread_slice_cpu_time', 'thread_slice_cpu_cycles']
 }
 
 
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/BUILD.gn
index 55294e7..2d51ae8 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/BUILD.gn
@@ -18,6 +18,7 @@
   sources = [
     "general.sql",
     "process.sql",
+    "slice.sql",
     "system.sql",
     "thread.sql",
   ]
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
index 95a78a8..d47bf20 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
@@ -84,7 +84,8 @@
     cpu,
     ucpu,
     freq
-FROM cpu_frequency_counters;
+FROM cpu_frequency_counters
+WHERE freq IS NOT NULL;
 
 CREATE PERFETTO VIEW _sched_without_id AS
 SELECT ts, dur, utid, ucpu
@@ -96,6 +97,20 @@
     _sched_without_id PARTITIONED ucpu,
     _cpu_freq_for_metrics PARTITIONED ucpu);
 
-CREATE PERFETTO TABLE _cpu_freq_per_thread
-AS SELECT * FROM _cpu_freq_per_thread_span_join;
+CREATE PERFETTO TABLE _cpu_freq_per_thread_no_id
+AS
+SELECT *
+FROM _cpu_freq_per_thread_span_join;
+
+CREATE PERFETTO VIEW _cpu_freq_per_thread AS
+SELECT
+  _auto_id AS id,
+  ts,
+  dur,
+  ucpu,
+  cpu,
+  utid,
+  freq,
+  id AS counter_id
+FROM _cpu_freq_per_thread_no_id;
 
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/slice.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/slice.sql
new file mode 100644
index 0000000..9cbfcd8
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/slice.sql
@@ -0,0 +1,126 @@
+--
+-- Copyright 2024 The Android Open Source Project
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+INCLUDE PERFETTO MODULE linux.cpu.utilization.general;
+
+INCLUDE PERFETTO MODULE time.conversion;
+INCLUDE PERFETTO MODULE intervals.intersect;
+INCLUDE PERFETTO MODULE slices.with_context;
+
+-- CPU cycles per each slice.
+CREATE PERFETTO TABLE cpu_cycles_per_thread_slice(
+  -- Id of a slice. Alias of `slice.id`.
+  id INT,
+  -- Name of the slice.
+  name STRING,
+  -- Id of the thread the slice is running on. Alias of `thread.id`.
+  utid INT,
+  -- Name of the thread.
+  thread_name STRING,
+  -- Id of the process the slice is running on. Alias of `process.id`.
+  upid INT,
+  -- Name of the process.
+  process_name STRING,
+  -- Sum of CPU millicycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  millicycles INT,
+  -- Sum of CPU megacycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  megacycles INT
+) AS
+WITH intersected AS (
+  SELECT
+    id_0 AS slice_id,
+    ii.utid,
+    sum(ii.dur) AS dur,
+    cast_int!(SUM(ii.dur * freq / 1000)) AS millicycles,
+    cast_int!(SUM(ii.dur * freq / 1000) / 1e9) AS megacycles
+  FROM _interval_intersect!(
+    ((SELECT * FROM thread_slice WHERE dur > 0 AND utid > 0),
+    _cpu_freq_per_thread), (utid)) ii
+  JOIN _cpu_freq_per_thread f ON f.id = ii.id_1
+  WHERE freq IS NOT NULL
+  GROUP BY slice_id
+)
+SELECT
+  id,
+  ts.name,
+  ts.utid,
+  ts.thread_name,
+  ts.upid,
+  ts.process_name,
+  millicycles,
+  megacycles
+FROM thread_slice ts
+LEFT JOIN intersected ON slice_id = ts.id AND ts.dur = intersected.dur;
+
+-- CPU cycles per each slice in interval.
+CREATE PERFETTO FUNCTION cpu_cycles_per_thread_slice_in_interval(
+    -- Start of the interval.
+    ts INT,
+    -- Duration of the interval.
+    dur INT
+)
+RETURNS TABLE(
+  -- Id of a slice. Alias of `slice.id`.
+  id INT,
+  -- Name of the slice.
+  name STRING,
+  -- Id of the thread the slice is running on. Alias of `thread.id`.
+  utid INT,
+  -- Name of the thread.
+  thread_name STRING,
+  -- Id of the process the slice is running on. Alias of `process.id`.
+  upid INT,
+  -- Name of the process.
+  process_name STRING,
+  -- Sum of CPU millicycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  millicycles INT,
+  -- Sum of CPU megacycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  megacycles INT
+) AS
+WITH cut_thread_slice AS (
+  SELECT id, ii.ts, ii.dur, thread_slice.*
+  FROM _interval_intersect_single!(
+    $ts, $dur, 
+    (SELECT * FROM thread_slice WHERE dur > 0 AND utid > 0)) ii
+  JOIN thread_slice USING (id)
+),
+intersected AS (
+  SELECT
+    id_0 AS slice_id,
+    ii.utid,
+    sum(ii.dur) AS dur,
+    cast_int!(SUM(ii.dur * freq / 1000)) AS millicycles,
+    cast_int!(SUM(ii.dur * freq / 1000) / 1e9) AS megacycles
+  FROM _interval_intersect!(
+    (cut_thread_slice, _cpu_freq_per_thread), (utid)) ii
+  JOIN _cpu_freq_per_thread f ON f.id = ii.id_1
+  WHERE freq IS NOT NULL
+  GROUP BY slice_id
+)
+SELECT
+  id,
+  ts.name,
+  ts.utid,
+  ts.thread_name,
+  ts.upid,
+  ts.process_name,
+  millicycles,
+  megacycles
+FROM cut_thread_slice ts
+LEFT JOIN intersected ON slice_id = ts.id AND ts.dur = intersected.dur;
\ No newline at end of file
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql
index a1d49e7..413f0f3 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql
@@ -67,49 +67,6 @@
   unnormalized_utilization
 FROM cpu_utilization_per_period(time_from_s(1));
 
--- Aggregated CPU statistics for runtime of each thread on a CPU.
-CREATE PERFETTO TABLE _cpu_cycles_raw(
-  -- Unique CPU id. Joinable with `cpu.id`.
-  ucpu INT,
-  -- The number of the CPU. Might not be the same as ucpu in multi machine cases.
-  cpu INT,
-  -- Unique thread id. Joinable with `thread.id`.
-  utid INT,
-  -- Sum of CPU millicycles.
-  millicycles INT,
-  -- Sum of CPU megacycles.
-  megacycles INT,
-  -- Total runtime duration.
-  runtime INT,
-  -- Minimum CPU frequency in kHz.
-  min_freq INT,
-  -- Maximum CPU frequency in kHz.
-  max_freq INT,
-  -- Average CPU frequency in kHz.
-  avg_freq INT
-) AS
-SELECT
-  ucpu,
-  cpu,
-  utid,
-  -- We divide by 1e3 here as dur is in ns and freq in khz. In total
-  -- this means we need to divide the duration by 1e9 and multiply the
-  -- frequency by 1e3 then multiply again by 1e3 to get millicycles
-  -- i.e. divide by 1e3 in total.
-  -- We use millicycles as we want to preserve this level of precision
-  -- for future calculations.
-  cast_int!(SUM(dur * freq / 1000)) AS millicycles,
-  cast_int!(SUM(dur * freq / 1000) / 1e9) AS megacycles,
-  SUM(dur) AS runtime,
-  MIN(freq) AS min_freq,
-  MAX(freq) AS max_freq,
-  -- We choose to work in micros space in both the numerator and
-  -- denominator as this gives us good enough precision without risking
-  -- overflows.
-  cast_int!(SUM((dur * freq / 1000)) / SUM(dur / 1000)) AS avg_freq
-FROM _cpu_freq_per_thread
-GROUP BY utid, ucpu;
-
 -- Aggregated CPU statistics for whole trace. Results in only one row.
 CREATE PERFETTO TABLE cpu_cycles(
   -- Sum of CPU millicycles.
diff --git a/src/trace_processor/perfetto_sql/stdlib/slices/cpu_time.sql b/src/trace_processor/perfetto_sql/stdlib/slices/cpu_time.sql
index 4a36d9c..c395c21 100644
--- a/src/trace_processor/perfetto_sql/stdlib/slices/cpu_time.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/slices/cpu_time.sql
@@ -13,60 +13,70 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
--- TODO(mayzner): Replace with good implementation of interval intersect.
-CREATE PERFETTO MACRO _interval_intersect_partition_utid(
-  left_table TableOrSubquery,
-  right_table TableOrSubquery
-)
-RETURNS TableOrSubquery AS
-(
-  WITH on_left AS (
-    SELECT
-      B.ts,
-      IIF(
-        A.ts + A.dur <= B.ts + B.dur,
-        A.ts + A.dur - B.ts, B.dur) AS dur,
-      A.id AS left_id,
-      B.id as right_id
-    FROM $left_table A
-    JOIN $right_table B ON (A.ts <= B.ts AND A.ts + A.dur > B.ts AND A.utid = B.utid)
-  ), on_right AS (
-    SELECT
-      B.ts,
-      IIF(
-        A.ts + A.dur <= B.ts + B.dur,
-        A.ts + A.dur - B.ts, B.dur) AS dur,
-      B.id as left_id,
-      A.id AS right_id
-    FROM $right_table A
-    -- The difference between this table and on_left is the lack of equality on
-    -- A.ts <= B.ts. This is to remove the issue of double accounting
-    -- timestamps that start at the same time.
-    JOIN $left_table B ON (A.ts < B.ts AND A.ts + A.dur > B.ts AND A.utid = B.utid)
-  )
-  SELECT * FROM on_left
-  UNION ALL
-  SELECT * FROM on_right
-);
+INCLUDE PERFETTO MODULE intervals.intersect;
+INCLUDE PERFETTO MODULE linux.cpu.utilization.slice;
 
 -- Time each thread slice spent running on CPU.
 -- Requires scheduling data to be available in the trace.
 CREATE PERFETTO TABLE thread_slice_cpu_time(
-    -- Slice id.
-    id INT,
-    -- Duration of the time the slice was running.
-    cpu_time INT) AS
-WITH slice_with_utid AS (
-  SELECT
-      slice.id,
-      slice.ts,
-      slice.dur,
-      utid
-  FROM slice
-  JOIN thread_track ON slice.track_id = thread_track.id
-  JOIN thread USING (utid)
-  WHERE utid != 0)
-SELECT left_id AS id, SUM(dur) AS cpu_time
-FROM _interval_intersect_partition_utid!(slice_with_utid, sched)
-GROUP BY 1
-ORDER BY 1;
\ No newline at end of file
+  -- Id of a slice. Alias of `slice.id`.
+  id INT,
+  -- Name of the slice.
+  name STRING,
+  -- Id of the thread the slice is running on. Alias of `thread.id`.
+  utid INT,
+  -- Name of the thread.
+  thread_name STRING,
+  -- Id of the process the slice is running on. Alias of `process.id`.
+  upid INT,
+  -- Name of the process.
+  process_name STRING,
+  -- Duration of the time the slice was running.
+  cpu_time INT) AS
+SELECT
+id_0 AS id,
+name,
+ts.utid,
+thread_name,
+upid,
+process_name,
+SUM(ii.dur) AS cpu_time
+FROM _interval_intersect!((
+  (SELECT * FROM thread_slice WHERE utid > 0 AND dur > 0),
+  (SELECT * FROM sched WHERE dur > 0)
+  ), (utid)) ii
+JOIN thread_slice ts ON ts.id = ii.id_0
+GROUP BY id
+ORDER BY id;
+
+-- CPU cycles per each slice.
+CREATE PERFETTO VIEW thread_slice_cpu_cycles(
+  -- Id of a slice. Alias of `slice.id`.
+  id INT,
+  -- Name of the slice.
+  name STRING,
+  -- Id of the thread the slice is running on. Alias of `thread.id`.
+  utid INT,
+  -- Name of the thread.
+  thread_name STRING,
+  -- Id of the process the slice is running on. Alias of `process.id`.
+  upid INT,
+  -- Name of the process.
+  process_name STRING,
+  -- Sum of CPU millicycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  millicycles INT,
+  -- Sum of CPU megacycles. Null if frequency couldn't be fetched for any
+  -- period during the runtime of the slice.
+  megacycles INT
+) AS
+SELECT
+  id,
+  name,
+  utid,
+  thread_name,
+  upid,
+  process_name,
+  millicycles,
+  megacycles
+FROM cpu_cycles_per_thread_slice;
diff --git a/test/trace_processor/diff_tests/stdlib/linux/cpu.py b/test/trace_processor/diff_tests/stdlib/linux/cpu.py
index d629708..1c38b5b 100644
--- a/test/trace_processor/diff_tests/stdlib/linux/cpu.py
+++ b/test/trace_processor/diff_tests/stdlib/linux/cpu.py
@@ -159,7 +159,7 @@
              """),
         out=Csv("""
           "millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-          5839969682564,5839,9476034254,614400,1708800,617686
+          31636287288,31,76193077,614400,1708800,415998
             """))
 
   def test_cpu_cycles_per_cpu(self):
@@ -208,10 +208,10 @@
              """),
         out=Csv("""
           "cpu","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-          0,5762458673747,5762,9350177660,614400,1708800,617691
-          1,72344785675,72,117748675,614400,614400,615831
-          2,533252160,0,617190,864000,864000,871327
-          3,4632970982,4,7490729,614400,864000,620044
+          0,27811901835,27,50296201,614400,1708800,554220
+          1,2893791427,2,4709947,614400,614400,615831
+          2,177750720,0,3718178,864000,864000,47885
+          3,752843306,0,17468751,614400,864000,43128
             """))
 
   def test_cpu_cycles_per_thread(self):
@@ -221,17 +221,21 @@
              INCLUDE PERFETTO MODULE linux.cpu.utilization.thread;
 
              SELECT
-               AVG(millicycles) AS millicycles,
-               AVG(megacycles) AS megacycles,
-               AVG(runtime) AS runtime,
-               AVG(min_freq) AS min_freq,
-               AVG(max_freq) AS max_freq,
-               AVG(avg_freq) AS avg_freq
-             FROM cpu_cycles_per_thread;
+              utid,
+              millicycles,
+              megacycles,
+              runtime,
+              min_freq,
+              max_freq,
+              avg_freq
+             FROM cpu_cycles_per_thread
+             WHERE utid < 10
              """),
         out=Csv("""
-            "millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-            25048302164.445362,24.624742,16080173.697531,1402708.453608,1648468.453608,1582627.707216
+        "utid","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
+        1,39042295612,39,28747861,614400,1708800,1359695
+        2,286312857,0,167552,1708800,1708800,1714448
+        8,124651656403,124,99592232,614400,1708800,1255974
             """))
 
   def test_cpu_cycles_per_thread_in_interval(self):
@@ -253,14 +257,18 @@
              """),
         out=Csv("""
             "utid","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-            1,48593411952,48,79090840,614400,614400,615792
-            14,613205232254,613,998055394,614400,614400,615792
-            15,527593574058,527,858713502,614400,614400,615793
-            16,291560471712,291,474545040,614400,614400,615792
-            30,2893791427,2,4709947,614400,614400,615831
-            61,72890117928,72,118636260,614400,614400,615792
-            62,282929432,0,165572,1708800,1708800,1714723
-            92,1071631296,1,1240314,864000,864000,867015
+            1,1226879384,1,1996874,614400,614400,614669
+            14,1247778191,1,2446930,614400,614400,513911
+            15,1407232193,1,2384063,614400,614400,593768
+            16,505278870,0,1142238,614400,614400,444396
+            30,29888102,0,48646,614400,614400,622668
+            37,"[NULL]","[NULL]",222814,"[NULL]","[NULL]","[NULL]"
+            38,"[NULL]","[NULL]",2915520,"[NULL]","[NULL]","[NULL]"
+            45,"[NULL]","[NULL]",2744688,"[NULL]","[NULL]","[NULL]"
+            54,"[NULL]","[NULL]",8614114,"[NULL]","[NULL]","[NULL]"
+            61,151616101,0,246771,614400,614400,618841
+            62,58740000,0,8307552,1708800,1708800,7071
+            92,243675648,0,962397,864000,864000,255157
             """))
 
   def test_cpu_cycles_per_process(self):
@@ -270,17 +278,21 @@
              INCLUDE PERFETTO MODULE linux.cpu.utilization.process;
 
              SELECT
-               AVG(millicycles) AS millicycles,
-               AVG(megacycles) AS megacycles,
-               AVG(runtime) AS runtime,
-               AVG(min_freq) AS min_freq,
-               AVG(max_freq) AS max_freq,
-               AVG(avg_freq) AS avg_freq
-             FROM cpu_cycles_per_process;
+              upid,
+              millicycles,
+              megacycles,
+              runtime,
+              min_freq,
+              max_freq,
+              avg_freq
+             FROM cpu_cycles_per_process
+             WHERE upid < 10
              """),
         out=Csv("""
-            "millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-            83434563989.406891,82.979310,53248030.726027,1193710.344828,1683773.793103,1536705.400000
+        "upid","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
+        1,79550724630,79,56977346,614400,1708800,1398005
+        2,286312857,0,167552,1708800,1708800,1714448
+        8,124651656403,124,99592232,614400,1708800,1255974
             """))
 
   def test_cpu_cycles_per_process_in_interval(self):
@@ -302,10 +314,68 @@
              """),
         out=Csv("""
           "upid","millicycles","megacycles","runtime","min_freq","max_freq","avg_freq"
-          1,121483529880,121,197727100,614400,614400,615792
-          14,613205232254,613,998055394,614400,614400,615792
-          15,527593574058,527,858713502,614400,614400,615793
-          16,291560471712,291,474545040,614400,614400,615792
+          1,2163648305,2,3521563,614400,614400,614672
+          14,1247778191,1,2446930,614400,614400,513911
+          15,1407232193,1,2384063,614400,614400,593768
+          16,505278870,0,1142238,614400,614400,444396
+            """))
+
+  def test_cpu_cycles_per_thread_slice(self):
+    return DiffTestBlueprint(
+        trace=DataPath('android_postboot_unlock.pftrace'),
+        query=("""
+             INCLUDE PERFETTO MODULE linux.cpu.utilization.slice;
+
+             SELECT
+              id,
+              utid,
+              millicycles,
+              megacycles
+             FROM cpu_cycles_per_thread_slice
+             WHERE millicycles IS NOT NULL
+             LIMIT 10
+             """),
+        out=Csv("""
+        "id","utid","millicycles","megacycles"
+        125,6,6375728,0
+        126,6,8699728,0
+        128,6,5565648,0
+        129,6,5565648,0
+        214,6,7132688,0
+        270,6,662972400,0
+        271,6,58483872,0
+        274,6,571785696,0
+        277,6,206411922,0
+        278,6,190908162,0
+            """))
+
+  def test_cpu_cycles_per_thread_slice(self):
+    return DiffTestBlueprint(
+        trace=DataPath('android_postboot_unlock.pftrace'),
+        query=("""
+             INCLUDE PERFETTO MODULE linux.cpu.utilization.slice;
+
+             SELECT
+              id,
+              utid,
+              millicycles,
+              megacycles
+             FROM cpu_cycles_per_thread_slice_in_interval(TRACE_START(), TRACE_DUR() / 10)
+             WHERE millicycles IS NOT NULL
+             LIMIT 10
+             """),
+        out=Csv("""
+        "id","utid","millicycles","megacycles"
+        110,17,13022368,0
+        121,17,9618704,0
+        125,6,6375728,0
+        126,6,8699728,0
+        128,6,5565648,0
+        129,6,5565648,0
+        146,24,6916224,0
+        151,26,5296064,0
+        203,17,150060016,0
+        214,6,7132688,0
             """))
 
   # Test CPU frequency counter grouping.
diff --git a/test/trace_processor/diff_tests/stdlib/slices/tests.py b/test/trace_processor/diff_tests/stdlib/slices/tests.py
index 5555c88..fa326d0 100644
--- a/test/trace_processor/diff_tests/stdlib/slices/tests.py
+++ b/test/trace_processor/diff_tests/stdlib/slices/tests.py
@@ -140,7 +140,7 @@
         query="""
         INCLUDE PERFETTO MODULE slices.cpu_time;
 
-        SELECT *
+        SELECT id, cpu_time
         FROM thread_slice_cpu_time
         LIMIT 10;
         """,