Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 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 | |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 15 | /** |
| 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 | */ |
| 20 | export interface ObjectById<Class extends{id: string}> { [id: string]: Class; } |
| 21 | |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 22 | export interface TrackState { |
| 23 | id: string; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 24 | engineId: string; |
Primiano Tucci | 9b5f13e | 2018-08-10 00:36:19 +0100 | [diff] [blame] | 25 | maxDepth: number; |
Hector Dearman | c62a5e3 | 2018-07-27 12:54:44 +0100 | [diff] [blame] | 26 | kind: string; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 27 | name: string; |
Primiano Tucci | dc3dbcb | 2018-08-10 00:34:33 +0100 | [diff] [blame] | 28 | // TODO: These need to be nested into track kind spesific state. |
| 29 | // cpu slice state: |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 30 | cpu: number; |
Primiano Tucci | dc3dbcb | 2018-08-10 00:34:33 +0100 | [diff] [blame] | 31 | // chrome slice state: |
| 32 | upid?: number; |
| 33 | utid?: number; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 34 | dataReq?: TrackDataRequest; |
| 35 | } |
| 36 | |
| 37 | export interface TrackDataRequest { |
| 38 | start: number; |
| 39 | end: number; |
| 40 | resolution: number; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | export interface EngineConfig { |
| 44 | id: string; |
Primiano Tucci | 8afc06d | 2018-08-06 19:11:42 +0100 | [diff] [blame] | 45 | ready: boolean; |
Hector Dearman | f9f2db0 | 2018-08-03 13:09:32 +0100 | [diff] [blame] | 46 | source: string|File; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | export interface QueryConfig { |
| 50 | id: string; |
| 51 | engineId: string; |
| 52 | query: string; |
| 53 | } |
| 54 | |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 55 | export interface PermalinkConfig { |
| 56 | requestId?: string; // Set by the frontend to request a new permalink. |
| 57 | hash?: string; // Set by the controller when the link has been created. |
| 58 | } |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 59 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 60 | export interface TraceTime { |
| 61 | startSec: number; |
| 62 | endSec: number; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 63 | lastUpdate: number; // Epoch in seconds (Date.now() / 1000). |
| 64 | } |
| 65 | |
| 66 | export interface Status { |
| 67 | msg: string; |
| 68 | timestamp: number; // Epoch in seconds (Date.now() / 1000). |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 71 | export interface State { |
| 72 | route: string|null; |
| 73 | nextId: number; |
| 74 | |
| 75 | /** |
| 76 | * Open traces. |
| 77 | */ |
| 78 | engines: ObjectById<EngineConfig>; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 79 | traceTime: TraceTime; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 80 | visibleTraceTime: TraceTime; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 81 | tracks: ObjectById<TrackState>; |
Michail Schwab | 1cc1aa0 | 2018-08-02 14:45:35 -0400 | [diff] [blame] | 82 | displayedTrackIds: string[]; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 83 | queries: ObjectById<QueryConfig>; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 84 | permalink: PermalinkConfig; |
| 85 | status: Status; |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 86 | } |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 87 | |
| 88 | export function createEmptyState(): State { |
| 89 | return { |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 90 | route: null, |
| 91 | nextId: 0, |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 92 | engines: {}, |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 93 | traceTime: {startSec: 0, endSec: 10, lastUpdate: 0}, |
| 94 | visibleTraceTime: {startSec: 0, endSec: 10, lastUpdate: 0}, |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 95 | tracks: {}, |
Michail Schwab | 1cc1aa0 | 2018-08-02 14:45:35 -0400 | [diff] [blame] | 96 | displayedTrackIds: [], |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 97 | queries: {}, |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 98 | permalink: {}, |
| 99 | status: {msg: '', timestamp: 0}, |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 100 | }; |
| 101 | } |