• 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 {Actions} from '../common/actions';
16import {AggregateData} from '../common/aggregation_data';
17import {ConversionJobStatusUpdate} from '../common/conversion_jobs';
18import {MetricResult} from '../common/metric_data';
19import {CurrentSearchResults, SearchSummary} from '../common/search_data';
20import {raf} from '../core/raf_scheduler';
21import {HttpRpcState} from '../trace_processor/http_rpc_engine';
22import {getLegacySelection} from '../common/state';
23
24import {
25  CpuProfileDetails,
26  Flow,
27  globals,
28  QuantizedLoad,
29  SliceDetails,
30  ThreadDesc,
31  ThreadStateDetails,
32  TraceContext,
33} from './globals';
34import {findCurrentSelection} from './keyboard_event_handler';
35
36export function publishOverviewData(data: {
37  [key: string]: QuantizedLoad | QuantizedLoad[];
38}) {
39  for (const [key, value] of Object.entries(data)) {
40    if (!globals.overviewStore.has(key)) {
41      globals.overviewStore.set(key, []);
42    }
43    if (value instanceof Array) {
44      globals.overviewStore.get(key)!.push(...value);
45    } else {
46      globals.overviewStore.get(key)!.push(value);
47    }
48  }
49  raf.scheduleRedraw();
50}
51
52export function clearOverviewData() {
53  globals.overviewStore.clear();
54  raf.scheduleRedraw();
55}
56
57export function publishTrackData(args: {id: string; data: {}}) {
58  globals.setTrackData(args.id, args.data);
59  raf.scheduleRedraw();
60}
61
62export function publishMetricResult(metricResult: MetricResult) {
63  globals.setMetricResult(metricResult);
64  globals.publishRedraw();
65}
66
67export function publishSelectedFlows(selectedFlows: Flow[]) {
68  globals.selectedFlows = selectedFlows;
69  globals.publishRedraw();
70}
71
72export function publishHttpRpcState(httpRpcState: HttpRpcState) {
73  globals.httpRpcState = httpRpcState;
74  raf.scheduleFullRedraw();
75}
76
77export function publishCpuProfileDetails(details: CpuProfileDetails) {
78  globals.cpuProfileDetails = details;
79  globals.publishRedraw();
80}
81
82export function publishHasFtrace(value: boolean): void {
83  globals.hasFtrace = value;
84  globals.publishRedraw();
85}
86
87export function publishTraceContext(details: TraceContext): void {
88  globals.traceContext = details;
89  globals.publishRedraw();
90}
91
92export function publishConversionJobStatusUpdate(
93  job: ConversionJobStatusUpdate,
94) {
95  globals.setConversionJobStatus(job.jobName, job.jobStatus);
96  globals.publishRedraw();
97}
98
99export function publishLoading(numQueuedQueries: number) {
100  globals.numQueuedQueries = numQueuedQueries;
101  // TODO(hjd): Clean up loadingAnimation given that this now causes a full
102  // redraw anyways. Also this should probably just go via the global state.
103  raf.scheduleFullRedraw();
104}
105
106export function publishBufferUsage(args: {percentage: number}) {
107  globals.setBufferUsage(args.percentage);
108  globals.publishRedraw();
109}
110
111export function publishSearch(args: SearchSummary) {
112  globals.searchSummary = args;
113  globals.publishRedraw();
114}
115
116export function publishSearchResult(args: CurrentSearchResults) {
117  globals.currentSearchResults = args;
118  globals.publishRedraw();
119}
120
121export function publishRecordingLog(args: {logs: string}) {
122  globals.setRecordingLog(args.logs);
123  globals.publishRedraw();
124}
125
126export function publishTraceErrors(numErrors: number) {
127  globals.setTraceErrors(numErrors);
128  globals.publishRedraw();
129}
130
131export function publishMetricError(error: string) {
132  globals.setMetricError(error);
133  globals.publishRedraw();
134}
135
136export function publishAggregateData(args: {
137  data: AggregateData;
138  kind: string;
139}) {
140  globals.setAggregateData(args.kind, args.data);
141  globals.publishRedraw();
142}
143
144export function publishQueryResult(args: {id: string; data?: {}}) {
145  globals.queryResults.set(args.id, args.data);
146  globals.publishRedraw();
147}
148
149export function publishThreads(data: ThreadDesc[]) {
150  globals.threads.clear();
151  data.forEach((thread) => {
152    globals.threads.set(thread.utid, thread);
153  });
154  globals.publishRedraw();
155}
156
157export function publishSliceDetails(click: SliceDetails) {
158  globals.sliceDetails = click;
159  const id = click.id;
160  if (id !== undefined && id === globals.state.pendingScrollId) {
161    findCurrentSelection();
162    globals.dispatch(Actions.clearPendingScrollId({id: undefined}));
163  }
164  globals.publishRedraw();
165}
166
167export function publishThreadStateDetails(click: ThreadStateDetails) {
168  globals.threadStateDetails = click;
169  globals.publishRedraw();
170}
171
172export function publishConnectedFlows(connectedFlows: Flow[]) {
173  globals.connectedFlows = connectedFlows;
174  // If a chrome slice is selected and we have any flows in connectedFlows
175  // we will find the flows on the right and left of that slice to set a default
176  // focus. In all other cases the focusedFlowId(Left|Right) will be set to -1.
177  globals.dispatch(Actions.setHighlightedFlowLeftId({flowId: -1}));
178  globals.dispatch(Actions.setHighlightedFlowRightId({flowId: -1}));
179  const currentSelection = getLegacySelection(globals.state);
180  if (currentSelection?.kind === 'SLICE') {
181    const sliceId = currentSelection.id;
182    for (const flow of globals.connectedFlows) {
183      if (flow.begin.sliceId === sliceId) {
184        globals.dispatch(Actions.setHighlightedFlowRightId({flowId: flow.id}));
185      }
186      if (flow.end.sliceId === sliceId) {
187        globals.dispatch(Actions.setHighlightedFlowLeftId({flowId: flow.id}));
188      }
189    }
190  }
191
192  globals.publishRedraw();
193}
194
195export function publishShowPanningHint() {
196  globals.showPanningHint = true;
197  globals.publishRedraw();
198}
199
200export function publishPermalinkHash(hash: string | undefined): void {
201  globals.permalinkHash = hash;
202  globals.publishRedraw();
203}
204