• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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 */
20export interface ObjectById<Class extends{id: string}> { [id: string]: Class; }
21
22export const SCROLLING_TRACK_GROUP = 'ScrollingTracks';
23
24export interface TrackState {
25  id: string;
26  engineId: string;
27  kind: string;
28  name: string;
29  trackGroup?: string;
30  dataReq?: TrackDataRequest;
31  config: {};
32}
33
34export interface TrackGroupState {
35  id: string;
36  engineId: string;
37  name: string;
38  collapsed: boolean;
39  tracks: string[];  // Child track ids.
40  summaryTrackId: string;
41}
42
43export interface TrackDataRequest {
44  start: number;
45  end: number;
46  resolution: number;
47}
48
49export interface EngineConfig {
50  id: string;
51  ready: boolean;
52  source: string|File;
53}
54
55export interface QueryConfig {
56  id: string;
57  engineId: string;
58  query: string;
59}
60
61export interface PermalinkConfig {
62  requestId?: string;  // Set by the frontend to request a new permalink.
63  hash?: string;       // Set by the controller when the link has been created.
64}
65
66export interface TraceTime {
67  startSec: number;
68  endSec: number;
69}
70
71export interface FrontendLocalState {
72  visibleTraceTime: TraceTime;
73  lastUpdate: number;  // Epoch in seconds (Date.now() / 1000).
74}
75
76export interface Status {
77  msg: string;
78  timestamp: number;  // Epoch in seconds (Date.now() / 1000).
79}
80
81export interface Note {
82  id: string;
83  timestamp: number;
84  color: string;
85  text: string;
86}
87
88export interface NoteSelection {
89  kind: 'NOTE';
90  id: string;
91}
92
93export interface SliceSelection {
94  kind: 'SLICE';
95  utid: number;
96  id: number;
97}
98
99export interface TimeSpanSelection {
100  kind: 'TIMESPAN';
101  startTs: number;
102  endTs: number;
103}
104
105export interface ThreadStateSelection {
106  kind: 'THREAD_STATE';
107  utid: number;
108  ts: number;
109  dur: number;
110  state: string;
111}
112
113type Selection =
114    NoteSelection|SliceSelection|TimeSpanSelection|ThreadStateSelection;
115
116export interface LogsPagination {
117  offset: number;
118  count: number;
119}
120
121export interface State {
122  route: string|null;
123  nextId: number;
124
125  /**
126   * State of the ConfigEditor.
127   */
128  recordConfig: RecordConfig;
129  displayConfigAsPbtxt: boolean;
130
131  /**
132   * Open traces.
133   */
134  engines: ObjectById<EngineConfig>;
135  traceTime: TraceTime;
136  trackGroups: ObjectById<TrackGroupState>;
137  tracks: ObjectById<TrackState>;
138  scrollingTracks: string[];
139  pinnedTracks: string[];
140  queries: ObjectById<QueryConfig>;
141  permalink: PermalinkConfig;
142  notes: ObjectById<Note>;
143  status: Status;
144  currentSelection: Selection|null;
145
146  logsPagination: LogsPagination;
147
148  /**
149   * This state is updated on the frontend at 60Hz and eventually syncronised to
150   * the controller at 10Hz. When the controller sends state updates to the
151   * frontend the frontend has special logic to pick whichever version of this
152   * key is most up to date.
153   */
154  frontendLocalState: FrontendLocalState;
155}
156
157export const defaultTraceTime = {
158  startSec: 0,
159  endSec: 10,
160};
161
162export declare type RecordMode =
163    'STOP_WHEN_FULL' | 'RING_BUFFER' | 'LONG_TRACE';
164
165export interface RecordConfig {
166  [key: string]: null|number|boolean|string|string[];
167
168  // Global settings
169  targetOS: string;  // 'Q','P','O' for Android, 'L' for Linux
170  mode: RecordMode;
171  durationMs: number;
172  bufferSizeMb: number;
173  maxFileSizeMb: number;      // Only for mode == 'LONG_TRACE'.
174  fileWritePeriodMs: number;  // Only for mode == 'LONG_TRACE'.
175
176  cpuSched: boolean;
177  cpuLatency: boolean;
178  cpuFreq: boolean;
179  cpuCoarse: boolean;
180  cpuCoarsePollMs: number;
181
182  ftrace: boolean;
183  atrace: boolean;
184  ftraceEvents: string[];
185  ftraceExtraEvents: string;
186  atraceCats: string[];
187  atraceApps: string;
188  ftraceBufferSizeKb: number;
189  ftraceDrainPeriodMs: number;
190  androidLogs: boolean;
191  androidLogBuffers: string[];
192
193  batteryDrain: boolean;
194  batteryDrainPollMs: number;
195
196  boardSensors: boolean;
197
198  memHiFreq: boolean;
199  memLmk: boolean;
200  meminfo: boolean;
201  meminfoPeriodMs: number;
202  meminfoCounters: string[];
203  vmstat: boolean;
204  vmstatPeriodMs: number;
205  vmstatCounters: string[];
206
207  procStats: boolean;
208  procStatsPeriodMs: number;
209}
210
211export function createEmptyRecordConfig(): RecordConfig {
212  return {
213    targetOS: 'Q',
214    mode: 'STOP_WHEN_FULL',
215    durationMs: 10000.0,
216    maxFileSizeMb: 100,
217    fileWritePeriodMs: 2500,
218    bufferSizeMb: 10.0,
219
220    cpuSched: false,
221    cpuLatency: false,
222    cpuFreq: false,
223
224    ftrace: false,
225    atrace: false,
226    ftraceEvents: [],
227    ftraceExtraEvents: '',
228    atraceCats: [],
229    atraceApps: '',
230    ftraceBufferSizeKb: 2 * 1024,
231    ftraceDrainPeriodMs: 250,
232    androidLogs: false,
233    androidLogBuffers: [],
234
235    cpuCoarse: false,
236    cpuCoarsePollMs: 1000,
237
238    batteryDrain: false,
239    batteryDrainPollMs: 1000,
240
241    boardSensors: false,
242
243    memHiFreq: false,
244    meminfo: false,
245    meminfoPeriodMs: 1000,
246    meminfoCounters: [],
247
248    vmstat: false,
249    vmstatPeriodMs: 1000,
250    vmstatCounters: [],
251
252    memLmk: false,
253    procStats: false,
254    procStatsPeriodMs: 1000,
255  };
256}
257
258export function createEmptyState(): State {
259  return {
260    route: null,
261    nextId: 0,
262    engines: {},
263    traceTime: {...defaultTraceTime},
264    tracks: {},
265    trackGroups: {},
266    pinnedTracks: [],
267    scrollingTracks: [],
268    queries: {},
269    permalink: {},
270    notes: {},
271
272    recordConfig: createEmptyRecordConfig(),
273    displayConfigAsPbtxt: false,
274
275    frontendLocalState: {
276      visibleTraceTime: {...defaultTraceTime},
277      lastUpdate: 0,
278    },
279
280    logsPagination: {
281      offset: 0,
282      count: 0,
283    },
284
285    status: {msg: '', timestamp: 0},
286    currentSelection: null,
287  };
288}
289