• 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 initTest = (metricData: Array<any>): ProcessInfoListItem => {
19    let processInfoListItems: Array<ProcessInfoItem> = [];
20    for (let index = 0; index < metricData.length; index++) {
21        let eventName = metricData[index].event_name;
22        let stat_type = metricData[index].stat_type;
23        let count = metricData[index].count;
24        let source = metricData[index].source;
25        let serverity = metricData[index].serverity;
26
27        let processInfoSource: ProcessInfoItem = {
28            // @ts-ignore
29            processName: eventName,
30            threads: {
31                // @ts-ignore
32                threadName: stat_type,
33                cpu: [{
34                    cpu: eventName,
35                    minFreq: stat_type,
36                    maxFreq: count,
37                    avgFrequency: source,
38                    duration: serverity,
39                }],
40            }
41        }
42        processInfoListItems?.push(processInfoSource)
43    }
44    return {
45        processInfo: processInfoListItems
46    }
47}
48
49export const initCpuStrategyData = (metricData: Array<any>): ProcessInfoListItem => {
50    info("Cpu Strategy data length is:", metricData.length)
51    let processInfoListItems: Array<ProcessInfoItem> = [];
52    if (metricData.length == 10) {
53
54    } else {
55
56    }
57    const splitChar: string = ','
58    for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) {
59        if (metricData[sqlIndex].avg_frequency == null) {
60            continue
61        }
62        let cpus = metricData[sqlIndex].cpu.split(splitChar);
63        let minFrequencies = metricData[sqlIndex].min_freq.split(splitChar);
64        let maxFrequencies = metricData[sqlIndex].max_freq.split(splitChar);
65        let avgFrequencies = metricData[sqlIndex].avg_frequency.split(splitChar);
66        let durations = metricData[sqlIndex].dur.split(splitChar);
67
68        let arrayCpu = [];
69        for (let index = 0; index < cpus.length; index++) {
70            let cpuIndex: CpuItem = {
71                cpu: cpus[index],
72                minFreq: minFrequencies[index],
73                maxFreq: maxFrequencies[index],
74                avgFrequency: avgFrequencies[index],
75                duration: durations[index],
76            }
77            arrayCpu.push(cpuIndex);
78        }
79        let processInfoSource: ProcessInfoItem = {
80            threads: {
81                cpu: arrayCpu,
82            }
83        }
84        processInfoListItems?.push(processInfoSource)
85    }
86    return {
87        processInfo: processInfoListItems
88    };
89}
90
91export interface ProcessInfoListItem {
92    processInfo: Array<ProcessInfoItem>
93}
94
95export interface ProcessInfoItem {
96    threads: ThreadsItem;
97}
98
99export interface ThreadsItem {
100    cpu: Array<CpuItem>;
101}
102
103export interface CpuItem {
104    cpu: string;
105    minFreq: string;
106    maxFreq: string;
107    avgFrequency: string;
108    duration: string;
109}
110