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 { ProcedureLogicWorkerPerf } from './ProcedureLogicWorkerPerf'; 17import { ProcedureLogicWorkerNativeMemory } from './ProcedureLogicWorkerNativeNemory'; 18import { ProcedureLogicWorkerFileSystem } from './ProcedureLogicWorkerFileSystem'; 19import { ProcedureLogicWorkerSPT } from './ProcedureLogicWorkerSPT'; 20import { ProcedureLogicWorkerCpuState } from './ProcedureLogicWorkerCpuState'; 21import { ProcedureLogicWorkerSchedulingAnalysis } from './ProcedureLogicWorkerSchedulingAnalysis'; 22import { DataCache } from './ProcedureLogicWorkerCommon'; 23import { ProcedureLogicWorkerJsCpuProfiler } from './ProcedureLogicWorkerJsCpuProfiler'; 24 25let logicWorker: any = { 26 perf: new ProcedureLogicWorkerPerf(), 27 'native-memory': new ProcedureLogicWorkerNativeMemory(), 28 fileSystem: new ProcedureLogicWorkerFileSystem(), 29 CpuState: new ProcedureLogicWorkerCpuState(), 30 spt: new ProcedureLogicWorkerSPT(), 31 scheduling: new ProcedureLogicWorkerSchedulingAnalysis(), 32 jsCpuProfile: new ProcedureLogicWorkerJsCpuProfiler(), 33}; 34 35function match(req: any) { 36 if (req.type === 'clear') { 37 Reflect.ownKeys(logicWorker).forEach((key) => logicWorker[key].clearAll()); 38 DataCache.getInstance().clearAll(); 39 return; 40 } 41 if (req.type === 'cache-data-dict') { 42 DataCache.getInstance().dataDict = req.params.dataDict; 43 self.postMessage({ 44 id: req.id, 45 action: req.type, 46 results: 'ok', 47 }); 48 return; 49 } 50 Reflect.ownKeys(logicWorker).filter((it) => { 51 if (req.type && req.type.startsWith(it as string)) { 52 logicWorker[it].handle(req); 53 } 54 }); 55} 56 57self.onmessage = function (e: any) { 58 match(e.data); 59}; 60