• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2021, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {nanos_to_string, transform} from './transform.js'
18
19function transform_change(change_data) {
20  const kind = change_data.__proto__.$type.name;
21  const name = change_data.layerId || change_data.id;
22  return transform({
23    kind: kind,
24    name: name,
25    stableId: kind + name,
26    obj: change_data,
27    children: [],
28    isVisible: true,
29  });
30}
31
32function transform_transaction_state(transaction_state) {
33  const obj = Object.assign({}, transaction_state)
34  if (obj.displayChanges) delete obj.displayChanges;
35  if (obj.layerChanges) delete obj.layerChanges;
36  const stableId = 'pid=' + transaction_state.pid +
37  ' uid=' + transaction_state.uid +
38  ' postTime=' + transaction_state.postTime;
39  return transform({
40    kind: 'TransactionState',
41    name: stableId,
42    stableId: stableId,
43    obj: obj,
44    children: [
45      [
46        [...transaction_state.layerChanges, ...transaction_state.displayChanges],
47        transform_change]
48      ]
49  });
50}
51
52function transform_transaction_trace_entry(entry) {
53  const obj = Object.assign({}, entry)
54  if (obj.transactions) delete obj.transactions;
55
56  return transform({
57    obj: obj,
58    kind: 'entry',
59    stableId: 'entry',
60    timestamp: entry.elapsedRealtimeNanos,
61    name: nanos_to_string(entry.elapsedRealtimeNanos),
62    children: [
63      [entry.transactions, transform_transaction_state]
64    ],
65  });
66}
67
68function transform_transaction_trace(trace) {
69  const data = trace.entry.map((entry) => transform_transaction_trace_entry(entry));
70  return {children: data};
71}
72
73export {transform_transaction_trace};
74