• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
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 { LitTable, RedrawTreeForm } from '../../../../../base-ui/table/lit-table';
16
17//并行度逻辑处理
18export function HanldParalLogic(
19    func: (dumpObj: unknown, value?: unknown, param?: unknown) => unknown,
20    value: unknown,
21    param?: unknown): unknown {
22    // @ts-ignore
23    let arr = value.stateItem;
24    let waitArr: unknown = [];
25    let globalTs: number = 0;
26    let index: number = 0;
27    // @ts-ignore
28    while (index < arr.length) {
29        // @ts-ignore
30        let minEndTs = Math.min(...waitArr.map((item: unknown) => item.endTs));
31        // @ts-ignore
32        let minIndex = waitArr.findIndex((item: unknown) => item.endTs === minEndTs);
33        //当waitArr为空时
34        // @ts-ignore
35        if (waitArr.length === 0) {
36            globalTs = arr[index].ts;
37            // @ts-ignore
38            waitArr.push(arr[index]);
39            index++;
40            continue;
41        }
42        //当全局Ts等于minEndTs时,只做删除处理
43        if (globalTs === minEndTs) {
44            // @ts-ignore
45            if (minIndex !== -1) { waitArr.splice(minIndex, 1) };
46            index++;
47            continue;
48        }
49        let list = JSON.parse(JSON.stringify(waitArr));
50        let dumpObj = {
51            ts: 0,
52            endTs: 0,
53            listSlice: [],
54            len: 0
55        };
56        //判断原队列的数据是否被用完,即是否为空
57        if (index < arr.length) {
58            if (arr[index].ts < minEndTs) {
59                if (globalTs === arr[index].ts) {
60                    // @ts-ignore
61                    waitArr.push(arr[index]);
62                    index++;
63                    continue;
64                } else {
65                    dumpObj = {
66                        ts: globalTs,
67                        endTs: arr[index].ts,
68                        listSlice: list,
69                        len: list.length
70                    };
71                    // @ts-ignore
72                    waitArr.push(arr[index]);
73                    globalTs = arr[index].ts;
74                    index++;
75                }
76            } else if (arr[index].ts >= minEndTs) {
77                dumpObj = {
78                    ts: globalTs,
79                    endTs: minEndTs,
80                    listSlice: list,
81                    len: list.length
82                };
83                globalTs = minEndTs;
84                // @ts-ignore
85                if (minIndex !== -1) { waitArr.splice(minIndex, 1) };
86                index++;
87            }
88        } else {
89            dumpObj = {
90                ts: globalTs,
91                endTs: minEndTs,
92                listSlice: list,
93                len: list.length
94            };
95            globalTs = minEndTs;
96            // @ts-ignore
97            if (minIndex !== -1) { waitArr.splice(minIndex, 1) };
98            index++;
99        }
100        param = func(dumpObj, value, param);
101    }
102    return param;
103}
104
105//表头点击事件
106export function MeterHeaderClick(tab: LitTable | null | undefined, data: Array<unknown>): void {
107    let labels = tab?.shadowRoot
108        ?.querySelector('.th > .td')!
109        .querySelectorAll('label');
110    if (labels) {
111        for (let i = 0; i < labels.length; i++) {
112            let label = labels[i].innerHTML;
113            labels[i].addEventListener('click', (e) => {
114                if (label.includes('Process') && i === 0) {
115                    tab!.setStatus(data, false);
116                    tab!.recycleDs =
117                        tab!.meauseTreeRowElement(
118                            data,
119                            RedrawTreeForm.Retract
120                        );
121                } else if (label.includes('Core') && i === 1) {
122                    tab!.setStatus(data, true);
123                    tab!.recycleDs =
124                        tab!.meauseTreeRowElement(
125                            data,
126                            RedrawTreeForm.Expand
127                        );
128                }
129            });
130        }
131    }
132}