     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;
 

    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
FROM on_msg
JOIN android_sysui_cuj_sf_vsync_boundaries cuj_boundaries
WHERE 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;

    MIN(COALESCE(mtf.ts_next_frame_start, frame.ts_end), frame.ts_end)
      - MAX(COALESCE(mtf.ts_prev_frame_end, 0), frame.ts))
    AS INTEGER) AS dur_frame,
  gcs.ts AS gcs_ts,
  gcs.ts_end AS gcs_ts_end,
  gcs.dur AS gcs_dur,
  CAST(1 AS INTEGER) AS app_missed
FROM android_sysui_cuj_sf_actual_frame_timeline_slice frame
JOIN android_sysui_cuj_surfaceflinger_main_thread_frames mtf ON frame.name = mtf.vsync
LEFT JOIN android_sysui_cuj_surfaceflinger_gpu_completion_slices gcs ON gcs.idx = gcs_idx
WHERE frame.jank_type != 'None';
