remove bytrace napi library.

Signed-off-by:Federer-JC <jincong4@huawei.com>

Signed-off-by: Federer-JC <jincong4@huawei.com>
This commit is contained in:
Federer-JC
2024-08-30 17:35:56 +08:00
parent d7d287983d
commit 0363699a7a
6 changed files with 1 additions and 416 deletions
+1 -8
View File
@@ -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": [
]
-20
View File
@@ -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" ]
}
}
-79
View File
@@ -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.
*
* <p>This interfaces trace the start, end, and value changes of key processes that last for at least 3 ms.
*
* <p>Example:
* To trace a name verification that is expected to complete within 5 ms:
* <pre>{@code
* bytrace.startTrace("checkName", 111, 5);
* //your process
* bytrace.finishTrace("checkName", 111);
* }</pre>
* To trace the number of layers, which is 3:
* <pre>{@code
* bytrace.traceByValue("curLayer", 3);
* }</pre>
*
* <p>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;
-29
View File
@@ -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"
}
@@ -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 <cstdio>
#include <functional>
#include <string>
#include <hilog/log.h>
#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<bool(std::string, napi_value&)>;
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);
}
@@ -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