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 initTraceTaskStrategy = (metricData: Array<{ 19 id: string; 20 pid: string; 21 process_name: string; 22 thread_name: string; 23}>): ProcessListItem => { 24 info('Trace Task Strategy data length is:', metricData.length); 25 let statListItems = []; 26 for (let sqlIndex = 0; sqlIndex < metricData.length; sqlIndex++) { 27 let pidList = metricData[sqlIndex].pid; 28 let processNameList = metricData[sqlIndex].process_name; 29 let threadNameList = metricData[sqlIndex].thread_name; 30 let threadNames = []; 31 let newArr = ''; 32 if (threadNameList !== null) { 33 threadNames = threadNameList.split(','); 34 newArr = threadNames.reduce((prev: any, item: any) => (prev.includes(item) ? prev : prev.concat(item)), []); 35 } 36 37 let statListItem = { 38 pid: pidList, 39 processName: processNameList, 40 threadName: newArr, 41 }; 42 statListItems?.push(statListItem); 43 } 44 return { 45 process: statListItems, 46 }; 47}; 48 49export interface ProcessListItem { 50 process: Array<any>; 51} 52 53export interface ProcessItem { 54 pid: string; 55 processName: string; 56 threadName: string; 57} 58