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 */ 15import { CatchTraceStatus } from './base/ProfilerConstant'; 16 17export default class WorkerHandler { 18 static socketHandler(result): void { 19 let arr = result.data.split('$'); 20 switch (arr[0]) { 21 case 'RAM': 22 globalThis.ramArr.push(arr[1]); 23 break; 24 case 'FPS': 25 globalThis.fpsArr.push(arr[1]); 26 globalThis.fpsJitterArr.push(arr[2]); 27 globalThis.timerFps = arr[1]; 28 if ( 29 globalThis.catchTraceState === CatchTraceStatus.catch_trace_start || 30 globalThis.catchTraceState === CatchTraceStatus.catch_trace_finish || 31 globalThis.catchTraceState === 32 CatchTraceStatus.catch_trace_first_running 33 ) { 34 if ( 35 globalThis.fpsJitterArr !== undefined && 36 globalThis.fpsJitterArr !== null && 37 globalThis.fpsJitterArr !== '' 38 ) { 39 let tempQueue: Array<String> = globalThis.fpsJitterArr; 40 let curJitter = tempQueue.pop(); 41 let tempJitterArr = curJitter.split('=='); 42 for (let i = 0; i < tempJitterArr.length; i++) { 43 let tmp = tempJitterArr[i]; 44 let jitter = parseInt(tmp) / 1e6; 45 if (jitter > 100) { 46 globalThis.jitterTrace = true; 47 return; 48 } 49 } 50 } 51 } 52 break; 53 case 'UdpStatus': 54 let isSocketConnect = Number(arr[1]).valueOf(); 55 if (isSocketConnect > 0) { 56 globalThis.useDaemon = true; 57 } else { 58 globalThis.useDaemon = false; 59 } 60 default: 61 break; 62 } 63 } 64} 65