diff --git a/cmd/BUILD.gn b/cmd/BUILD.gn index 58a43c0..61e7a33 100644 --- a/cmd/BUILD.gn +++ b/cmd/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//base/hiviewdfx/hitrace/hitrace.gni") import("//build/ohos.gni") config("hitrace_osal_inner_config") { @@ -18,6 +19,7 @@ config("hitrace_osal_inner_config") { include_dirs = [ "./include", "../interfaces/native/innerkits/include/hitrace_meter", + "${OHOS_HITRACE_DIR}/interfaces/native/innerkits/include/", ] } @@ -36,6 +38,7 @@ ohos_executable("hitrace") { deps = [ ":hitrace_osal_inner", + "${OHOS_HITRACE_DIR}/interfaces/native/innerkits:hitrace_dump", "//third_party/zlib:libz", ] @@ -55,6 +58,7 @@ ohos_executable("bytrace") { deps = [ ":hitrace_osal_inner", + "${OHOS_HITRACE_DIR}/interfaces/native/innerkits:hitrace_dump", "//third_party/zlib:libz", ] diff --git a/cmd/src/hitrace_cmd.cpp b/cmd/src/hitrace_cmd.cpp index 28c07e5..055b0bb 100644 --- a/cmd/src/hitrace_cmd.cpp +++ b/cmd/src/hitrace_cmd.cpp @@ -34,6 +34,7 @@ #include #include "hitrace_meter.h" +#include "hitrace_dump.h" #include "hitrace_osal.h" #include "securec.h" @@ -89,6 +90,8 @@ const unsigned int START_ASYNC = 2; unsigned int g_traceStart = START_NORMAL; bool g_traceStop = true; bool g_traceDump = true; +bool g_defaultMode = false; +bool g_closeService = false; map g_tagMap; vector g_userEnabledTags; @@ -339,6 +342,9 @@ static bool SetUserSpaceSettings() static bool ClearUserSpaceSettings() { + if (g_closeService) { + return SetTraceTagsEnabled(HITRACE_TAG_ALWAYS) && RefreshServices(); + } return SetTraceTagsEnabled(0) && RefreshServices(); } @@ -466,10 +472,12 @@ static bool ParseLongOpt(const string& cmd, int optionIndex) g_traceStart = START_NONE; g_traceStop = true; g_traceDump = true; + g_closeService = true; } else if (!strcmp(LONG_OPTIONS[optionIndex].name, "trace_finish_nodump")) { g_traceStart = START_NONE; g_traceStop = true; g_traceDump = false; + g_closeService = true; } else if (!strcmp(LONG_OPTIONS[optionIndex].name, "trace_dump")) { g_traceStart = START_NONE; g_traceStop = false; @@ -561,6 +569,10 @@ static bool HandleOpt(int argc, char** argv) } isTrue = ParseOpt(opt, argv, optionIndex); } + + if (g_userEnabledTags.size() == 0 && g_kernelEnabledPaths.size() == 0) { + g_defaultMode = true; + } return isTrue; } @@ -988,6 +1000,10 @@ int main(int argc, char **argv) exit(-1); } if (g_traceStart == START_ASYNC) { + if (g_defaultMode) { + const std::vector tagGroups = {"scene_performance"}; + OHOS::HiviewDFX::Hitrace::OpenTrace(tagGroups); + } return isTrue ? 0 : -1; } WaitForTraceDone();