19b256929Sopenharmony_ci/* 29b256929Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 39b256929Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49b256929Sopenharmony_ci * you may not use this file except in compliance with the License. 59b256929Sopenharmony_ci * You may obtain a copy of the License at 69b256929Sopenharmony_ci * 79b256929Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89b256929Sopenharmony_ci * 99b256929Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109b256929Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119b256929Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129b256929Sopenharmony_ci * See the License for the specific language governing permissions and 139b256929Sopenharmony_ci * limitations under the License. 149b256929Sopenharmony_ci */ 159b256929Sopenharmony_ci 169b256929Sopenharmony_ciimport byTrace from "@ohos.bytrace"; 179b256929Sopenharmony_ciimport {Log} from "./Log"; 189b256929Sopenharmony_ci 199b256929Sopenharmony_ciexport class Trace { 209b256929Sopenharmony_ci static readonly CORE_METHOD_UNLOCK_SCREEN = "unlockScreen" 219b256929Sopenharmony_ci static readonly CORE_METHOD_CALL_ACCOUNT_SYSTEM = "callAccountSubsystem"; 229b256929Sopenharmony_ci static readonly CORE_METHOD_PASS_ACCOUNT_SYSTEM_RESULT = "passingAccountSubsystemResult"; 239b256929Sopenharmony_ci static readonly CORE_METHOD_HIDE_PSD_PAGE = "hidePsdPage"; 249b256929Sopenharmony_ci static readonly CORE_METHOD_SHOW_LOCK_SCREEN = "showLockScreen"; 259b256929Sopenharmony_ci static readonly CORE_METHOD_SLEEP_TO_LOCK_SCREEN = "sleepToLockScreen" 269b256929Sopenharmony_ci 279b256929Sopenharmony_ci private static readonly TRACE_TAG = 'ScreenLock:Trace'; 289b256929Sopenharmony_ci private static readonly RECORD_TRACE = true; 299b256929Sopenharmony_ci private static readonly TRACE_LIMIT = 2000; 309b256929Sopenharmony_ci 319b256929Sopenharmony_ci private static readonly TRACE_BASE_INDEX = 10020; 329b256929Sopenharmony_ci 339b256929Sopenharmony_ci private static init() { 349b256929Sopenharmony_ci Log.showInfo(this.TRACE_TAG, 'init trace parameters'); 359b256929Sopenharmony_ci globalThis.taskIdMap = new Map<string, number>(); 369b256929Sopenharmony_ci globalThis.traceIndex = Trace.TRACE_BASE_INDEX; 379b256929Sopenharmony_ci } 389b256929Sopenharmony_ci 399b256929Sopenharmony_ci /** 409b256929Sopenharmony_ci * start trace method 419b256929Sopenharmony_ci * 429b256929Sopenharmony_ci * @param {string} methodName - methodName for tracing 439b256929Sopenharmony_ci */ 449b256929Sopenharmony_ci static start(methodName: string) { 459b256929Sopenharmony_ci if (!Trace.RECORD_TRACE) return; 469b256929Sopenharmony_ci if (typeof globalThis.taskIdMap === 'undefined' || typeof globalThis.traceIndex === 'undefined') { 479b256929Sopenharmony_ci Trace.init(); 489b256929Sopenharmony_ci } 499b256929Sopenharmony_ci let taskId = globalThis.taskIdMap.get(methodName); 509b256929Sopenharmony_ci if (taskId == undefined) { 519b256929Sopenharmony_ci taskId = globalThis.traceIndex; 529b256929Sopenharmony_ci globalThis.traceIndex++; 539b256929Sopenharmony_ci globalThis.taskIdMap.set(methodName, taskId); 549b256929Sopenharmony_ci } 559b256929Sopenharmony_ci Log.showInfo(this.TRACE_TAG, `start trace ${taskId} for ${methodName}`); 569b256929Sopenharmony_ci byTrace.startTrace(this.TRACE_TAG + methodName, taskId, Trace.TRACE_LIMIT); 579b256929Sopenharmony_ci } 589b256929Sopenharmony_ci 599b256929Sopenharmony_ci /** 609b256929Sopenharmony_ci * stop trace method 619b256929Sopenharmony_ci * 629b256929Sopenharmony_ci * @param {string} methodName - methodName for tracing 639b256929Sopenharmony_ci */ 649b256929Sopenharmony_ci static end(methodName: string) { 659b256929Sopenharmony_ci if (!Trace.RECORD_TRACE) return; 669b256929Sopenharmony_ci if (typeof globalThis.taskIdMap === 'undefined') { 679b256929Sopenharmony_ci return; 689b256929Sopenharmony_ci } 699b256929Sopenharmony_ci const taskId = globalThis.taskIdMap.get(methodName); 709b256929Sopenharmony_ci if (taskId == undefined) { 719b256929Sopenharmony_ci Log.showError(this.TRACE_TAG, `fail to end trace name ${methodName}`); 729b256929Sopenharmony_ci return; 739b256929Sopenharmony_ci } 749b256929Sopenharmony_ci Log.showInfo(this.TRACE_TAG, `end trace ${taskId} for ${methodName}`); 759b256929Sopenharmony_ci byTrace.finishTrace(this.TRACE_TAG + methodName, taskId); 769b256929Sopenharmony_ci } 779b256929Sopenharmony_ci} 78