• 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 {NUM} from '../../common/query_result';
16import {fromNs, toNsCeil, toNsFloor} from '../../common/time';
17import {LIMIT} from '../../common/track_data';
18import {
19  TrackController,
20  trackControllerRegistry,
21} from '../../controller/track_controller';
22
23import {ANDROID_LOGS_TRACK_KIND, Config, Data} from './common';
24
25class AndroidLogTrackController extends TrackController<Config, Data> {
26  static readonly kind = ANDROID_LOGS_TRACK_KIND;
27
28  async onBoundsChange(start: number, end: number, resolution: number):
29      Promise<Data> {
30    const startNs = toNsFloor(start);
31    const endNs = toNsCeil(end);
32
33    // |resolution| is in s/px the frontend wants.
34    const quantNs = toNsCeil(resolution);
35
36    const queryRes = await this.query(`
37      select
38        cast(ts / ${quantNs} as integer) * ${quantNs} as tsQuant,
39        prio,
40        count(prio) as numEvents
41      from android_logs
42      where ts >= ${startNs} and ts <= ${endNs}
43      group by tsQuant, prio
44      order by tsQuant, prio limit ${LIMIT};`);
45
46    const rowCount = queryRes.numRows();
47    const result = {
48      start,
49      end,
50      resolution,
51      length: rowCount,
52      numEvents: 0,
53      timestamps: new Float64Array(rowCount),
54      priorities: new Uint8Array(rowCount),
55    };
56
57
58    const it = queryRes.iter({tsQuant: NUM, prio: NUM, numEvents: NUM});
59    for (let row = 0; it.valid(); it.next(), row++) {
60      result.timestamps[row] = fromNs(it.tsQuant);
61      const prio = Math.min(it.prio, 7);
62      result.priorities[row] |= (1 << prio);
63      result.numEvents += it.numEvents;
64    }
65    return result;
66  }
67}
68
69trackControllerRegistry.register(AndroidLogTrackController);
70