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 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 15 | import {assertExists} from '../base/logging'; |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 16 | import {Action} from '../common/actions'; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 17 | import {createEmptyState, State} from '../common/state'; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 18 | |
Deepanjan Roy | 9d95a25 | 2018-08-09 10:10:19 -0400 | [diff] [blame] | 19 | import {FrontendLocalState} from './frontend_local_state'; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 20 | import {RafScheduler} from './raf_scheduler'; |
Hector Dearman | 306a539 | 2018-07-26 15:29:42 +0100 | [diff] [blame] | 21 | |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 22 | type Dispatch = (action: Action) => void; |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 23 | type TrackDataStore = Map<string, {}>; |
Primiano Tucci | 8afc06d | 2018-08-06 19:11:42 +0100 | [diff] [blame] | 24 | type QueryResultsStore = Map<string, {}>; |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 25 | |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 26 | export interface QuantizedLoad { |
| 27 | startSec: number; |
| 28 | endSec: number; |
| 29 | load: number; |
| 30 | } |
| 31 | type OverviewStore = Map<string, QuantizedLoad[]>; |
| 32 | |
| 33 | export interface ThreadDesc { |
| 34 | utid: number; |
| 35 | tid: number; |
| 36 | threadName: string; |
| 37 | pid: number; |
| 38 | procName: string; |
| 39 | } |
| 40 | type ThreadMap = Map<number, ThreadDesc>; |
| 41 | |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 42 | /** |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 43 | * Global accessors for state/dispatch in the frontend. |
Hector Dearman | 916c761 | 2018-07-09 15:42:22 +0100 | [diff] [blame] | 44 | */ |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 45 | class Globals { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 46 | private _dispatch?: Dispatch = undefined; |
| 47 | private _state?: State = undefined; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 48 | private _frontendLocalState?: FrontendLocalState = undefined; |
| 49 | private _rafScheduler?: RafScheduler = undefined; |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 50 | |
| 51 | // TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads. |
| 52 | private _trackDataStore?: TrackDataStore = undefined; |
| 53 | private _queryResults?: QueryResultsStore = undefined; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 54 | private _overviewStore?: OverviewStore = undefined; |
| 55 | private _threadMap?: ThreadMap = undefined; |
Hector Dearman | a38bd90 | 2018-08-02 10:38:41 +0100 | [diff] [blame] | 56 | |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 57 | initialize(dispatch?: Dispatch) { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 58 | this._dispatch = dispatch; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 59 | this._state = createEmptyState(); |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 60 | this._frontendLocalState = new FrontendLocalState(); |
| 61 | this._rafScheduler = new RafScheduler(); |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 62 | |
| 63 | // TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads. |
| 64 | this._trackDataStore = new Map<string, {}>(); |
| 65 | this._queryResults = new Map<string, {}>(); |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 66 | this._overviewStore = new Map<string, QuantizedLoad[]>(); |
| 67 | this._threadMap = new Map<number, ThreadDesc>(); |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 70 | get state(): State { |
| 71 | return assertExists(this._state); |
| 72 | } |
| 73 | |
| 74 | set state(state: State) { |
| 75 | this._state = assertExists(state); |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | get dispatch(): Dispatch { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 79 | return assertExists(this._dispatch); |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 82 | get frontendLocalState() { |
| 83 | return assertExists(this._frontendLocalState); |
| 84 | } |
| 85 | |
| 86 | get rafScheduler() { |
| 87 | return assertExists(this._rafScheduler); |
| 88 | } |
| 89 | |
| 90 | // TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads. |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 91 | get overviewStore(): OverviewStore { |
| 92 | return assertExists(this._overviewStore); |
| 93 | } |
| 94 | |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 95 | get trackDataStore(): TrackDataStore { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 96 | return assertExists(this._trackDataStore); |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Primiano Tucci | 8afc06d | 2018-08-06 19:11:42 +0100 | [diff] [blame] | 99 | get queryResults(): QueryResultsStore { |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 100 | return assertExists(this._queryResults); |
Primiano Tucci | 8afc06d | 2018-08-06 19:11:42 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 103 | get threads() { |
| 104 | return assertExists(this._threadMap); |
| 105 | } |
| 106 | |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 107 | resetForTesting() { |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 108 | this._dispatch = undefined; |
| 109 | this._state = undefined; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 110 | this._frontendLocalState = undefined; |
| 111 | this._rafScheduler = undefined; |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 112 | |
| 113 | // TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads. |
| 114 | this._trackDataStore = undefined; |
| 115 | this._queryResults = undefined; |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 116 | this._overviewStore = undefined; |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 117 | this._threadMap = undefined; |
Hector Dearman | a16f8a9 | 2018-07-18 17:29:09 +0100 | [diff] [blame] | 118 | } |
| 119 | } |
Hector Dearman | 510bbe0 | 2018-07-17 17:02:09 +0100 | [diff] [blame] | 120 | |
Hector Dearman | 306a539 | 2018-07-26 15:29:42 +0100 | [diff] [blame] | 121 | export const globals = new Globals(); |