• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2021 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
15import {createEmptyRecordConfig} from '../controller/record_config_types';
16import {
17  autosaveConfigStore,
18  recordTargetStore
19} from '../frontend/record_config';
20
21import {featureFlags} from './feature_flags';
22import {defaultTraceTime, State, STATE_VERSION} from './state';
23
24const AUTOLOAD_STARTED_CONFIG_FLAG = featureFlags.register({
25  id: 'autoloadStartedConfig',
26  name: 'Auto-load last used recording config',
27  description: 'Starting a recording automatically saves its configuration. ' +
28      'This flag controls whether this config is automatically loaded.',
29  defaultValue: true,
30});
31
32export function createEmptyState(): State {
33  return {
34    version: STATE_VERSION,
35    nextId: 0,
36    nextNoteId: 1,  // 0 is reserved for ephemeral area marking.
37    nextAreaId: 0,
38    newEngineMode: 'USE_HTTP_RPC_IF_AVAILABLE',
39    engines: {},
40    traceTime: {...defaultTraceTime},
41    tracks: {},
42    uiTrackIdByTraceTrackId: {},
43    aggregatePreferences: {},
44    trackGroups: {},
45    visibleTracks: [],
46    pinnedTracks: [],
47    scrollingTracks: [],
48    areas: {},
49    queries: {},
50    metrics: {},
51    permalink: {},
52    notes: {},
53    pivotTableConfig: {},
54    pivotTable: {},
55
56    recordConfig: AUTOLOAD_STARTED_CONFIG_FLAG.get() ?
57        autosaveConfigStore.get() :
58        createEmptyRecordConfig(),
59    displayConfigAsPbtxt: false,
60    lastLoadedConfig: {type: 'NONE'},
61
62    frontendLocalState: {
63      omniboxState: {
64        lastUpdate: 0,
65        omnibox: '',
66        mode: 'SEARCH',
67      },
68
69      visibleState: {
70        ...defaultTraceTime,
71        lastUpdate: 0,
72        resolution: 0,
73      },
74    },
75
76    logsPagination: {
77      offset: 0,
78      count: 0,
79    },
80
81    status: {msg: '', timestamp: 0},
82    currentSelection: null,
83    currentFlamegraphState: null,
84    traceConversionInProgress: false,
85
86    perfDebug: false,
87    sidebarVisible: true,
88    hoveredUtid: -1,
89    hoveredPid: -1,
90    hoveredLogsTimestamp: -1,
91    hoveredNoteTimestamp: -1,
92    highlightedSliceId: -1,
93    focusedFlowIdLeft: -1,
94    focusedFlowIdRight: -1,
95    searchIndex: -1,
96
97    recordingInProgress: false,
98    recordingCancelled: false,
99    extensionInstalled: false,
100    flamegraphModalDismissed: false,
101    recordingTarget: recordTargetStore.getValidTarget(),
102    availableAdbDevices: [],
103
104    fetchChromeCategories: false,
105    chromeCategories: undefined,
106    pivotTableRedux:
107        {selectionArea: null, query: null, queryId: 0, queryResult: null},
108  };
109}