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 { 16 NamedSliceTrack, 17 NamedSliceTrackTypes 18} from '../../frontend/named_slice_track'; 19import {NewTrackArgs} from '../../frontend/track'; 20import {trackRegistry} from '../../frontend/track_registry'; 21 22export interface GenericSliceTrackConfig { 23 sqlTrackId: number; 24} 25 26export interface GenericSliceTrackTypes extends NamedSliceTrackTypes { 27 config: GenericSliceTrackConfig; 28} 29 30export class GenericSliceTrack extends NamedSliceTrack<GenericSliceTrackTypes> { 31 static readonly kind = 'GenericSliceTrack'; 32 static create(args: NewTrackArgs) { 33 return new GenericSliceTrack(args); 34 } 35 36 constructor(args: NewTrackArgs) { 37 super(args); 38 } 39 40 async initSqlTable(tableName: string): Promise<void> { 41 const sql = `create view ${tableName} as 42 select ts, dur, id, depth, ifnull(name, '') as name 43 from slice where track_id = ${this.config.sqlTrackId}`; 44 await this.engine.query(sql); 45 } 46} 47 48trackRegistry.register(GenericSliceTrack); 49