From b47d00b489fda0c064826d37b4297bee32e59db2 Mon Sep 17 00:00:00 2001 From: Federer-JC Date: Fri, 30 Aug 2024 17:35:56 +0800 Subject: [PATCH] remove bytrace napi library. Signed-off-by:Federer-JC Signed-off-by: Federer-JC --- bundle.json | 9 +- interfaces/kits/BUILD.gn | 20 -- interfaces/kits/js/@ohos.bytrace.d.ts | 79 ------ interfaces/kits/js/napi/BUILD.gn | 29 -- .../kits/js/napi/bytrace_napi_common.cpp | 250 ------------------ interfaces/kits/js/napi/bytrace_napi_common.h | 30 --- 6 files changed, 1 insertion(+), 416 deletions(-) delete mode 100644 interfaces/kits/BUILD.gn delete mode 100644 interfaces/kits/js/@ohos.bytrace.d.ts delete mode 100644 interfaces/kits/js/napi/BUILD.gn delete mode 100644 interfaces/kits/js/napi/bytrace_napi_common.cpp delete mode 100644 interfaces/kits/js/napi/bytrace_napi_common.h diff --git a/bundle.json b/bundle.json index 07a1ecf..21ee33a 100644 --- a/bundle.json +++ b/bundle.json @@ -18,17 +18,10 @@ "rom": "114KB", "ram": "720KB", "deps": { - "components": [ - "hitrace", - "hilog", - "init", - "ipc", - "napi" - ] + "components": [] }, "build": { "sub_component": [ - "//developtools/bytrace/interfaces/kits:jsapi_kits_target" ], "inner_kits": [ ] diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn deleted file mode 100644 index 16f3d85..0000000 --- a/interfaces/kits/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2021-2022 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. - -import("//build/ohos.gni") - -group("jsapi_kits_target") { - if (support_jsapi) { - deps = [ "js/napi:bytrace" ] - } -} diff --git a/interfaces/kits/js/@ohos.bytrace.d.ts b/interfaces/kits/js/@ohos.bytrace.d.ts deleted file mode 100644 index c4a1910..0000000 --- a/interfaces/kits/js/@ohos.bytrace.d.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 interfaces to trace a task for performance measure, the logs can be capture by the - * bytrace cmdline available on the device. - * - *

This interfaces trace the start, end, and value changes of key processes that last for at least 3 ms. - * - *

Example: - * To trace a name verification that is expected to complete within 5 ms: - *

{@code
- * bytrace.startTrace("checkName", 111, 5);
- * //your process
- * bytrace.finishTrace("checkName", 111);
- * }
- * To trace the number of layers, which is 3: - *
{@code
- * bytrace.traceByValue("curLayer", 3);
- * }
- * - *

Each {@code startTrace} matches one {@code finishTrace}, and they must have the same name - * and taskId. - * - * @SysCap SystemCapability.Developtools.Bytrace - * @devices phone, tablet - * @since 7 - */ -declare namespace bytrace { - /** - * Records a trace marking it as the start of a task, can with the expected completion time between - * startTrace and finishTrace. - * - * This method is invoked at the start of a transaction to indicate that a task has started, whose name - * is specified by {@code name}, and the taskId is used to distinguish the tasks. It must be followed by - * {@link #finishTrace}, the name and taskId need to be the same. - * - * @param name Indicates the task name. - * @param taskId The unique id used to distinguish the tasks and match with the id in follow finishTrace. - * @param expectedTime Indicates the expected time required for completing the task, in milliseconds. - * @since 7 - */ - function startTrace(name: string, taskId: number, expectedTime?: number): void; - - /** - * Records a trace and marks it as the end of a task. - * - * This method is invoked at the end of a transaction to indicate that a task has ended, whose name - * is specified by {@code name}. This method must be invoked after the the startTrace. - * - * @param name Indicates the task name. It must be the same as the {@code name} of startTrace. - * @param taskId The unique id used to distinguish the tasks and must be the same as the . - * {@code taskId} of startTrace. - * @since 7 - */ - function finishTrace(name: string, taskId: number): void; - - /** - * Records a trace for generating a count, such as clock pulse and the number of layers. - * - * @param name Indicates the name used to identify the count. - * @param count Indicates the number of the count. - * @since 7 - */ - function traceByValue(name: string, count: number): void; -} -export default bytrace; diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn deleted file mode 100644 index 7eaa145..0000000 --- a/interfaces/kits/js/napi/BUILD.gn +++ /dev/null @@ -1,29 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("../../../../bytrace.gni") - -ohos_shared_library("bytrace") { - sources = [ "bytrace_napi_common.cpp" ] - external_deps = [ - "hilog:libhilog", - "hitrace:hitrace_meter", - "napi:ace_napi", - ] - - relative_install_dir = "module" - - subsystem_name = "developtools" - part_name = "bytrace" -} diff --git a/interfaces/kits/js/napi/bytrace_napi_common.cpp b/interfaces/kits/js/napi/bytrace_napi_common.cpp deleted file mode 100644 index 5d9b386..0000000 --- a/interfaces/kits/js/napi/bytrace_napi_common.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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. - */ - -#include -#include -#include -#include -#include "hitrace_meter.h" -#include "bytrace_napi_common.h" - -using namespace OHOS::HiviewDFX; -namespace { -constexpr int FIRST_ARGC_INDEX = 0; -constexpr int SECOND_ARGC_INDEX = 1; -constexpr int THIRD_ARGC_INDEX = 2; -constexpr int ARGC_NUMBER_TWICE = 2; -constexpr int ARGC_NUMBER_TRIPLE = 3; -constexpr uint64_t HITRACE_METER_LABEL = 0xD002D33; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HITRACE_METER_LABEL, "HITRACE_METER_JS"}; -using STR_NUM_PARAM_FUNC = std::function; - -napi_value ParseParams(napi_env& env, napi_callback_info& info, size_t& argc, napi_value* argv) -{ - napi_value thisVar; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - return nullptr; -} - -bool TypeCheck(const napi_env& env, const napi_value& value, const napi_valuetype expectType) -{ - napi_valuetype valueType; - napi_status status = napi_typeof(env, value, &valueType); - if (status != napi_ok) { - HiLog::Error(LABEL, "Failed to get the type of the argument"); - return false; - } - if (valueType != expectType) { - HiLog::Error(LABEL, "Type of the parameter is invalid"); - return false; - } - return true; -} - -void GetStringParam(const napi_env& env, const napi_value& value, std::string& dest) -{ - // parsing the value of string type into dest - constexpr int maxNameSize = 1024; - char buf[maxNameSize] = {0}; - size_t len = 0; - napi_get_value_string_utf8(env, value, buf, maxNameSize, &len); - dest = std::string {buf}; -} - -bool ParseStringParam(const napi_env& env, const napi_value& value, std::string& dest) -{ - // if it is not a string, convert the corresponding type to a string - if (TypeCheck(env, value, napi_string)) { - GetStringParam(env, value, dest); - return true; - } - if (TypeCheck(env, value, napi_number)) { - int64_t destI64; - napi_get_value_int64(env, value, &destI64); - dest = std::to_string(destI64); - return true; - } - // if it's napi_null, then handle it as 'null' - if (TypeCheck(env, value, napi_null)) { - dest = "null"; - return true; - } - if (TypeCheck(env, value, napi_undefined)) { - dest = "undefined"; - return true; - } - return false; -} - -bool ParseInt32Param(const napi_env& env, const napi_value& value, int& dest) -{ - if (!TypeCheck(env, value, napi_number)) { - return false; - } - napi_get_value_int32(env, value, &dest); - return true; -} - -bool ParseInt64Param(const napi_env& env, const napi_value& value, int64_t& dest) -{ - if (!TypeCheck(env, value, napi_number)) { - return false; - } - napi_get_value_int64(env, value, &dest); - return true; -} - -bool ParseDoubleParam(const napi_env& env, const napi_value& value, double& dest) -{ - if (!TypeCheck(env, value, napi_number)) { - return false; - } - napi_get_value_double(env, value, &dest); - return true; -} - -bool ParseUndefinedParam(const napi_env& env, const napi_value& value) -{ - return TypeCheck(env, value, napi_undefined); -} - -bool ParseNullParam(const napi_env& env, const napi_value& value) -{ - return TypeCheck(env, value, napi_null); -} - -bool JsStrNumParamsFunc(napi_env& env, napi_callback_info& info, STR_NUM_PARAM_FUNC nativeCall) -{ - size_t argc = ARGC_NUMBER_TWICE; - napi_value argv[ARGC_NUMBER_TWICE]; - ParseParams(env, info, argc, argv); - if (argc != ARGC_NUMBER_TWICE) { - HiLog::Error(LABEL, "Wrong number of parameters."); - return false; - } - std::string name; - if (!ParseStringParam(env, argv[FIRST_ARGC_INDEX], name)) { - return false; - } - if (!nativeCall(name, argv[SECOND_ARGC_INDEX])) { - return false; - } - return true; -} -} - -static napi_value JSTraceStart(napi_env env, napi_callback_info info) -{ - size_t argc = ARGC_NUMBER_TRIPLE; - napi_value argv[ARGC_NUMBER_TRIPLE]; - ParseParams(env, info, argc, argv); - NAPI_ASSERT(env, argc >= ARGC_NUMBER_TWICE, "Wrong number of arguments"); - if (argc < ARGC_NUMBER_TWICE) { - HiLog::Error(LABEL, "Wrong number of parameters."); - } - std::string name; - if (!ParseStringParam(env, argv[FIRST_ARGC_INDEX], name)) { - return nullptr; - } - int taskId = 0; - if (!ParseInt32Param(env, argv[SECOND_ARGC_INDEX], taskId)) { - return nullptr; - } - if (argc == ARGC_NUMBER_TWICE) { - StartAsyncTrace(HITRACE_TAG_APP, name, taskId); - } else { - double limit = 0.0; - if (!ParseDoubleParam(env, argv[THIRD_ARGC_INDEX], limit) && - !ParseUndefinedParam(env, argv[THIRD_ARGC_INDEX]) && !ParseNullParam(env, argv[THIRD_ARGC_INDEX])) { - HiLog::Error(LABEL, "the third param is not number, not undefined, not null."); - return nullptr; - } - StartAsyncTrace(HITRACE_TAG_APP, name, taskId, limit); - } - return nullptr; -} - -static napi_value JSTraceFinish(napi_env env, napi_callback_info info) -{ - size_t argc = ARGC_NUMBER_TWICE; - napi_value argv[ARGC_NUMBER_TWICE]; - napi_value thisVar; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= ARGC_NUMBER_TWICE, "Wrong number of arguments"); - (void)JsStrNumParamsFunc(env, info, [&env] (std::string name, napi_value& nValue) -> bool { - int taskId = 0; - if (!ParseInt32Param(env, nValue, taskId)) { - return false; - } - FinishAsyncTrace(HITRACE_TAG_APP, name, taskId); - return true; - }); - return nullptr; -} - -static napi_value JSTraceCount(napi_env env, napi_callback_info info) -{ - size_t argc = ARGC_NUMBER_TWICE; - napi_value argv[ARGC_NUMBER_TWICE]; - napi_value thisVar; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc == ARGC_NUMBER_TWICE, "Wrong number of arguments"); - (void)JsStrNumParamsFunc(env, info, [&env] (std::string name, napi_value& nValue) -> bool { - int64_t count = 0; - if (!ParseInt64Param(env, nValue, count)) { - return false; - } - CountTrace(HITRACE_TAG_APP, name, count); - return true; - }); - return nullptr; -} - -/* - * function for module exports - */ -EXTERN_C_START -static napi_value BytraceInit(napi_env env, napi_value exports) -{ - static napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("startTrace", JSTraceStart), - DECLARE_NAPI_FUNCTION("finishTrace", JSTraceFinish), - DECLARE_NAPI_FUNCTION("traceByValue", JSTraceCount), - }; - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - return exports; -} -EXTERN_C_END - -/* - * bytrace module definition - */ -static napi_module bytrace_module = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = "bytrace", - .nm_register_func = BytraceInit, - .nm_modname = "bytrace", - .nm_priv = ((void *)0), - .reserved = {0} -}; - -/* - * Module registration - */ -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - napi_module_register(&bytrace_module); -} diff --git a/interfaces/kits/js/napi/bytrace_napi_common.h b/interfaces/kits/js/napi/bytrace_napi_common.h deleted file mode 100644 index 0c3380c..0000000 --- a/interfaces/kits/js/napi/bytrace_napi_common.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2021-2022 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. - */ - -#ifndef INTERFACES_KITS_JS_NAPI_DECLARE_NAPI_H -#define INTERFACES_KITS_JS_NAPI_DECLARE_NAPI_H - -#include "napi/native_api.h" -#include "napi/native_node_api.h" - -namespace OHOS { -namespace Developtools { -namespace BytraceNapi { -napi_value BytraceInit(napi_env env, napi_value exports); -} -} -} - -#endif // INTERFACES_KITS_JS_NAPI_DECLARE_NAPI_H -- Gitee