From ed730e9a9c86f2787030a0a2e6887e654c304ba8 Mon Sep 17 00:00:00 2001 From: xuyong Date: Tue, 25 Jan 2022 15:15:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?HiTrace=20Js=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuyong --- api/phone/@ohos.hitrace.d.ts | 215 +++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 api/phone/@ohos.hitrace.d.ts diff --git a/api/phone/@ohos.hitrace.d.ts b/api/phone/@ohos.hitrace.d.ts new file mode 100644 index 0000000000..22c192ba20 --- /dev/null +++ b/api/phone/@ohos.hitrace.d.ts @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Provides APIs to implement call chain tracing throughout a service process. + * With HiTrace, you can quickly obtain the run log for the call chain of a + * specified service process and locate faults in cross-device, cross-process, + * or cross-thread communications. + * + * @since 7 + * @devices phone, tablet, tv, wearable + */ +declare namespace hitrace { + /** + * Enumerate trace flag + */ + enum HiTraceFlag { + /** + * default value + */ + DEFAULT = 0, + + /** + * trace sync and async call. default: trace sync call only. + */ + INCLUDE_ASYNC = 1, + + /** + * do not create child span. default: create child span. + */ + DONOT_CREATE_SPAN = 1 << 1, + + /** + * output tracepoint info in span. default: do not output tracepoint info. + */ + TP_INFO = 1 << 2, + + /** + * do not output begin and end info. default: output begin and end info. + */ + NO_BE_INFO = 1 << 3, + + /** + * do not add id to log. default: add id to log. + */ + DONOT_ENABLE_LOG = 1 << 4, + + /** + * the trace is triggered by fault. + */ + FAILURE_TRIGGER = 1 << 5, + + /** + * output device-to-device tracepoint info in span only. default: do not output device-to-device tracepoint info. + */ + D2D_TP_INFO = 1 << 6, + } + + /** + * Enumerate trace point type + */ + enum HiTraceTracePointType { + /** + * client send + */ + CS = 0, + + /** + * client receive + */ + CR = 1, + + /** + * server send + */ + SS = 2, + + /** + * server receive + */ + SR = 3, + + /** + * general info + */ + GENERAL = 4, + } + + /** + * Enumerate trace communication mode + */ + enum HiTraceCommunicationMode { + /** + * unspecified + */ + DEFAULT = 0, + + /** + * thread-to-thread + */ + THREAD = 1, + + /** + * process-to-process + */ + PROCESS = 2, + + /** + * device-to-device + */ + DEVICE = 3, + } + + /** + * trace id + */ + interface HiTraceId { + chainId: bigint; /* 0n: invalid */ + spandId?: bigint; + parentSpanId?: bigint; + flags?: number; + } + + /** + * begin a new trace. + * + * @param {string} name trace name. + * @param {number} flags trace flags. + * @return {HiTraceId} id of the trace. + */ + function begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId; + + /** + * end a trace by trace id. + * + * @param {HiTraceId} id trace id of the trace. + */ + function end(id: HiTraceId): void; + + /** + * get the trace id of a trace. + * + * @return {HiTraceId} trace id of a trace. + */ + function getId(): HiTraceId; + + /** + * change the trace id of a trace. + * + * @param {HiTraceId} id trace id of a trace. + */ + function setId(id: HiTraceId): void; + + /** + * clear the id of a trace. + * + */ + function clearId(): void; + + /** + * create span for a trace. + * + * @return {HiTraceId} trace id of the trace which has created a span. + */ + function createSpan(): HiTraceId; + + /** + * start trace point + * + * @param {HiTraceCommunicationMode} mode communication mode. + * @param {HiTraceTracePointType} type trace point type. + * @param {HiTraceId} id trace id of the trace. + * @param {string} msg description about this trace point. + */ + function tracepoint(mode: HiTraceCommunicationMode, type: HiTraceTracePointType, id: HiTraceId, msg?: string): void; + + /** + * check whether a trace id is valid. + * + * @param {HiTraceId} id the trace id to check. + * @return {boolean} true if trace id is valid. + */ + function isValid(id: HiTraceId): boolean; + + /** + * check whether a trace id has enabled a trace flag. + * + * @param {HiTraceId} id the trace id to check. + * @param {HiTraceFlag} flag the trace flag to check. + * @return {boolean} true if the flag has been enabled in a trace. + */ + function isFlagEnabled(id: HiTraceId, flag: HiTraceFlag): boolean; + + /** + * enable a trace flag for a trace id. + * + * @param {HiTraceId} id trace id which need enable a flag. + * @param {HiTraceFlag} flag trace flag will be enabled in a trace. + */ + function enableFlag(id: HiTraceId, flag: HiTraceFlag): void; +} + +export default hitrace; -- Gitee From 453442887622d3fbd09bbdfd6d69858801fb40a5 Mon Sep 17 00:00:00 2001 From: xuyong Date: Wed, 26 Jan 2022 14:24:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?HiTrace=20JS=20Napi=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuyong --- api/phone/@ohos.hitrace.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/api/phone/@ohos.hitrace.d.ts b/api/phone/@ohos.hitrace.d.ts index 22c192ba20..c2b10c0d3b 100644 --- a/api/phone/@ohos.hitrace.d.ts +++ b/api/phone/@ohos.hitrace.d.ts @@ -157,9 +157,9 @@ declare namespace hitrace { function getId(): HiTraceId; /** - * change the trace id of a trace. + * change the trace id for a trace. * - * @param {HiTraceId} id trace id of a trace. + * @param {HiTraceId} id trace id which will be set into a trace. */ function setId(id: HiTraceId): void; @@ -177,7 +177,7 @@ declare namespace hitrace { function createSpan(): HiTraceId; /** - * start trace point + * set a trace point * * @param {HiTraceCommunicationMode} mode communication mode. * @param {HiTraceTracePointType} type trace point type. @@ -195,7 +195,7 @@ declare namespace hitrace { function isValid(id: HiTraceId): boolean; /** - * check whether a trace id has enabled a trace flag. + * check whether a trace id has enabled the designative trace flag. * * @param {HiTraceId} id the trace id to check. * @param {HiTraceFlag} flag the trace flag to check. @@ -204,10 +204,10 @@ declare namespace hitrace { function isFlagEnabled(id: HiTraceId, flag: HiTraceFlag): boolean; /** - * enable a trace flag for a trace id. + * enable a designative trace flag for a trace id. * * @param {HiTraceId} id trace id which need enable a flag. - * @param {HiTraceFlag} flag trace flag will be enabled in a trace. + * @param {HiTraceFlag} flag the designative trace flag which will be enabled. */ function enableFlag(id: HiTraceId, flag: HiTraceFlag): void; } -- Gitee From b5b67b16ac1f78effb507c7236e47586908357f5 Mon Sep 17 00:00:00 2001 From: xuyong Date: Thu, 27 Jan 2022 15:06:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?HiTrace=20JS=20Napi=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuyong --- api/phone/@ohos.hitrace.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/phone/@ohos.hitrace.d.ts b/api/phone/@ohos.hitrace.d.ts index c2b10c0d3b..9810485c10 100644 --- a/api/phone/@ohos.hitrace.d.ts +++ b/api/phone/@ohos.hitrace.d.ts @@ -128,8 +128,8 @@ declare namespace hitrace { */ interface HiTraceId { chainId: bigint; /* 0n: invalid */ - spandId?: bigint; - parentSpanId?: bigint; + spandId?: number; + parentSpanId?: number; flags?: number; } -- Gitee