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 { PerfCall, PerfFile } from '../../bean/PerfProfile'; 17import { info } from '../../../log/Log'; 18import { SpHiPerf } from './SpHiPerf'; 19import { procedurePool } from '../../database/Procedure'; 20import { SpSystemTrace } from '../SpSystemTrace'; 21import {queryPerfFiles} from "../../database/sql/Perf.sql"; 22 23export class PerfDataQuery { 24 filesData: any = {}; 25 callChainMap: Map<number, PerfCall> = new Map<number, PerfCall>(); 26 27 async initPerfCache() { 28 await this.initPerfCallChainMap(); 29 await this.initPerfFiles(); 30 } 31 32 async initPerfCallChainMap() { 33 this.callChainMap.clear(); 34 } 35 36 async initPerfFiles() { 37 let files = await queryPerfFiles(); 38 info('PerfFiles Data size is: ', files!.length); 39 files.forEach((file) => { 40 this.filesData[file.fileId] = this.filesData[file.fileId] || []; 41 PerfFile.setFileName(file); 42 this.filesData[file.fileId].push(file); 43 }); 44 const data = { 45 fValue: SpHiPerf.stringResult?.fValue, 46 }; 47 let results = await new Promise<any>((resolve, reject) => { 48 procedurePool.submitWithName('logic0', 'perf-init', data, undefined, (res: any) => { 49 resolve(res); 50 }); 51 }); 52 this.callChainMap = results as any; 53 info('Perf Files Data initialized'); 54 } 55 56 getLibName(fileId: number, symbolId: number) { 57 let name = 'unknown'; 58 if (symbolId == -1) { 59 if (this.filesData[fileId] && this.filesData[fileId].length > 0) { 60 name = this.filesData[fileId][0].fileName; 61 } 62 } else { 63 if (this.filesData[fileId] && this.filesData[fileId].length > symbolId) { 64 name = this.filesData[fileId][symbolId].fileName; 65 } 66 } 67 return name.replace(/</g, '<').replace(/>/g, '>'); 68 } 69} 70 71export const perfDataQuery = new PerfDataQuery(); 72