mirror of
https://github.com/openharmony/developtools_bytrace.git
synced 2026-07-18 16:24:29 -04:00
!58 update bytrace warehouse name for developtools_bytrace
Merge pull request !58 from wenlong_12/master
This commit is contained in:
@@ -20,7 +20,7 @@ ByTrace is a tool for you to trace processes and monitor performance. It encapsu
|
||||
## Directory Structure<a name="section1610792125019"></a>
|
||||
|
||||
```
|
||||
/developtools/bytrace_standard
|
||||
/developtools/bytrace
|
||||
├── bin # ByTrace code
|
||||
│ └── include # Header files
|
||||
│ └── src # Source files
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ bytrace是开发人员用于追踪进程轨迹、查看性能的一种工具,
|
||||
## 目录<a name="section1610792125019"></a>
|
||||
|
||||
```
|
||||
/developtools/bytrace_standard
|
||||
/developtools/bytrace
|
||||
├── bin # bytrace组件代码目录
|
||||
│ └── include # 头文件目录
|
||||
│ └── src # 源文件目录
|
||||
|
||||
+14
-31
@@ -12,34 +12,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//developtools/bytrace_standard/bytrace.gni")
|
||||
|
||||
config("bytrace_lib_inner_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "${innerkits_path}/native/include" ]
|
||||
}
|
||||
|
||||
ohos_static_library("bytrace_inner") {
|
||||
sources = [ "./src/bytrace_impl.cpp" ]
|
||||
public_configs = [ ":bytrace_lib_inner_config" ]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"startup_l2:syspara",
|
||||
"startup_l2:syspara_watchagent",
|
||||
|
||||
#"distributedschedule:samgr_standard"
|
||||
]
|
||||
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
}
|
||||
import("//developtools/bytrace/bytrace.gni")
|
||||
|
||||
config("bytrace_osal_inner_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${innerkits_path}/native/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -52,7 +31,7 @@ ohos_static_library("bytrace_osal_inner") {
|
||||
]
|
||||
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
ohos_executable("bytrace") {
|
||||
@@ -61,33 +40,37 @@ ohos_executable("bytrace") {
|
||||
|
||||
deps = [
|
||||
":bytrace_osal_inner",
|
||||
"${innerkits_path}/native:bytrace_core",
|
||||
"//third_party/zlib:libz",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
|
||||
include_dirs = [
|
||||
"${bytrace_path}/bin/include",
|
||||
"${innerkits_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"//utils/native/base/include",
|
||||
"//third_party/zlib",
|
||||
]
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("bytrace.cfg") {
|
||||
source = "./config/bytrace.cfg"
|
||||
relative_install_dir = "init"
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
ohos_executable("bytrace_example") {
|
||||
sources = [ "example/bytrace_example.cpp" ]
|
||||
deps = [ "${innerkits_path}/native:bytrace_core" ]
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
group("bytrace_target") {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "bytrace.h"
|
||||
#include "hitrace_meter.h"
|
||||
|
||||
using namespace std;
|
||||
namespace {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <zlib.h>
|
||||
#include "bytrace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "bytrace_osal.h"
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
@@ -1,239 +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 <atomic>
|
||||
#include <cinttypes>
|
||||
#include <climits>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include "bytrace.h"
|
||||
#include "hilog/log.h"
|
||||
#include "parameter.h"
|
||||
#include "parameters.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
#define EXPECTANTLY(exp) (__builtin_expect(!!(exp), true))
|
||||
#define UNEXPECTANTLY(exp) (__builtin_expect(!!(exp), false))
|
||||
|
||||
namespace {
|
||||
int g_markerFd = -1;
|
||||
std::once_flag g_onceFlag;
|
||||
|
||||
std::atomic<bool> g_isBytraceInit(false);
|
||||
std::atomic<uint64_t> g_tagsProperty(BYTRACE_TAG_NOT_READY);
|
||||
|
||||
const std::string KEY_TRACE_TAG = "debug.bytrace.tags.enableflags";
|
||||
const std::string KEY_APP_NUMBER = "debug.bytrace.app_number";
|
||||
const std::string KEY_RO_DEBUGGABLE = "ro.debuggable";
|
||||
|
||||
constexpr int NAME_MAX_SIZE = 1000;
|
||||
static std::vector<std::string> g_markTypes = {"B", "E", "S", "F", "C"};
|
||||
enum MarkerType { MARKER_BEGIN, MARKER_END, MARKER_ASYNC_BEGIN, MARKER_ASYNC_END, MARKER_INT, MARKER_MAX };
|
||||
|
||||
constexpr uint64_t BYTRACE_TAG = 0xd03301;
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, BYTRACE_TAG, "BytraceCore"};
|
||||
|
||||
static void ParameterChange(const char* key, const char* value, void* context)
|
||||
{
|
||||
HiLog::Info(LABEL, "Trace param %{public}s change notified", key);
|
||||
UpdateTraceLabel();
|
||||
}
|
||||
|
||||
bool IsAppValid()
|
||||
{
|
||||
// Judge if application-level tracing is enabled.
|
||||
if (OHOS::system::GetBoolParameter(KEY_RO_DEBUGGABLE, 0)) {
|
||||
std::ifstream fs;
|
||||
fs.open("/proc/self/cmdline");
|
||||
if (!fs.is_open()) {
|
||||
fprintf(stderr, "IsAppValid, open /proc/self/cmdline failed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string lineStr;
|
||||
std::getline(fs, lineStr);
|
||||
std::string keyPrefix = "debug.bytrace.app_";
|
||||
int nums = OHOS::system::GetIntParameter<int>(KEY_APP_NUMBER, 0);
|
||||
for (int i = 0; i < nums; i++) {
|
||||
std::string keyStr = keyPrefix + std::to_string(i);
|
||||
std::string val = OHOS::system::GetParameter(keyStr, "");
|
||||
if (val == "*" || val == lineStr) {
|
||||
fs.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t GetSysParamTags()
|
||||
{
|
||||
// Get the system parameters of KEY_TRACE_TAG.
|
||||
uint64_t tags = OHOS::system::GetUintParameter<uint64_t>(KEY_TRACE_TAG, 0);
|
||||
if (tags == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
IsAppValid();
|
||||
return (tags | BYTRACE_TAG_ALWAYS) & BYTRACE_TAG_VALID_MASK;
|
||||
}
|
||||
|
||||
// open file "trace_marker".
|
||||
void OpenTraceMarkerFile()
|
||||
{
|
||||
const std::string debugFile = "/sys/kernel/debug/tracing/trace_marker";
|
||||
const std::string traceFile = "/sys/kernel/tracing/trace_marker";
|
||||
g_markerFd = open(debugFile.c_str(), O_WRONLY | O_CLOEXEC);
|
||||
if (g_markerFd == -1) {
|
||||
g_markerFd = open(traceFile.c_str(), O_WRONLY | O_CLOEXEC);
|
||||
if (g_markerFd == -1) {
|
||||
HiLog::Error(LABEL, "open trace file %{public}s failed: %{public}d", traceFile.c_str(), errno);
|
||||
g_tagsProperty = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_tagsProperty = GetSysParamTags();
|
||||
if (g_tagsProperty == 0 || (g_tagsProperty & BYTRACE_TAG_VALID_MASK) == BYTRACE_TAG_ALWAYS) {
|
||||
HiLog::Info(LABEL, "Get trace param value zero firstly");
|
||||
}
|
||||
|
||||
if (WatchParameter(KEY_TRACE_TAG.c_str(), ParameterChange, nullptr) != 0) {
|
||||
HiLog::Error(LABEL, "WatchParameter %{public}s failed", KEY_TRACE_TAG.c_str());
|
||||
return;
|
||||
}
|
||||
g_isBytraceInit = true;
|
||||
}
|
||||
}; // namespace
|
||||
|
||||
void AddBytraceMarker(MarkerType type, uint64_t tag, const std::string& name, const std::string& value)
|
||||
{
|
||||
if (UNEXPECTANTLY(!g_isBytraceInit)) {
|
||||
std::call_once(g_onceFlag, OpenTraceMarkerFile);
|
||||
}
|
||||
if (UNEXPECTANTLY(g_tagsProperty & tag)) {
|
||||
// record fomart: "type|pid|name value".
|
||||
std::string record = g_markTypes[type] + "|";
|
||||
record += std::to_string(getpid()) + "|";
|
||||
record += (name.size() < NAME_MAX_SIZE) ? name : name.substr(0, NAME_MAX_SIZE);
|
||||
record += " " + value;
|
||||
if (write(g_markerFd, record.c_str(), record.size()) < 0) {
|
||||
HiLog::Error(LABEL, "write trace_marker failed, %{public}d", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTraceLabel()
|
||||
{
|
||||
if (!g_isBytraceInit) {
|
||||
HiLog::Info(LABEL, "trace param notified value delay to acquire");
|
||||
return;
|
||||
}
|
||||
g_tagsProperty = GetSysParamTags();
|
||||
uint64_t val = g_tagsProperty;
|
||||
if (val == 0 || (val & BYTRACE_TAG_VALID_MASK) == BYTRACE_TAG_ALWAYS) {
|
||||
HiLog::Info(LABEL, "Get trace param notified value zero");
|
||||
} else {
|
||||
HiLog::Info(LABEL, "Get trace param notified value 0x%{public}" PRIx64, val);
|
||||
}
|
||||
}
|
||||
|
||||
void StartTrace(uint64_t label, const string& value, float limit)
|
||||
{
|
||||
string traceName = "H:" + value;
|
||||
AddBytraceMarker(MARKER_BEGIN, label, traceName, "");
|
||||
}
|
||||
|
||||
void StartTraceDebug(uint64_t label, const string& value, float limit)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
string traceName = "H:" + value + GetHiTraceInfo();
|
||||
AddBytraceMarker(MARKER_BEGIN, label, traceName, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
void FinishTrace(uint64_t label)
|
||||
{
|
||||
AddBytraceMarker(MARKER_END, label, "", "");
|
||||
}
|
||||
|
||||
void FinishTraceDebug(uint64_t label)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
AddBytraceMarker(MARKER_END, label, "", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
void StartAsyncTrace(uint64_t label, const string& value, int32_t taskId, float limit)
|
||||
{
|
||||
string traceName = "H:" + value;
|
||||
AddBytraceMarker(MARKER_ASYNC_BEGIN, label, traceName, std::to_string(taskId));
|
||||
}
|
||||
|
||||
void StartAsyncTraceDebug(uint64_t label, const string& value, int32_t taskId, float limit)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
string traceName = "H:" + value;
|
||||
AddBytraceMarker(MARKER_ASYNC_BEGIN, label, traceName, std::to_string(taskId));
|
||||
#endif
|
||||
}
|
||||
|
||||
void FinishAsyncTrace(uint64_t label, const string& value, int32_t taskId)
|
||||
{
|
||||
string traceName = "H:" + value;
|
||||
AddBytraceMarker(MARKER_ASYNC_END, label, traceName, std::to_string(taskId));
|
||||
}
|
||||
|
||||
void FinishAsyncTraceDebug(uint64_t label, const string& value, int32_t taskId)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
string traceName = "H:" + value;
|
||||
AddBytraceMarker(MARKER_ASYNC_END, label, traceName, std::to_string(taskId));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MiddleTrace(uint64_t label, const string& beforeValue, const std::string& afterValue)
|
||||
{
|
||||
string traceName = "H:" + afterValue;
|
||||
AddBytraceMarker(MARKER_END, label, "", "");
|
||||
AddBytraceMarker(MARKER_BEGIN, label, traceName, "");
|
||||
}
|
||||
|
||||
void MiddleTraceDebug(uint64_t label, const string& beforeValue, const std::string& afterValue)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
string traceName = "H:" + afterValue + GetTraceInfo();
|
||||
AddBytraceMarker(MARKER_END, label, "", "");
|
||||
AddBytraceMarker(MARKER_BEGIN, label, traceName, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
void CountTrace(uint64_t label, const string& name, int64_t count)
|
||||
{
|
||||
string traceName = "H:" + name;
|
||||
AddBytraceMarker(MARKER_INT, label, traceName, std::to_string(count));
|
||||
}
|
||||
|
||||
void CountTraceDebug(uint64_t label, const string& name, int64_t count)
|
||||
{
|
||||
#if (TRACE_LEVEL >= DEBUG_LEVEL)
|
||||
string traceName = "H:" + name;
|
||||
AddBytraceMarker(MARKER_INT, label, traceName, std::to_string(count));
|
||||
#endif
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "bytrace_osal.h"
|
||||
#include "bytrace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "parameters.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
+4
-4
@@ -9,12 +9,12 @@
|
||||
# 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.
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//developtools/bytrace_standard/bytrace.gni")
|
||||
import("//developtools/bytrace/bytrace.gni")
|
||||
|
||||
module_output_path = "bytrace_standard/bytrace"
|
||||
module_output_path = "bytrace/bytrace"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
@@ -25,10 +25,10 @@ ohos_unittest("BytraceNDKTest") {
|
||||
sources = [ "unittest/common/native/bytrace_ndk_test.cpp" ]
|
||||
deps = [
|
||||
"${bytrace_path}/bin:bytrace_osal_inner",
|
||||
"${innerkits_path}/native:bytrace_core",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hilog/log.h>
|
||||
#include "bytrace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "bytrace_osal.h"
|
||||
#include "parameters.h"
|
||||
|
||||
|
||||
+7
-18
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "@ohos/bytrace_standard",
|
||||
"name": "@ohos/bytrace",
|
||||
"description": "A tool to trace processes and monitor performance",
|
||||
"version": "3.1",
|
||||
"license": "Apache License 2.0",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "developtools/bytrace_standard"
|
||||
"destPath": "developtools/bytrace"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "bytrace_standard",
|
||||
"name": "bytrace",
|
||||
"subsystem": "developtools",
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
@@ -31,25 +31,14 @@
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
|
||||
"//developtools/bytrace_standard/bin:bytrace_target",
|
||||
"//developtools/bytrace_standard/bin:bytrace.cfg",
|
||||
"//developtools/bytrace_standard/interfaces/kits:jsapi_kits_target"
|
||||
"//developtools/bytrace/bin:bytrace_target",
|
||||
"//developtools/bytrace/bin:bytrace.cfg",
|
||||
"//developtools/bytrace/interfaces/kits:jsapi_kits_target"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"bytrace.h"
|
||||
],
|
||||
"header_base": "//developtools/bytrace_standard/interfaces/innerkits/native/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//developtools/bytrace_standard/bin/test:unittest"
|
||||
"//developtools/bytrace/bin/test:unittest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
bytrace_path = "//developtools/bytrace_standard"
|
||||
bytrace_path = "//developtools/bytrace"
|
||||
|
||||
innerkits_path = "${bytrace_path}/interfaces/innerkits"
|
||||
|
||||
|
||||
@@ -1,18 +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("innerkits_target") {
|
||||
deps = [ "native:bytrace_core" ]
|
||||
}
|
||||
@@ -1,27 +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")
|
||||
import("//developtools/bytrace_standard/bytrace.gni")
|
||||
|
||||
config("bytrace_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("bytrace_core") {
|
||||
public_configs = [ ":bytrace_config" ]
|
||||
deps = [ "${bytrace_path}/bin:bytrace_inner" ]
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
}
|
||||
@@ -1,128 +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_INNERKITS_NATIVE_INCLUDE_BYTRACE_H
|
||||
#define INTERFACES_INNERKITS_NATIVE_INCLUDE_BYTRACE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
constexpr uint64_t BYTRACE_TAG_NEVER = 0; // This tag is never enabled.
|
||||
constexpr uint64_t BYTRACE_TAG_ALWAYS = (1ULL << 0); // This tag is always enabled.
|
||||
constexpr uint64_t BYTRACE_TAG_OHOS = (1ULL << 30); // OHOS generic tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ABILITY_MANAGER = (1ULL << 31); // Ability Manager tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ZCAMERA = (1ULL << 32); // Camera module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ZMEDIA = (1ULL << 33); // Media module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ZIMAGE = (1ULL << 34); // Image module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ZAUDIO = (1ULL << 35); // Audio module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_DISTRIBUTEDDATA = (1ULL << 36); // Distributeddata manager module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_MDFS = (1ULL << 37); // Mobile distributed file system tag.
|
||||
constexpr uint64_t BYTRACE_TAG_GRAPHIC_AGP = (1ULL << 38); // Graphic module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ACE = (1ULL << 39); // ACE development framework tag.
|
||||
constexpr uint64_t BYTRACE_TAG_NOTIFICATION = (1ULL << 40); // Notification module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_MISC = (1ULL << 41); // Notification module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_MULTIMODALINPUT = (1ULL << 42); // Multi modal module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_SENSORS = (1ULL << 43); // Sensors mudule tag.
|
||||
constexpr uint64_t BYTRACE_TAG_MSDP = (1ULL << 44); // Multimodal Sensor Data Platform module tag.
|
||||
constexpr uint64_t BYTRACE_TAG_DSOFTBUS = (1ULL << 45); // Distributed Softbus tag.
|
||||
constexpr uint64_t BYTRACE_TAG_RPC = (1ULL << 46); // RPC and IPC tag.
|
||||
constexpr uint64_t BYTRACE_TAG_ARK = (1ULL << 47); // ARK tag.
|
||||
constexpr uint64_t BYTRACE_TAG_WINDOW_MANAGER = (1ULL << 48); // window manager tag.
|
||||
constexpr uint64_t BYTRACE_TAG_APP = (1ULL << 62); // App tag.
|
||||
|
||||
constexpr uint64_t BYTRACE_TAG_LAST = BYTRACE_TAG_APP;
|
||||
constexpr uint64_t BYTRACE_TAG_NOT_READY = (1ULL << 63); // Reserved for initialization.
|
||||
constexpr uint64_t BYTRACE_TAG_VALID_MASK = ((BYTRACE_TAG_LAST - 1) | BYTRACE_TAG_LAST);
|
||||
|
||||
#ifndef BYTRACE_TAG
|
||||
#define BYTRACE_TAG BYTRACE_TAG_NEVER
|
||||
#elif BYTRACE_TAG > BYTRACE_TAG_VALID_MASK
|
||||
#error BYTRACE_TAG must be defined to be one of the tags defined in bytrace.h
|
||||
#elif BYTRACE_TAG < BYTRACE_TAG_OHOS
|
||||
#error BYTRACE_TAG must be defined to be one of the tags defined in bytrace.h
|
||||
#endif
|
||||
|
||||
#define RELEASE_LEVEL 0X01
|
||||
#define DEBUG_LEVEL 0X02
|
||||
|
||||
#ifndef TRACE_LEVEL
|
||||
#define TRACE_LEVEL RELEASE
|
||||
#endif
|
||||
|
||||
#define TOKENPASTE(x, y) x ## y
|
||||
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
|
||||
#define BYTRACE_NAME(TAG, fmt, ...) ByTraceScoped TOKENPASTE2(tracer, __LINE__)(TAG, fmt, ##__VA_ARGS__)
|
||||
#define BYTRACE(TAG) BYTRACE_NAME(TAG, __func__)
|
||||
|
||||
/**
|
||||
* Update trace label when your process has started.
|
||||
*/
|
||||
void UpdateTraceLabel();
|
||||
|
||||
/**
|
||||
* Track the beginning of a context.
|
||||
*/
|
||||
void StartTrace(uint64_t label, const std::string& value, float limit = -1);
|
||||
void StartTraceDebug(uint64_t label, const std::string& value, float limit = -1);
|
||||
/**
|
||||
* Track the end of a context.
|
||||
*/
|
||||
void FinishTrace(uint64_t label);
|
||||
void FinishTraceDebug(uint64_t label);
|
||||
/**
|
||||
* Track the beginning of an asynchronous event.
|
||||
*/
|
||||
void StartAsyncTrace(uint64_t label, const std::string& value, int32_t taskId, float limit = -1);
|
||||
void StartAsyncTraceDebug(uint64_t label, const std::string& value, int32_t taskId, float limit = -1);
|
||||
|
||||
/**
|
||||
* Track the end of an asynchronous event.
|
||||
*/
|
||||
void FinishAsyncTrace(uint64_t label, const std::string& value, int32_t taskId);
|
||||
void FinishAsyncTraceDebug(uint64_t label, const std::string& value, int32_t taskId);
|
||||
|
||||
/**
|
||||
* Track the middle of a context. Match the previous function of StartTrace before it.
|
||||
*/
|
||||
void MiddleTrace(uint64_t label, const std::string& beforeValue, const std::string& afterValue);
|
||||
void MiddleTraceDebug(uint64_t label, const std::string& beforeValue, const std::string& afterValue);
|
||||
|
||||
/**
|
||||
* Track the 64-bit integer counter value.
|
||||
*/
|
||||
void CountTrace(uint64_t label, const std::string& name, int64_t count);
|
||||
void CountTraceDebug(uint64_t label, const std::string& name, int64_t count);
|
||||
|
||||
class ByTraceScoped {
|
||||
public:
|
||||
inline ByTraceScoped(uint64_t tag, const std::string &value) : mTag(tag)
|
||||
{
|
||||
StartTrace(mTag, value);
|
||||
}
|
||||
|
||||
inline ~ByTraceScoped()
|
||||
{
|
||||
FinishTrace(mTag);
|
||||
}
|
||||
private:
|
||||
uint64_t mTag;
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_BYTRACE_H
|
||||
@@ -16,8 +16,8 @@ import("//build/ohos.gni")
|
||||
group("jsapi_kits_target") {
|
||||
if (support_jsapi) {
|
||||
deps = [
|
||||
"//developtools/bytrace_standard/interfaces/kits/js/napi:bytrace",
|
||||
"//developtools/bytrace_standard/interfaces/kits/js/napi:hitracemeter_napi",
|
||||
"//developtools/bytrace/interfaces/kits/js/napi:bytrace",
|
||||
"//developtools/bytrace/interfaces/kits/js/napi:hitracemeter_napi",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,23 +12,23 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//developtools/bytrace_standard/bytrace.gni")
|
||||
import("//developtools/bytrace/bytrace.gni")
|
||||
|
||||
ohos_shared_library("bytrace") {
|
||||
sources = [
|
||||
"bytrace.cpp",
|
||||
"bytrace_napi_common.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${innerkits_path}/native:bytrace_core",
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
deps = [ "//foundation/arkui/napi:ace_napi" ]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
|
||||
relative_install_dir = "module"
|
||||
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
ohos_shared_library("hitracemeter_napi") {
|
||||
@@ -36,14 +36,14 @@ ohos_shared_library("hitracemeter_napi") {
|
||||
"bytrace_napi_common.cpp",
|
||||
"hitracemeter.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${innerkits_path}/native:bytrace_core",
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
deps = [ "//foundation/arkui/napi:ace_napi" ]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
|
||||
relative_install_dir = "module"
|
||||
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
part_name = "bytrace"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <hilog/log.h>
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "bytrace.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "bytrace_napi_common.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
Reference in New Issue
Block a user