• 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 initMemoryAggStrategy = (metricData: Array<any>): ProcessValuesListItem => {
19    info("Memory Agg Strategy data length is:", metricData.length)
20    let processValuesListItems: Array<ProcessValuesItem> = []
21    const splitChar: string = ','
22    for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) {
23        let processNames = metricData[sqlIndex].processName;
24        let processInfoSource: ProcessValuesItem = {
25            processName: processNames,
26        }
27        if (metricData[sqlIndex].name == null) {
28            let values = metricData[sqlIndex].value.split(splitChar);
29            let times = metricData[sqlIndex].ts.split(splitChar);
30            let oomScoreValue = 0;
31            for (let index = 0; index < values.length; index++) {
32                if (!processInfoSource) continue
33                processValuesListItems?.push(processInfoSource)
34            }
35        } else {
36            let names = metricData[sqlIndex].name.split(splitChar);
37            let values = metricData[sqlIndex].value.split(splitChar);
38            let times = metricData[sqlIndex].ts.split(splitChar);
39            let oomScoreValue = 0;
40            for (let indexScore = 0; indexScore < names.length; indexScore++) {
41                if ("oom_score_adj" === names[indexScore]) {
42                    oomScoreValue = values[indexScore];
43                    break;
44                }
45            }
46            for (let index = 0; index < names.length; index++) {
47                let typeItem: TypeItem = {
48                    ts: times[index],
49                    oom_score: oomScoreValue,
50                    value: values[index],
51                }
52                if (!processInfoSource) continue
53                if ("mem.rss.anon" === names[index]) {
54                    processInfoSource.anonRss = typeItem
55                }
56                if ("mem.swap" === names[index]) {
57                    processInfoSource.swap = typeItem
58                }
59                if ("mem.rss.file" === names[index]) {
60                    processInfoSource.fileRss = typeItem
61                }
62                if ("oom_score_adj" === names[index]) {
63                    processInfoSource.anonAndSwap = typeItem
64                }
65            }
66        }
67        processValuesListItems?.push(processInfoSource)
68    }
69    return {
70        processValues: processValuesListItems
71    }
72}
73
74export interface ProcessValuesListItem {
75    processValues: Array<ProcessValuesItem>
76}
77
78export interface ProcessValuesItem {
79    processName: string;
80    anonRss?: TypeItem;
81    swap?: TypeItem;
82    fileRss?: TypeItem;
83    anonAndSwap?: TypeItem;
84}
85
86export interface TypeItem {
87    ts: number;
88    oom_score: number;
89    value: number;
90}
91