     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
+    lead(match.commit_ts) OVER (ORDER BY match.commit_ts ASC) AS ts_next_frame_start,
+    composite.gcs_idx
   FROM commit_to_composite match
   JOIN android_sysui_cuj_surfaceflinger_composite_slices composite ON match.composite_ts = composite.ts;
 

JOIN android_sysui_cuj_sf_vsync_boundaries cuj_boundaries
WHERE vsync >= cuj_boundaries.vsync_min AND vsync <= cuj_boundaries.vsync_max;

-- Find just the onMessageInvalidate slices, within the CUJ (by vsync)
DROP VIEW IF EXISTS android_sysui_cuj_surfaceflinger_on_message_invalidate_slices_in_cuj;
CREATE VIEW android_sysui_cuj_surfaceflinger_on_message_invalidate_slices_in_cuj AS

    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,
    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
