• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2021 Huawei Device Co., Ltd.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14import { TraficEnum } from './utils/QueryEnum';
15import {filterDataByGroup} from "./utils/DataFilter";
16import {lrqList} from "./utils/AllMemoryCache";
17
18export const chartIrqDataSql = (args: any): string => {
19  if (args.name === 'irq') {
20    return `
21        select i.ts - ${
22          args.recordStartNS
23        }                                                                                                   as startNs,
24               max(i.dur)                                                                                       as dur,
25               i.depth,
26               ifnull(argsetid, -1)                                                                         as argSetId,
27               i.id,
28               case when i.cat = 'ipi' then 'IPI' || i.name else i.name end                                 as name,
29               ((i.ts - ${args.recordStartNS}) / (${Math.floor((args.endNS - args.startNS) / args.width)})) as px
30        from irq i
31        where i.callid = ${args.cpu}
32          and ((i.cat = 'irq' and i.flag = '1') or i.cat = 'ipi')
33          and startNs + dur >= ${Math.floor(args.startNS)}
34          and startNs <= ${Math.floor(args.endNS)}
35        group by px;
36    `;
37  } else {
38    return `
39        select i.ts - ${args.recordStartNS}                                                                 as startNs,
40               max(i.dur)                                                                                       as dur,
41               i.depth,
42               ifnull(argsetid,-1)                                                                            as argSetId,
43               i.id,
44               i.name,
45               ((i.ts - ${args.recordStartNS}) / (${Math.floor((args.endNS - args.startNS) / args.width)})) as px
46        from irq i
47        where i.callid = ${args.cpu}
48          and i.cat = 'softirq'
49          and startNs + dur >= ${Math.floor(args.startNS)}
50          and startNs <= ${Math.floor(args.endNS)}
51        group by px;
52    `;
53  }
54};
55
56export const chartIrqDataSqlMem = (args: any): string => {
57  if (args.name === 'irq') {
58    return `
59        select i.ts - t.start_ts as startNs,i.dur,
60        case when i.cat = 'ipi' then 'IPI' || i.name else i.name end as name,
61        i.depth,
62        ifnull(argsetid, -1) as argSetId,
63        i.id
64        from irq i,trace_range t
65        where i.callid = ${args.cpu} and ((i.cat = 'irq' and i.flag ='1') or i.cat = 'ipi')
66    `;
67  } else {
68    return `
69        select i.ts - t.start_ts as startNs,i.dur,i.name,i.depth,ifnull(argsetid, -1) as argSetId,i.id from irq i,
70trace_range t where i.callid = ${args.cpu} and i.cat = 'softirq'
71    `;
72  }
73};
74
75export function irqDataReceiver(data: any, proc: Function): void {
76  if (data.params.trafic === TraficEnum.Memory) {
77    let res: any[], list: any[];
78    if (!lrqList.has(data.params.cpu + data.params.name)) {
79      list = proc(chartIrqDataSqlMem(data.params));
80      lrqList.set(data.params.cpu + data.params.name, list);
81    } else {
82      list = lrqList.get(data.params.cpu + data.params.name) || [];
83    }
84    res = filterDataByGroup(list || [], 'startNs', 'dur', data.params.startNS, data.params.endNS, data.params.width);
85    arrayBufferHandler(data, res,true);
86  } else {
87    let sql = chartIrqDataSql(data.params);
88    let res = proc(sql);
89    arrayBufferHandler(data, res,data.params.trafic !== TraficEnum.SharedArrayBuffer);
90  }
91}
92
93function arrayBufferHandler(data: any, res: any[], transfer: boolean): void {
94  let startNS = new Float64Array(transfer ? res.length : data.params.sharedArrayBuffers.startNS);
95  let dur = new Float64Array(transfer ? res.length : data.params.sharedArrayBuffers.dur);
96  let depth = new Uint32Array(transfer ? res.length : data.params.sharedArrayBuffers.depth);
97  let argSetId = new Int32Array(transfer ? res.length : data.params.sharedArrayBuffers.argSetId);
98  let id = new Uint32Array(transfer ? res.length : data.params.sharedArrayBuffers.id);
99  res.forEach((it, i) => {
100    data.params.trafic === TraficEnum.ProtoBuffer && (it = it.irqData);
101    startNS[i] = it.startNs;
102    dur[i] = it.dur;
103    depth[i] = it.depth;
104    argSetId[i] = it.argSetId;
105    id[i] = it.id;
106  });
107  (self as unknown as Worker).postMessage(
108    {
109      id: data.id,
110      action: data.action,
111      results: transfer
112        ? {
113            startNS: startNS.buffer,
114            dur: dur.buffer,
115            depth: depth.buffer,
116            argSetId: argSetId.buffer,
117            id: id.buffer,
118          }
119        : {},
120      len: res.length,
121      transfer: transfer,
122    },
123    transfer ? [startNS.buffer, dur.buffer, depth.buffer, argSetId.buffer, id.buffer] : []
124  );
125}
126