• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {fromNs} from '../../common/time';
16import {LIMIT} from '../../common/track_data';
17
18import {
19  TrackController,
20  trackControllerRegistry
21} from '../../controller/track_controller';
22
23import {Config, Data, KIND} from './common';
24
25class VsyncTrackController extends TrackController<Config, Data> {
26  static readonly kind = KIND;
27  private setup = false;
28
29  async onBoundsChange(start: number, end: number, resolution: number):
30      Promise<Data> {
31    if (this.setup === false) {
32      await this.query(
33          `create virtual table window_${this.trackState.id} using window;`);
34      await this.query(
35          `create virtual table span_${this.trackState.id}
36              using span_join(sched PARTITIONED cpu,
37                              window_${this.trackState.id});`);
38      this.setup = true;
39    }
40
41    const rawResult = await this.engine.query(`
42      select ts from counters
43        where name like "${this.config.counterName}%"
44        order by ts limit ${LIMIT};`);
45    const rowCount = +rawResult.numRecords;
46    const result = {
47      start,
48      end,
49      resolution,
50      length: rowCount,
51      vsyncs: new Float64Array(rowCount),
52    };
53    const cols = rawResult.columns;
54    for (let i = 0; i < rowCount; i++) {
55      const startSec = fromNs(+cols[0].longValues![i]);
56      result.vsyncs[i] = startSec;
57    }
58    return result;
59  }
60
61  onDestroy(): void {
62    if (this.setup) {
63      this.query(`drop table window_${this.trackState.id}`);
64      this.query(`drop table span_${this.trackState.id}`);
65      this.setup = false;
66    }
67  }
68}
69
70trackControllerRegistry.register(VsyncTrackController);
71