• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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
15// Definition of the SQL table to be displayed in the SQL table widget,
16// including the semantic definitions of the columns (e.g. timestamp
17// column which requires special formatting). Also note that some of the
18// columns require other columns for advanced display features (e.g. timestamp
19// and duration taken together define "a time range", which can be used for
20// additional filtering.
21
22export type DisplayConfig =
23  | SliceIdDisplayConfig
24  | Timestamp
25  | Duration
26  | ThreadDuration;
27
28// Common properties for all columns.
29interface SqlTableColumnBase {
30  // Name of the column in the SQL table.
31  name: string;
32  // Display name of the column in the UI.
33  title?: string;
34}
35
36export interface ArgSetIdColumn extends SqlTableColumnBase {
37  type: 'arg_set_id';
38}
39
40export interface RegularSqlTableColumn extends SqlTableColumnBase {
41  // Special rendering instructions for this column, including the list
42  // of additional columns required for the rendering.
43  display?: DisplayConfig;
44  // Whether the column should be hidden by default.
45  startsHidden?: boolean;
46}
47
48export type SqlTableColumn = RegularSqlTableColumn | ArgSetIdColumn;
49
50export function startsHidden(c: SqlTableColumn): boolean {
51  if (isArgSetIdColumn(c)) return true;
52  return c.startsHidden ?? false;
53}
54
55export function isArgSetIdColumn(c: SqlTableColumn): c is ArgSetIdColumn {
56  return (c as {type?: string}).type === 'arg_set_id';
57}
58
59export interface SqlTableDescription {
60  readonly imports?: string[];
61  name: string;
62  displayName?: string;
63  columns: SqlTableColumn[];
64}
65
66export function tableDisplayName(table: SqlTableDescription): string {
67  return table.displayName ?? table.name;
68}
69
70// Additional columns needed to display the given column.
71export function dependendentColumns(display?: DisplayConfig): string[] {
72  switch (display?.type) {
73    case 'slice_id':
74      return [display.ts, display.dur, display.trackId];
75    default:
76      return [];
77  }
78}
79
80// Column displaying ids into the `slice` table. Requires the ts, dur and
81// track_id columns to be able to display the value, including the
82// "go-to-slice-on-click" functionality.
83export interface SliceIdDisplayConfig {
84  type: 'slice_id';
85  ts: string;
86  dur: string;
87  trackId: string;
88}
89
90// Column displaying timestamps.
91interface Timestamp {
92  type: 'timestamp';
93}
94
95// Column displaying durations.
96export interface Duration {
97  type: 'duration';
98}
99
100// Column displaying thread durations.
101export interface ThreadDuration {
102  type: 'thread_duration';
103}
104