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