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