• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 */
15
16import {info} from "../../../log/Log.js";
17
18export const initDistributedTermData = (metricData: Array<any>): DistributedTermListItem => {
19    info("Distributed Term data length is:", metricData.length)
20    let distributedTermListItems: Array<DistributedTermItem> = []
21    const splitChar = ','
22    for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) {
23        let threadIdsList = metricData[sqlIndex].threadId.split(splitChar);
24        let threadNamesList = metricData[sqlIndex].threadName.split(splitChar);
25        let processIdList = metricData[sqlIndex].processId.split(splitChar);
26        let processNameList = metricData[sqlIndex].processName === null ? threadIdsList.length + '' : metricData[sqlIndex].processName.split(splitChar);
27
28        let funNameList = metricData[sqlIndex].funName.split(splitChar);
29        let timeList = metricData[sqlIndex].ts.split(splitChar);
30        let durList = metricData[sqlIndex].dur.split(splitChar);
31        let flag = metricData[sqlIndex].flag;
32        let flagList = flag.split(splitChar);
33        let traceNameList = metricData[sqlIndex].trace_name;
34        let chainIdList = metricData[sqlIndex].chainId;
35        let spanIdList = metricData[sqlIndex].spanId;
36        let parentSpanIdList = metricData[sqlIndex].parentSpanId;
37
38        let distributedTermListItem: DistributedTermItem = {}
39        for (let index = 0; index < flagList.length; index++) {
40            let across: boolean = true;
41            let receiverTime: number = 0;
42            let senderTime: number = 0;
43            let delay: number = 0;
44            if (flag.indexOf('S,C') > -1 || flag.indexOf('C,S') > -1) {
45                across = false;
46                if (flagList[index] == 'S') receiverTime = timeList[index]
47                if (flagList[index] == 'C') senderTime = timeList[index]
48                delay = receiverTime - senderTime;
49            }
50
51            let type = {
52                acrossTheDevice: across,
53                traceName: traceNameList,
54                traceId: {
55                    chainID: chainIdList,
56                    spanID: spanIdList,
57                    parentSpanID: parentSpanIdList,
58                },
59                functionName: funNameList[index],
60                processInfo: {
61                    processId: processIdList[index],
62                    processName: processNameList[index],
63                },
64                threadInfoItem: {
65                    threadId: threadIdsList[index],
66                    threadName: threadNamesList[index],
67                },
68                dur: durList[index],
69                delay: delay,
70            }
71            if ("C" == flagList[index]) {
72                distributedTermListItem.sender = type
73            } else {
74                distributedTermListItem.receiver = type
75            }
76        }
77        distributedTermListItems?.push(distributedTermListItem)
78    }
79    return {
80        distributedTermItem: distributedTermListItems
81    }
82}
83
84export interface DistributedTermListItem {
85    distributedTermItem: Array<DistributedTermItem>
86}
87
88export interface DistributedTermItem {
89    sender?: SenderOrReceiverItem;
90    receiver?: SenderOrReceiverItem;
91}
92
93export interface SenderOrReceiverItem {
94    acrossTheDevice?: boolean
95    traceName: string
96    traceId: TraceIdItem
97    functionName: string
98    processInfo: ProcessInfoItem
99    threadInfoItem: ThreadInfoItem
100    dur: string
101    delay: number
102}
103
104export interface TraceIdItem {
105    chainID: string
106    spanID: string
107    parentSpanID: string
108}
109
110export interface ProcessInfoItem {
111    processId: string
112    processName: string
113}
114
115export interface ThreadInfoItem {
116    threadId: string
117    threadName: string
118}
119