• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2021 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 {NUM} from '../../common/query_result';
16import {
17  TrackController,
18  trackControllerRegistry
19} from '../../controller/track_controller';
20
21import {
22  Config,
23  Data,
24  PERF_SAMPLES_PROFILE_TRACK_KIND,
25} from './common';
26
27class PerfSamplesProfileTrackController extends TrackController<Config, Data> {
28  static readonly kind = PERF_SAMPLES_PROFILE_TRACK_KIND;
29  async onBoundsChange(start: number, end: number, resolution: number):
30      Promise<Data> {
31    if (this.config.upid === undefined) {
32      return {
33        start,
34        end,
35        resolution,
36        length: 0,
37        tsStartsNs: new Float64Array()
38      };
39    }
40    const queryRes = await this.query(`
41     select ts, upid from perf_sample
42     join thread using (utid)
43     where upid = ${this.config.upid}
44     order by ts`);
45    const numRows = queryRes.numRows();
46    const data: Data = {
47      start,
48      end,
49      resolution,
50      length: numRows,
51      tsStartsNs: new Float64Array(numRows)
52    };
53
54    const it = queryRes.iter({ts: NUM});
55    for (let row = 0; it.valid(); it.next(), row++) {
56      data.tsStartsNs[row] = it.ts;
57    }
58    return data;
59  }
60}
61
62trackControllerRegistry.register(PerfSamplesProfileTrackController);
63