xref: /aosp_15_r20/external/perfetto/ui/src/public/aggregation.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1// Copyright (C) 2019 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
15export type Column = (
16  | StringColumn
17  | TimestampColumn
18  | NumberColumn
19  | StateColumn
20) & {
21  readonly title: string;
22  readonly columnId: string;
23};
24
25export interface StringColumn {
26  readonly kind: 'STRING';
27  readonly data: Uint16Array;
28}
29
30export interface TimestampColumn {
31  readonly kind: 'TIMESTAMP_NS';
32  readonly data: Float64Array;
33}
34
35export interface NumberColumn {
36  readonly kind: 'NUMBER';
37  readonly data: Uint16Array;
38}
39
40export interface StateColumn {
41  readonly kind: 'STATE';
42  readonly data: Uint16Array;
43}
44
45type TypedArrayConstructor =
46  | Uint16ArrayConstructor
47  | Float64ArrayConstructor
48  | Uint32ArrayConstructor;
49export interface ColumnDef {
50  readonly title: string;
51  readonly kind: string;
52  readonly sum?: boolean;
53  readonly columnConstructor: TypedArrayConstructor;
54  readonly columnId: string;
55}
56
57export interface AggregateData {
58  readonly tabName: string;
59  readonly columns: Column[];
60  readonly columnSums: string[];
61  // For string interning.
62  readonly strings: string[];
63  // Some aggregations will have extra info to display;
64  readonly extra?: ThreadStateExtra;
65}
66
67export function isEmptyData(data: AggregateData) {
68  return data.columns.length === 0 || data.columns[0].data.length === 0;
69}
70
71export interface ThreadStateExtra {
72  readonly kind: 'THREAD_STATE';
73  readonly states: string[];
74  readonly values: Float64Array;
75  readonly totalMs: number;
76}
77
78export interface Sorting {
79  readonly column: string;
80  readonly direction: 'DESC' | 'ASC';
81}
82