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 { Utils } from '../../trace/base/Utils.js'; 17 18export const getFormatData = (data: Array<any>) => { 19 let arrData: Array<any> = []; 20 data.forEach((item, idx) => { 21 arrData.push({ 22 index: idx + 1, 23 ...item, 24 avg: Utils.getProbablyTime(item.avg), 25 max: Utils.getProbablyTime(item.max), 26 min: Utils.getProbablyTime(item.min), 27 sum: Utils.getProbablyTime(item.sum), 28 }); 29 }); 30 return arrData; 31}; 32 33export const getDataNo = (data: Array<any>) => { 34 let arrData: Array<any> = []; 35 data.forEach((item, idx) => { 36 arrData.push({ 37 index: idx + 1, 38 ...item, 39 }); 40 }); 41 return arrData; 42}; 43 44export const getInitializeTime = (ns: string) => { 45 let hour1 = 3600_000_000_000; 46 let minute1 = 60_000_000_000; 47 let second1 = 1_000_000_000; 48 let millisecond1 = 1_000_000; 49 let microsecond1 = 1_000; 50 51 let res = ''; 52 let currentNs = ns; 53 if (currentNs.indexOf('h') != -1) { 54 res += Number(currentNs.slice(0, currentNs.length - 1)) * hour1; 55 } else if (currentNs.indexOf('m') != -1) { 56 res += Number(currentNs.slice(0, currentNs.length - 1)) * minute1; 57 } else if (currentNs.indexOf('s') != -1) { 58 res += Number(currentNs.slice(0, currentNs.length - 1)) * second1; 59 } else if (currentNs.indexOf('ms') != -1) { 60 res += Number(currentNs.slice(0, currentNs.length - 2)) * millisecond1; 61 } else if (currentNs.indexOf('μs') != -1) { 62 res += Number(currentNs.slice(0, currentNs.length - 2)) * microsecond1; 63 } else { 64 res += Number(currentNs); 65 } 66 return res; 67}; 68