     CAST(CAST(STR_SPLIT(slice.name, ' ', 3) AS NUMBER) * 1e6 + slice.ts AS INTEGER) AS expected_vsync_ts,
     slice.ts,
     slice.ts + slice.dur AS ts_end,
-    slice.dur
-  FROM slice
-  JOIN android_sysui_cuj_sf_main_thread_track main_track ON slice.track_id = main_track.id
+    slice.dur,
+    gcs.gcs_idx
+  FROM slice
+  JOIN android_sysui_cuj_sf_main_thread_track main_track ON slice.track_id = main_track.id
+  LEFT JOIN android_sysui_cuj_sf_mts_to_gcs gcs ON slice.ts = gcs.ts
   WHERE slice.name GLOB 'onMessageInvalidate *'
   )
 SELECT

    composite.ts_end - match.commit_ts AS dur,
    match.expected_vsync_ts,
    lag(composite.ts_end) OVER (ORDER BY composite.ts_end ASC) AS ts_prev_frame_end,
    lead(match.commit_ts) OVER (ORDER BY match.commit_ts ASC) AS ts_next_frame_start
  FROM commit_to_composite match
  JOIN android_sysui_cuj_surfaceflinger_composite_slices composite ON match.composite_ts = composite.ts;


    on_msg.dur,
    on_msg.expected_vsync_ts,
    lag(on_msg.ts_end) OVER (ORDER BY on_msg.ts_end ASC) AS ts_prev_frame_end,
    lead(on_msg.ts) OVER (ORDER BY on_msg.ts ASC) AS ts_next_frame_start,
    on_msg.gcs_idx
FROM on_msg
JOIN android_sysui_cuj_sf_vsync_boundaries cuj_boundaries
ON on_msg.vsync >= cuj_boundaries.vsync_min AND on_msg.vsync <= cuj_boundaries.vsync_max;

-- Find just the composite slices
DROP TABLE IF EXISTS android_sysui_cuj_surfaceflinger_composite_slices;
