blob: 935b7be99e110b82cc6c2481f3f5aa651e22041d [file] [log] [blame]
Hector Dearman916c7612018-07-09 15:42:22 +01001// 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
Deepanjan Roy75b46a92018-07-24 09:11:29 -040015/**
16 * A plain js object, holding objects of type |Class| keyed by string id.
17 * We use this instead of using |Map| object since it is simpler and faster to
18 * serialize for use in postMessage.
19 */
20export interface ObjectById<Class extends{id: string}> { [id: string]: Class; }
21
Deepanjan Roy75b46a92018-07-24 09:11:29 -040022export interface TrackState {
23 id: string;
Hector Dearmana38bd902018-08-02 10:38:41 +010024 engineId: string;
Primiano Tucci9b5f13e2018-08-10 00:36:19 +010025 maxDepth: number;
Hector Dearmanc62a5e32018-07-27 12:54:44 +010026 kind: string;
Hector Dearmana38bd902018-08-02 10:38:41 +010027 name: string;
Primiano Tuccidc3dbcb2018-08-10 00:34:33 +010028 // TODO: These need to be nested into track kind spesific state.
29 // cpu slice state:
Hector Dearmana38bd902018-08-02 10:38:41 +010030 cpu: number;
Primiano Tuccidc3dbcb2018-08-10 00:34:33 +010031 // chrome slice state:
32 upid?: number;
33 utid?: number;
Hector Dearmana38bd902018-08-02 10:38:41 +010034}
35
36export interface EngineConfig {
37 id: string;
Primiano Tucci8afc06d2018-08-06 19:11:42 +010038 ready: boolean;
Hector Dearmanf9f2db02018-08-03 13:09:32 +010039 source: string|File;
Hector Dearmana38bd902018-08-02 10:38:41 +010040}
41
42export interface QueryConfig {
43 id: string;
44 engineId: string;
45 query: string;
46}
47
Hector Dearman03f962c2018-08-09 17:00:32 +010048export interface PermalinkConfig { state: State; }
49
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020050export interface TraceTime {
51 startSec: number;
52 endSec: number;
53}
54
Hector Dearmana38bd902018-08-02 10:38:41 +010055export interface State {
56 route: string|null;
57 nextId: number;
58
59 /**
60 * Open traces.
61 */
62 engines: ObjectById<EngineConfig>;
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020063 traceTime: TraceTime;
Hector Dearmana38bd902018-08-02 10:38:41 +010064 tracks: ObjectById<TrackState>;
Michail Schwab1cc1aa02018-08-02 14:45:35 -040065 displayedTrackIds: string[];
Hector Dearmana38bd902018-08-02 10:38:41 +010066 queries: ObjectById<QueryConfig>;
Hector Dearman03f962c2018-08-09 17:00:32 +010067 permalink: null|PermalinkConfig;
Deepanjan Roy75b46a92018-07-24 09:11:29 -040068}
Hector Dearman916c7612018-07-09 15:42:22 +010069
70export function createEmptyState(): State {
71 return {
Hector Dearmana38bd902018-08-02 10:38:41 +010072 route: null,
73 nextId: 0,
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020074 engines: {},
75 traceTime: {startSec: 0, endSec: 10},
Deepanjan Roy75b46a92018-07-24 09:11:29 -040076 tracks: {},
Michail Schwab1cc1aa02018-08-02 14:45:35 -040077 displayedTrackIds: [],
Hector Dearmana38bd902018-08-02 10:38:41 +010078 queries: {},
Hector Dearman03f962c2018-08-09 17:00:32 +010079 permalink: null,
Hector Dearman916c7612018-07-09 15:42:22 +010080 };
81}