ui: remove vsync tracks

* vsync trakcs should really be created from metrics using the derived
  events feature of trace processor. They should also just use the
  generic counter implementation when they do that.
* Also add the missing link between trace_controller and async tracks
  which was missing.

Change-Id: I2f936435f2cc1a0622e5bdc153ffa9e127d9f07b
diff --git a/ui/src/controller/trace_controller.ts b/ui/src/controller/trace_controller.ts
index 826e855..99811ef 100644
--- a/ui/src/controller/trace_controller.ts
+++ b/ui/src/controller/trace_controller.ts
@@ -38,6 +38,7 @@
 } from '../common/wasm_engine_proxy';
 import {QuantizedLoad, ThreadDesc} from '../frontend/globals';
 import {ANDROID_LOGS_TRACK_KIND} from '../tracks/android_log/common';
+import {ASYNC_SLICE_TRACK_KIND} from '../tracks/async_slices/common';
 import {SLICE_TRACK_KIND} from '../tracks/chrome_slices/common';
 import {CPU_FREQ_TRACK_KIND} from '../tracks/cpu_freq/common';
 import {CPU_PROFILE_TRACK_KIND} from '../tracks/cpu_profile/common';
@@ -311,25 +312,6 @@
     const numGpus = await engine.getNumberOfGpus();
     const tracksToAdd: AddTrackArgs[] = [];
 
-    // TODO(hjd): Renable Vsync tracks when fixed.
-    //// TODO(hjd): Move this code out of TraceController.
-    // for (const counterName of ['VSYNC-sf', 'VSYNC-app']) {
-    //  const hasVsync =
-    //      !!(await engine.query(
-    //             `select ts from counters where name like "${
-    //                                                         counterName
-    //                                                       }" limit 1`))
-    //            .numRecords;
-    //  if (!hasVsync) continue;
-    //  addToTrackActions.push(Actions.addTrack({
-    //    engineId: this.engineId,
-    //    kind: 'VsyncTrack',
-    //    name: `${counterName}`,
-    //    config: {
-    //      counterName,
-    //    }
-    //  }));
-    //}
     const maxCpuFreq = await engine.query(`
       select max(value)
       from counter c
@@ -414,7 +396,7 @@
       const maxDepth = +rawGlobalAsyncTracks.columns[2].longValues![i];
       const track = {
         engineId: this.engineId,
-        kind: 'AsyncSliceTrack',
+        kind: ASYNC_SLICE_TRACK_KIND,
         trackGroup: SCROLLING_TRACK_GROUP,
         name,
         config: {
diff --git a/ui/src/tracks/all_controller.ts b/ui/src/tracks/all_controller.ts
index f2a573d..777f2ec 100644
--- a/ui/src/tracks/all_controller.ts
+++ b/ui/src/tracks/all_controller.ts
@@ -25,5 +25,4 @@
 import './process_scheduling/controller';
 import './process_summary/controller';
 import './thread_state/controller';
-import './vsync/controller';
 import './async_slices/controller';
diff --git a/ui/src/tracks/all_frontend.ts b/ui/src/tracks/all_frontend.ts
index 5d90e9f..fc3fd8d 100644
--- a/ui/src/tracks/all_frontend.ts
+++ b/ui/src/tracks/all_frontend.ts
@@ -25,5 +25,4 @@
 import './process_scheduling/frontend';
 import './process_summary/frontend';
 import './thread_state/frontend';
-import './vsync/frontend';
 import './async_slices/frontend';
diff --git a/ui/src/tracks/async_slices/common.ts b/ui/src/tracks/async_slices/common.ts
index daa0802..7bdd794 100644
--- a/ui/src/tracks/async_slices/common.ts
+++ b/ui/src/tracks/async_slices/common.ts
@@ -13,7 +13,7 @@
 // limitations under the License.
 import {TrackData} from '../../common/track_data';
 
-export const SLICE_TRACK_KIND = 'AsyncSliceTrack';
+export const ASYNC_SLICE_TRACK_KIND = 'AsyncSliceTrack';
 
 export interface Config {
   maxDepth: number;
diff --git a/ui/src/tracks/async_slices/controller.ts b/ui/src/tracks/async_slices/controller.ts
index 77049c8..57694bc 100644
--- a/ui/src/tracks/async_slices/controller.ts
+++ b/ui/src/tracks/async_slices/controller.ts
@@ -19,10 +19,10 @@
   trackControllerRegistry,
 } from '../../controller/track_controller';
 
-import {Config, Data, SLICE_TRACK_KIND} from './common';
+import {ASYNC_SLICE_TRACK_KIND, Config, Data} from './common';
 
 class AsyncSliceTrackController extends TrackController<Config, Data> {
-  static readonly kind = SLICE_TRACK_KIND;
+  static readonly kind = ASYNC_SLICE_TRACK_KIND;
   private setup = false;
 
   async onBoundsChange(start: number, end: number, resolution: number):
diff --git a/ui/src/tracks/async_slices/frontend.ts b/ui/src/tracks/async_slices/frontend.ts
index 918f831..17d4d14 100644
--- a/ui/src/tracks/async_slices/frontend.ts
+++ b/ui/src/tracks/async_slices/frontend.ts
@@ -17,10 +17,10 @@
 import {trackRegistry} from '../../frontend/track_registry';
 import {ChromeSliceTrack} from '../chrome_slices/frontend';
 
-import {SLICE_TRACK_KIND} from './common';
+import {ASYNC_SLICE_TRACK_KIND} from './common';
 
 export class AsyncSliceTrack extends ChromeSliceTrack {
-  static readonly kind = SLICE_TRACK_KIND;
+  static readonly kind = ASYNC_SLICE_TRACK_KIND;
   static create(trackState: TrackState): Track {
     return new AsyncSliceTrack(trackState);
   }
diff --git a/ui/src/tracks/vsync/common.ts b/ui/src/tracks/vsync/common.ts
deleted file mode 100644
index 9d8f968..0000000
--- a/ui/src/tracks/vsync/common.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-
-// Copyright (C) 2018 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
-//
-//      http://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.
-
-import {TrackData} from '../../common/track_data';
-
-export const KIND = 'VsyncTrack';
-
-export interface Data extends TrackData { vsyncs: Float64Array; }
-
-export interface Config { counterName: string; }
diff --git a/ui/src/tracks/vsync/controller.ts b/ui/src/tracks/vsync/controller.ts
deleted file mode 100644
index 4934758..0000000
--- a/ui/src/tracks/vsync/controller.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (C) 2018 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
-//
-//      http://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.
-
-import {fromNs} from '../../common/time';
-import {LIMIT} from '../../common/track_data';
-
-import {
-  TrackController,
-  trackControllerRegistry
-} from '../../controller/track_controller';
-
-import {Config, Data, KIND} from './common';
-
-class VsyncTrackController extends TrackController<Config, Data> {
-  static readonly kind = KIND;
-  private setup = false;
-
-  async onBoundsChange(start: number, end: number, resolution: number):
-      Promise<Data> {
-    if (this.setup === false) {
-      await this.query(
-          `create virtual table window_${this.trackState.id} using window;`);
-      await this.query(
-          `create virtual table span_${this.trackState.id}
-              using span_join(sched PARTITIONED cpu,
-                              window_${this.trackState.id});`);
-      this.setup = true;
-    }
-
-    const rawResult = await this.engine.query(`
-      select ts from counters
-        where name like "${this.config.counterName}%"
-        order by ts limit ${LIMIT};`);
-    const rowCount = +rawResult.numRecords;
-    const result = {
-      start,
-      end,
-      resolution,
-      length: rowCount,
-      vsyncs: new Float64Array(rowCount),
-    };
-    const cols = rawResult.columns;
-    for (let i = 0; i < rowCount; i++) {
-      const startSec = fromNs(+cols[0].longValues![i]);
-      result.vsyncs[i] = startSec;
-    }
-    return result;
-  }
-
-  onDestroy(): void {
-    if (this.setup) {
-      this.query(`drop table window_${this.trackState.id}`);
-      this.query(`drop table span_${this.trackState.id}`);
-      this.setup = false;
-    }
-  }
-}
-
-trackControllerRegistry.register(VsyncTrackController);
diff --git a/ui/src/tracks/vsync/frontend.ts b/ui/src/tracks/vsync/frontend.ts
deleted file mode 100644
index d1f4f78..0000000
--- a/ui/src/tracks/vsync/frontend.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (C) 2018 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
-//
-//      http://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.
-
-import {TrackState} from '../../common/state';
-import {checkerboardExcept} from '../../frontend/checkerboard';
-import {globals} from '../../frontend/globals';
-import {Track} from '../../frontend/track';
-import {trackRegistry} from '../../frontend/track_registry';
-
-import {Config, Data, KIND} from './common';
-
-// TODO(hjd): De-dupe this from ChromeSliceTrack, CpuSliceTrack and VsyncTrack.
-const MARGIN_TOP = 5;
-const RECT_HEIGHT = 30;
-
-class VsyncTrack extends Track<Config, Data> {
-  static readonly kind = KIND;
-  static create(trackState: TrackState): VsyncTrack {
-    return new VsyncTrack(trackState);
-  }
-
-  constructor(trackState: TrackState) {
-    super(trackState);
-  }
-
-  renderCanvas(ctx: CanvasRenderingContext2D): void {
-    const {timeScale, visibleWindowTime} = globals.frontendLocalState;
-
-    const data = this.data();
-    if (data === undefined) return;  // Can't possibly draw anything.
-
-    const dataStartPx = timeScale.timeToPx(data.start);
-    const dataEndPx = timeScale.timeToPx(data.end);
-    const visibleStartPx = timeScale.timeToPx(visibleWindowTime.start);
-    const visibleEndPx = timeScale.timeToPx(visibleWindowTime.end);
-
-    checkerboardExcept(
-        ctx,
-        this.getHeight(),
-        visibleStartPx,
-        visibleEndPx,
-        dataStartPx,
-        dataEndPx);
-
-    const bgColor = '#5E909B';
-    const fgColor = '#323D48';
-
-    const startPx = Math.floor(Math.max(dataStartPx, visibleStartPx));
-    const endPx = Math.floor(Math.min(dataEndPx, visibleEndPx));
-
-    ctx.fillStyle = bgColor;
-    ctx.fillRect(startPx, MARGIN_TOP, endPx - startPx, RECT_HEIGHT);
-
-    ctx.fillStyle = fgColor;
-    for (let i = 0; i < data.vsyncs.length; i += 2) {
-      const leftPx = Math.floor(timeScale.timeToPx(data.vsyncs[i]));
-      const rightPx = Math.floor(timeScale.timeToPx(data.vsyncs[i + 1]));
-      if (rightPx < startPx) continue;
-      // TODO(hjd): Do some thing better when very zoomed out.
-      if ((rightPx - leftPx) <= 1) continue;
-      if (leftPx > endPx) break;
-      ctx.fillRect(leftPx, MARGIN_TOP, rightPx - leftPx, RECT_HEIGHT);
-    }
-  }
-}
-
-trackRegistry.register(VsyncTrack);