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 bytrace from '@ohos.bytrace'; 17 18export class TraceControllerUtils { 19 // Used to track the start of sequential tasks 20 public static startTrace(name: string): void { 21 bytrace.startTrace(name, 1); 22 } 23 24 // Used to track the end of sequential tasks. The name must be the same as that at start 25 public static finishTrace(name: string): void { 26 bytrace.finishTrace(name, 1); 27 } 28 29 // Used to track the start of cross tasks 30 // (scenarios where the next task starts before the previous task is finished) 31 public static startTraceWithTaskId(name: string, taskId: number): void { 32 bytrace.startTrace(name, taskId); 33 } 34 35 // Used to track the end of cross tasks. The name and taskid must be the same as at start 36 public static finishTraceWithTaskId(name: string, taskId: number): void { 37 bytrace.finishTrace(name, taskId); 38 } 39}