diff --git a/bin/BUILD.gn b/bin/BUILD.gn index 3868414..f43dfb4 100644 --- a/bin/BUILD.gn +++ b/bin/BUILD.gn @@ -14,14 +14,14 @@ import("//build/ohos.gni") import("//developtools/bytrace_standard/bytrace.gni") -config("bytrace_inner_config") { +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_inner_config" ] + public_configs = [ ":bytrace_lib_inner_config" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", @@ -35,7 +35,7 @@ ohos_static_library("bytrace_inner") { part_name = "bytrace_standard" } -config("bytrace_capture_inner_config") { +config("bytrace_osal_inner_config") { visibility = [ ":*" ] include_dirs = [ "./include", @@ -43,9 +43,9 @@ config("bytrace_capture_inner_config") { ] } -ohos_static_library("bytrace_capture_inner") { - sources = [ "./src/bytrace_capture.cpp" ] - public_configs = [ ":bytrace_capture_inner_config" ] +ohos_static_library("bytrace_osal_inner") { + sources = [ "./src/bytrace_osal.cpp" ] + public_configs = [ ":bytrace_osal_inner_config" ] external_deps = [ "ipc:ipc_core", "startup_l2:syspara", @@ -57,10 +57,10 @@ ohos_static_library("bytrace_capture_inner") { ohos_executable("bytrace") { install_enable = true - sources = [ "./src/bytrace.cpp" ] + sources = [ "./src/bytrace_cmd.cpp" ] deps = [ - ":bytrace_capture_inner", + ":bytrace_osal_inner", "${innerkits_path}/native:bytrace_core", "//third_party/zlib:libz", "//utils/native/base:utils", diff --git a/bin/include/bytrace_capture.h b/bin/include/bytrace_osal.h similarity index 89% rename from bin/include/bytrace_capture.h rename to bin/include/bytrace_osal.h index 659c07d..b7dcd28 100644 --- a/bin/include/bytrace_capture.h +++ b/bin/include/bytrace_osal.h @@ -19,6 +19,9 @@ #include #include +namespace OHOS { +namespace Developtools { +namespace BytraceOsal { const int MAX_SYS_FILES = 11; enum TraceType { USER, KERNEL }; struct TagCategory { @@ -33,6 +36,9 @@ struct TagCategory { std::string GetPropertyInner(const std::string& property, const std::string& value); bool SetPropertyInner(const std::string& property, const std::string& value); -void RefreshBinderServices(); -bool RefreshHalServices(); +bool RefreshBinderServices(void); +bool RefreshHalServices(void); +} +} +} #endif // BIN_INCLUDE_BYTRACE_CAPTURE_H diff --git a/bin/src/bytrace.cpp b/bin/src/bytrace_cmd.cpp similarity index 97% rename from bin/src/bytrace.cpp rename to bin/src/bytrace_cmd.cpp index 8627671..5d80218 100644 --- a/bin/src/bytrace.cpp +++ b/bin/src/bytrace_cmd.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "bytrace.h" #include #include #include @@ -31,10 +30,13 @@ #include #include #include -#include "bytrace_capture.h" +#include "bytrace.h" +#include "bytrace_osal.h" #include "securec.h" using namespace std; +using namespace OHOS::Developtools::BytraceOsal; + namespace { struct option g_longOptions[] = { { "buffer_size", required_argument, nullptr, 0 }, @@ -101,7 +103,7 @@ static bool IsTraceMounted() return true; } - fprintf(stderr, "Error: Did not find trace folder\n"); + (void)fprintf(stderr, "Error: Did not find trace folder\n"); return false; } @@ -298,8 +300,14 @@ static bool SetTraceTagsEnabled(uint64_t tags) static bool RefreshServices() { - RefreshBinderServices(); - return RefreshHalServices(); + bool res = false; + + res = RefreshBinderServices(); + if (!res) { + return res; + } + res = RefreshHalServices(); + return res; } static bool SetUserSpaceSettings() @@ -419,8 +427,7 @@ static void ParseLongOpt(const string& cmd, int optionIndex, bool& isTrue) } else if (!strcmp(g_longOptions[optionIndex].name, "output")) { struct stat buf; size_t len = strnlen(optarg, MAX_OUTPUT_LEN); - if (len == MAX_OUTPUT_LEN || len < 1 || - (stat(optarg, &buf) == 0 && (buf.st_mode & S_IFDIR))) { + if (len == MAX_OUTPUT_LEN || len < 1 || (stat(optarg, &buf) == 0 && (buf.st_mode & S_IFDIR))) { fprintf(stderr, "Error: output file is illegal\n"); isTrue = false; } else { @@ -479,8 +486,7 @@ static bool ParseOpt(int opt, char** argv, int optIndex) case 'o': { struct stat buf; size_t len = strnlen(optarg, MAX_OUTPUT_LEN); - if (len == MAX_OUTPUT_LEN || len < 1 || - (stat(optarg, &buf) == 0 && (buf.st_mode & S_IFDIR))) { + if (len == MAX_OUTPUT_LEN || len < 1 || (stat(optarg, &buf) == 0 && (buf.st_mode & S_IFDIR))) { fprintf(stderr, "Error: output file is illegal\n"); isTrue = false; } else { @@ -569,7 +575,7 @@ static bool StopTrace() static void DumpCompressedTrace(int traceFd, int outFd) { - z_stream zs { 0 }; + z_stream zs { nullptr }; ssize_t bytesWritten; ssize_t bytesRead; if (memset_s(&zs, sizeof(zs), 0, sizeof(zs)) != 0) { @@ -713,9 +719,12 @@ static void InitDiskSupportTags() g_tagMap["mmc"] = { "mmc", "eMMC commands", 0, KERNEL, { { "events/mmc/enable" }, }}; + g_tagMap["ufs"] = { "ufs", "UFS commands", 0, KERNEL, { + { "events/ufs/enable" }, + }}; } -static void InitHardwareSupportTags() +static void InitHardwareSupportTags() { g_tagMap["irq"] = { "irq", "IRQ Events", 0, KERNEL, { { "events/irq/enable" }, @@ -737,6 +746,16 @@ static void InitHardwareSupportTags() { "events/i2c/smbus_result/enable" }, { "events/i2c/smbus_reply/enable" }, }}; + g_tagMap["regulators"] = { "regulators", "Voltage and Current Regulators", 0, KERNEL, { + { "events/regulator/enable" }, + }}; + g_tagMap["membus"] = { "membus", "Memory Bus Utilization", 0, KERNEL, { + { "events/memory_bus/enable" }, + }}; +} + +static void InitCpuSupportTags() +{ g_tagMap["freq"] = { "freq", "CPU Frequency", 0, KERNEL, { { "events/power/cpu_frequency/enable" }, { "events/power/clock_set_rate/enable" }, @@ -747,14 +766,11 @@ static void InitHardwareSupportTags() { "events/clk/clk_enable/enable" }, { "events/power/cpu_frequency_limits/enable" }, }}; - g_tagMap["ufs"] = { "ufs", "UFS commands", 0, KERNEL, { - { "events/ufs/enable" }, + g_tagMap["idle"] = { "idle", "CPU Idle", 0, KERNEL, { + { "events/power/cpu_idle/enable" }, }}; - g_tagMap["regulators"] = { "regulators", "Voltage and Current Regulators", 0, KERNEL, { - { "events/regulator/enable" }, - }}; - g_tagMap["membus"] = { "membus", "Memory Bus Utilization", 0, KERNEL, { - { "events/memory_bus/enable" }, + g_tagMap["load"] = { "load", "CPU Load", 0, KERNEL, { + { "events/cpufreq_interactive/enable" }, }}; } @@ -777,9 +793,6 @@ static void InitKernelSupportTags() { "events/preemptirq/preempt_enable/enable" }, { "events/preemptirq/preempt_disable/enable" }, }}; - g_tagMap["idle"] = { "idle", "CPU Idle", 0, KERNEL, { - { "events/power/cpu_idle/enable" }, - }}; g_tagMap["binder"] = { "binder", "Binder kernel Info", 0, KERNEL, { { "events/binder/binder_transaction/enable" }, @@ -791,9 +804,6 @@ static void InitKernelSupportTags() { "events/binder/binder_unlock/enable" }, }}; - g_tagMap["load"] = { "load", "CPU Load", 0, KERNEL, { - { "events/cpufreq_interactive/enable" }, - }}; g_tagMap["sync"] = { "sync", "Synchronization", 0, KERNEL, { // linux kernel > 4.9 { "events/dma_fence/enable" }, @@ -816,6 +826,7 @@ static void InitKernelSupportTags() { "events/kmem/ion_heap_grow/enable" }, { "events/kmem/ion_heap_shrink/enable" }, }}; + InitCpuSupportTags(); InitHardwareSupportTags(); } @@ -859,8 +870,8 @@ static void InterruptExit(int signo) int main(int argc, char **argv) { - signal(SIGKILL, InterruptExit); - signal(SIGINT, InterruptExit); + (void)signal(SIGKILL, InterruptExit); + (void)signal(SIGINT, InterruptExit); if (!IsTraceMounted()) { exit(-1); diff --git a/bin/src/bytrace_capture.cpp b/bin/src/bytrace_osal.cpp similarity index 80% rename from bin/src/bytrace_capture.cpp rename to bin/src/bytrace_osal.cpp index 62d97fb..1789f07 100644 --- a/bin/src/bytrace_capture.cpp +++ b/bin/src/bytrace_osal.cpp @@ -13,12 +13,14 @@ * limitations under the License. */ -#include "bytrace_capture.h" +#include "bytrace_osal.h" #include "bytrace.h" #include "parameters.h" -using namespace std; -bool SetPropertyInner(const string& property, const string& value) +namespace OHOS { +namespace Developtools { +namespace BytraceOsal { +bool SetPropertyInner(const std::string& property, const std::string& value) { bool result = OHOS::system::SetParameter(property, value); if (!result) { @@ -32,11 +34,15 @@ std::string GetPropertyInner(const std::string& property, const std::string& val return OHOS::system::GetParameter(property, value); } -void RefreshBinderServices() -{ -} - -bool RefreshHalServices() +bool RefreshBinderServices(void) { return true; } + +bool RefreshHalServices(void) +{ + return true; +} +} +} +} diff --git a/bin/test/BUILD.gn b/bin/test/BUILD.gn index 92951a6..7ceae89 100644 --- a/bin/test/BUILD.gn +++ b/bin/test/BUILD.gn @@ -24,7 +24,7 @@ ohos_unittest("BytraceNDKTest") { module_out_path = module_output_path sources = [ "unittest/common/native/bytrace_ndk_test.cpp" ] deps = [ - "${bytrace_path}/bin:bytrace_capture_inner", + "${bytrace_path}/bin:bytrace_osal_inner", "${innerkits_path}/native:bytrace_core", "//third_party/googletest:gtest_main", ] diff --git a/bin/test/unittest/common/native/bytrace_ndk_test.cpp b/bin/test/unittest/common/native/bytrace_ndk_test.cpp index d98aedb..6e5c519 100644 --- a/bin/test/unittest/common/native/bytrace_ndk_test.cpp +++ b/bin/test/unittest/common/native/bytrace_ndk_test.cpp @@ -20,12 +20,14 @@ #include #include #include "bytrace.h" -#include "bytrace_capture.h" +#include "bytrace_osal.h" #include "parameters.h" using namespace testing::ext; using namespace std; using namespace OHOS::HiviewDFX; +using namespace OHOS::Developtools::BytraceOsal; + namespace OHOS { namespace Developtools { namespace BytraceTest { diff --git a/interfaces/kits/BUILD.gn b/interfaces/kits/BUILD.gn index 2a073bc..05d1b57 100644 --- a/interfaces/kits/BUILD.gn +++ b/interfaces/kits/BUILD.gn @@ -16,8 +16,8 @@ import("//build/ohos.gni") group("jsapi_kits_target") { if (support_jsapi) { deps = [ - "js/napi:bytrace", - "js/napi:hitracemeter_napi", + "//developtools/bytrace_standard/interfaces/kits/js/napi:bytrace", + "//developtools/bytrace_standard/interfaces/kits/js/napi:hitracemeter_napi", ] } } diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn index 7d6b4be..3ebdcdc 100644 --- a/interfaces/kits/js/napi/BUILD.gn +++ b/interfaces/kits/js/napi/BUILD.gn @@ -17,7 +17,7 @@ import("//developtools/bytrace_standard/bytrace.gni") ohos_shared_library("bytrace") { sources = [ "bytrace.cpp", - "declare_napi.cpp", + "bytrace_napi_common.cpp", ] deps = [ "${innerkits_path}/native:bytrace_core", @@ -33,7 +33,7 @@ ohos_shared_library("bytrace") { ohos_shared_library("hitracemeter_napi") { sources = [ - "declare_napi.cpp", + "bytrace_napi_common.cpp", "hitracemeter.cpp", ] deps = [ diff --git a/interfaces/kits/js/napi/bytrace.cpp b/interfaces/kits/js/napi/bytrace.cpp index 3d28317..c6809c3 100644 --- a/interfaces/kits/js/napi/bytrace.cpp +++ b/interfaces/kits/js/napi/bytrace.cpp @@ -17,8 +17,9 @@ #include #include #include -#include "bytrace.h" -#include "declare_napi.h" +#include "bytrace_napi_common.h" + +using namespace OHOS::Developtools::BytraceNapi; /* * bytrace module definition diff --git a/interfaces/kits/js/napi/declare_napi.cpp b/interfaces/kits/js/napi/bytrace_napi_common.cpp similarity index 92% rename from interfaces/kits/js/napi/declare_napi.cpp rename to interfaces/kits/js/napi/bytrace_napi_common.cpp index 431eb0f..8434e6c 100644 --- a/interfaces/kits/js/napi/declare_napi.cpp +++ b/interfaces/kits/js/napi/bytrace_napi_common.cpp @@ -13,15 +13,14 @@ * limitations under the License. */ -#include "declare_napi.h" - #include #include #include #include -#include "bytrace.h" #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "bytrace.h" +#include "bytrace_napi_common.h" using namespace OHOS::HiviewDFX; namespace { @@ -44,7 +43,7 @@ static napi_value JSTraceStart(napi_env env, napi_callback_info info) char buf[NAME_MAX_SIZE] = {0}; size_t len = 0; napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len); - std::string name = std::string{buf}; + std::string name = std::string {buf}; NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number"); @@ -76,7 +75,7 @@ static napi_value JSTraceFinish(napi_env env, napi_callback_info info) char buf[NAME_MAX_SIZE] = {0}; size_t len = 0; napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len); - std::string name = std::string{buf}; + std::string name = std::string {buf}; NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number"); @@ -100,7 +99,7 @@ static napi_value JSTraceCount(napi_env env, napi_callback_info info) char buf[NAME_MAX_SIZE] = {0}; size_t len = 0; napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len); - std::string name = std::string{buf}; + std::string name = std::string {buf}; NAPI_CALL(env, napi_typeof(env, argv[1], &valueType)); NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number"); @@ -110,7 +109,9 @@ static napi_value JSTraceCount(napi_env env, napi_callback_info info) return nullptr; } -EXTERN_C_START +namespace OHOS { +namespace Developtools { +namespace BytraceNapi { /* * function for module exports */ @@ -124,4 +125,6 @@ napi_value BytraceInit(napi_env env, napi_value exports) NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); return exports; } -EXTERN_C_END +} +} +} diff --git a/interfaces/kits/js/napi/declare_napi.h b/interfaces/kits/js/napi/bytrace_napi_common.h similarity index 89% rename from interfaces/kits/js/napi/declare_napi.h rename to interfaces/kits/js/napi/bytrace_napi_common.h index 26d4d3f..0c3380c 100644 --- a/interfaces/kits/js/napi/declare_napi.h +++ b/interfaces/kits/js/napi/bytrace_napi_common.h @@ -19,8 +19,12 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" -EXTERN_C_START +namespace OHOS { +namespace Developtools { +namespace BytraceNapi { napi_value BytraceInit(napi_env env, napi_value exports); -EXTERN_C_END +} +} +} #endif // INTERFACES_KITS_JS_NAPI_DECLARE_NAPI_H diff --git a/interfaces/kits/js/napi/hitracemeter.cpp b/interfaces/kits/js/napi/hitracemeter.cpp index f3f4b2e..325ef82 100644 --- a/interfaces/kits/js/napi/hitracemeter.cpp +++ b/interfaces/kits/js/napi/hitracemeter.cpp @@ -17,8 +17,9 @@ #include #include #include -#include "bytrace.h" -#include "declare_napi.h" +#include "bytrace_napi_common.h" + +using namespace OHOS::Developtools::BytraceNapi; /* * hiTraceMeter module definition