• 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 
16 import { queryPerfFiles } from '../../database/SqlLite.js';
17 import { PerfCall, PerfFile } from '../../bean/PerfProfile.js';
18 import { info } from '../../../log/Log.js';
19 import { SpHiPerf } from './SpHiPerf.js';
20 import { procedurePool } from '../../database/Procedure.js';
21 
22 export class PerfDataQuery {
23   filesData: any = {};
24   callChainMap: Map<number, PerfCall> = new Map<number, PerfCall>();
25 
26   async initPerfCache() {
27     await this.initPerfCallChainMap();
28     await this.initPerfFiles();
29   }
30 
31   async initPerfCallChainMap() {
32     this.callChainMap.clear();
33   }
34 
35   async initPerfFiles() {
36     let files = await queryPerfFiles();
37     info('PerfFiles Data size is: ', files!.length);
38     files.forEach((file) => {
39       this.filesData[file.fileId] = this.filesData[file.fileId] || [];
40       PerfFile.setFileName(file);
41       this.filesData[file.fileId].push(file);
42     });
43     let results = await new Promise<any>((resolve, reject) => {
44       procedurePool.submitWithName('logic0', 'perf-init', SpHiPerf.stringResult, undefined, (res: any) => {
45         resolve(res);
46       });
47     });
48     this.callChainMap = results as any;
49     info('Perf Files Data initialized');
50   }
51 }
52 
53 export const perfDataQuery = new PerfDataQuery();
54