• 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 initCpuStrategyData = (metricData: Array<{
19  tid: string;
20  pid: string;
21  cpu: string;
22  dur: string;
23  min_freq: string;
24  max_freq: string;
25  avg_frequency: string;
26}>): ProcessInfoListItem => {
27  info('Cpu Strategy data length is:', metricData.length);
28  let processInfoListItems: Array<ProcessInfoItem> = [];
29  if (metricData.length == 10) {
30  } else {
31  }
32  const splitChar: string = ',';
33  for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) {
34    if (metricData[sqlIndex].avg_frequency == null) {
35      continue;
36    }
37    let cpus = metricData[sqlIndex].cpu.split(splitChar);
38    let minFrequencies = metricData[sqlIndex].min_freq.split(splitChar);
39    let maxFrequencies = metricData[sqlIndex].max_freq.split(splitChar);
40    let avgFrequencies = metricData[sqlIndex].avg_frequency.split(splitChar);
41    let durations = metricData[sqlIndex].dur.split(splitChar);
42
43    let arrayCpu = [];
44    for (let index = 0; index < cpus.length; index++) {
45      let cpuIndex: CpuItem = {
46        cpu: cpus[index],
47        minFreq: minFrequencies[index],
48        maxFreq: maxFrequencies[index],
49        avgFrequency: avgFrequencies[index],
50        duration: durations[index],
51      };
52      arrayCpu.push(cpuIndex);
53    }
54    let processInfoSource: ProcessInfoItem = {
55      threads: {
56        cpu: arrayCpu,
57      },
58    };
59    processInfoListItems?.push(processInfoSource);
60  }
61  return {
62    processInfo: processInfoListItems,
63  };
64};
65
66export interface ProcessInfoListItem {
67  processInfo: Array<ProcessInfoItem>;
68}
69
70export interface ProcessInfoItem {
71  threads: ThreadsItem;
72}
73
74export interface ThreadsItem {
75  cpu: Array<CpuItem>;
76}
77
78export interface CpuItem {
79  cpu: string;
80  minFreq: string;
81  maxFreq: string;
82  avgFrequency: string;
83  duration: string;
84}
85