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 initSysCallsTopStrategy = (metricData: Array<{ 19 tid: string; 20 pid: string; 21 funName: string; 22 frequency: string; 23 minDur: number; 24 maxDur: number; 25 avgDur: number; 26}>): ProcessInfoListItem => { 27 info('System Calls Strategy data length is:', metricData.length); 28 let ProcessInfoListItems: Array<ProcessInfoItem> = []; 29 30 for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) { 31 let pidList = metricData[sqlIndex].pid; 32 let tidList = metricData[sqlIndex].tid; 33 let functionNames = metricData[sqlIndex].funName; 34 let durMaxes = metricData[sqlIndex].maxDur; 35 let durMines = metricData[sqlIndex].minDur < 0 ? 0 : metricData[sqlIndex].minDur; 36 let durAvgs = Math.floor(metricData[sqlIndex].avgDur); 37 38 let processInfoItem: ProcessInfoItem = { 39 pid: pidList, 40 threads: { 41 tid: tidList, 42 function: { 43 functionName: functionNames, 44 durMax: durMaxes, 45 durMin: durMines, 46 durAvg: durAvgs, 47 }, 48 }, 49 }; 50 ProcessInfoListItems?.push(processInfoItem); 51 } 52 return { 53 processInfo: ProcessInfoListItems, 54 }; 55}; 56 57export interface ProcessInfoListItem { 58 processInfo: Array<ProcessInfoItem>; 59} 60 61export interface ProcessInfoItem { 62 pid: string; 63 threads: ThreadsItem; 64} 65 66export interface ThreadsItem { 67 tid: string; 68 function: FunctionItem; 69} 70 71export interface FunctionItem { 72 functionName: string; 73 durMax: number; 74 durMin: number; 75 durAvg: number; 76} 77