blob: e370127ec8b19a99a7d9b3122f4e33951c672232 [file] [log] [blame]
// Copyright (C) 2018 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {assertExists} from '../base/logging';
import {Action} from '../common/actions';
import {createEmptyState, State} from '../common/state';
import {FrontendLocalState} from './frontend_local_state';
import {RafScheduler} from './raf_scheduler';
type Dispatch = (action: Action) => void;
type TrackDataStore = Map<string, {}>;
type QueryResultsStore = Map<string, {}>;
export interface QuantizedLoad {
startSec: number;
endSec: number;
load: number;
}
type OverviewStore = Map<string, QuantizedLoad[]>;
export interface ThreadDesc {
utid: number;
tid: number;
threadName: string;
pid: number;
procName: string;
}
type ThreadMap = Map<number, ThreadDesc>;
/**
* Global accessors for state/dispatch in the frontend.
*/
class Globals {
private _dispatch?: Dispatch = undefined;
private _state?: State = undefined;
private _frontendLocalState?: FrontendLocalState = undefined;
private _rafScheduler?: RafScheduler = undefined;
// TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads.
private _trackDataStore?: TrackDataStore = undefined;
private _queryResults?: QueryResultsStore = undefined;
private _overviewStore?: OverviewStore = undefined;
private _threadMap?: ThreadMap = undefined;
initialize(dispatch?: Dispatch) {
this._dispatch = dispatch;
this._state = createEmptyState();
this._frontendLocalState = new FrontendLocalState();
this._rafScheduler = new RafScheduler();
// TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads.
this._trackDataStore = new Map<string, {}>();
this._queryResults = new Map<string, {}>();
this._overviewStore = new Map<string, QuantizedLoad[]>();
this._threadMap = new Map<number, ThreadDesc>();
}
get state(): State {
return assertExists(this._state);
}
set state(state: State) {
this._state = assertExists(state);
}
get dispatch(): Dispatch {
return assertExists(this._dispatch);
}
get frontendLocalState() {
return assertExists(this._frontendLocalState);
}
get rafScheduler() {
return assertExists(this._rafScheduler);
}
// TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads.
get overviewStore(): OverviewStore {
return assertExists(this._overviewStore);
}
get trackDataStore(): TrackDataStore {
return assertExists(this._trackDataStore);
}
get queryResults(): QueryResultsStore {
return assertExists(this._queryResults);
}
get threads() {
return assertExists(this._threadMap);
}
resetForTesting() {
this._dispatch = undefined;
this._state = undefined;
this._frontendLocalState = undefined;
this._rafScheduler = undefined;
// TODO(hjd): Unify trackDataStore, queryResults, overviewStore, threads.
this._trackDataStore = undefined;
this._queryResults = undefined;
this._overviewStore = undefined;
this._threadMap = undefined;
}
}
export const globals = new Globals();