From f08e7568979a5cc2dd7e73411c60e5d93c1d1cef Mon Sep 17 00:00:00 2001 From: zhang-zepeng1 Date: Fri, 26 Apr 2024 16:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=980426codecheck=E6=B8=85=E7=90=86?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang-zepeng1 --- trace_streamer/build/build_base.sh | 12 ++--- trace_streamer/build/build_base_func.sh | 6 +-- .../build/build_stanalone_plugins.sh | 31 +++++++---- trace_streamer/build/protoc_w.py | 12 ++--- trace_streamer/build/sync_base.sh | 14 ++++- trace_streamer/src/rpc/ffrt_converter.h | 2 +- .../pbreader_ffrt_parser_test.cpp | 54 ++++++++++++++++++- .../test/unittest/table/table_test.cpp | 2 +- 8 files changed, 99 insertions(+), 34 deletions(-) diff --git a/trace_streamer/build/build_base.sh b/trace_streamer/build/build_base.sh index b95092bc8..85ad86bd9 100644 --- a/trace_streamer/build/build_base.sh +++ b/trace_streamer/build/build_base.sh @@ -13,8 +13,8 @@ # limitations under the License. set -e . build/build_base_func.sh -function prepare_windows { - if [ $target_os == "windows" ];then +function prepare_windows() { + if [ "$target_os" == "windows" ];then cp .gn_win .gn else cp .gn_unix .gn @@ -28,9 +28,9 @@ function prepare_windows { exit fi } -function prepare_proto { +function prepare_proto() { TARGET_DIR=$1 - if [[ $PARAMS == *"debug"* ]]; then + if [[ "$PARAMS" == *"debug"* ]]; then TARGET_DIR=$1"_debug" fi if [ ! -f "out/$TARGET_DIR/protoc" ];then @@ -44,8 +44,8 @@ function prepare_proto { cp out/$target_os/protoreader_plugin out/"$TARGET_DIR"/protoreader_plugin fi } -function check_params { - if [[ $1 == "" || $1 == -* ]]; then +function check_params() { + if [[ "$1" == "" || "$1" == -* ]]; then echo "Option '$1' is not reasonable." >&2 exit 1 fi diff --git a/trace_streamer/build/build_base_func.sh b/trace_streamer/build/build_base_func.sh index 0aaee9c81..6cc0c6373 100644 --- a/trace_streamer/build/build_base_func.sh +++ b/trace_streamer/build/build_base_func.sh @@ -13,7 +13,7 @@ # limitations under the License. set -e . build/build_base_var.sh -function help { +function help() { echo "Usage: $1 [linux/wasm/windows/macx] [debug] [-e ] [-d ]" echo " -e , enable the default plugins." echo " -d , enable the extend plugins." @@ -21,7 +21,7 @@ function help { echo " -h Show the help info." exit } -function list_all_plugins { +function list_all_plugins() { echo "the default support plugin list:" for var in "${enable_plugin_array[@]}"; do echo " ${var#enable_}" @@ -50,7 +50,7 @@ function set_enable_extend_plugin_array() { eval "$enable_extend_plugin=$1" done } -function choose_os_type { +function choose_os_type() { case "$OSTYPE" in solaris*) echo "SOLARIS" ;; darwin*) gn_path="macx" target_os="macx" ;; diff --git a/trace_streamer/build/build_stanalone_plugins.sh b/trace_streamer/build/build_stanalone_plugins.sh index 0eb9277a0..efccaa1a7 100644 --- a/trace_streamer/build/build_stanalone_plugins.sh +++ b/trace_streamer/build/build_stanalone_plugins.sh @@ -13,21 +13,29 @@ # limitations under the License. set -e . build/build_base.sh -function check_plugin_true { + +function init_vars() { + TARGET_PATH="" + PROJ_PATH="" + SCRIPT_PATH=$(dirname "$(readlink -f "$0")") + flag="false" + IFS=',' +} + +function check_plugin_true() { if [ $1 == "false" ];then echo "Current plugins haven't '$2'!Please check!" exit fi } -function enable_plugin { + +function enable_plugin() { check_params $1 set_enable_plugin_array "false" - flag="false" - IFS=',' read -ra plugins <<< "$1" for plugin in "${plugins[@]}"; do for enable_plugin in "${enable_plugin_array[@]}"; do - if [[ $enable_plugin == *$plugin ]]; then + if [[ "$enable_plugin" == *"$plugin"* ]]; then eval "$enable_plugin=\"true\"" echo "$enable_plugin=${!enable_plugin}" flag="true" @@ -37,15 +45,14 @@ function enable_plugin { flag="false" done } -function enable_extend_plugin { - check_params $1 + +function enable_extend_plugin() { + check_params "$1" set_enable_extend_plugin_array "false" - flag="false" - IFS=',' read -ra plugins <<< "$1" for plugin in "${plugins[@]}"; do for enable_extend_plugin in "${enable_extend_plugin_array[@]}"; do - if [[ $enable_extend_plugin == *$plugin ]]; then + if [[ "$enable_extend_plugin" == *"$plugin"* ]]; then eval "$enable_extend_plugin=\"true\"" echo "$enable_extend_plugin=${!enable_extend_plugin}" flag="true" @@ -54,4 +61,6 @@ function enable_extend_plugin { check_plugin_true $flag $plugin flag="false" done -} \ No newline at end of file +} + +init_vars diff --git a/trace_streamer/build/protoc_w.py b/trace_streamer/build/protoc_w.py index cb88d9cdd..3dd7b13a4 100755 --- a/trace_streamer/build/protoc_w.py +++ b/trace_streamer/build/protoc_w.py @@ -27,8 +27,7 @@ if "developtools" in sys.argv[3]: PROJECT_TOP = os.path.realpath(os.path.join(THIS_DIR, "..")) OHOS_X64_OUT = os.path.join(PROJECT_TOP, sys.argv[2]) -LIBCXX_X64_OUT = os.path.join( - PROJECT_TOP, sys.argv[1], "ndk/libcxx/linux_x86_64") +LIBCXX_X64_OUT = os.path.join(PROJECT_TOP, sys.argv[1], "ndk/libcxx/linux_x86_64") SUBSYS_X64_OUT = os.path.join(PROJECT_TOP, sys.argv[2], TAIL_DIR) PROTOC_NAME = "protoc" PROTOCREADER_PLUGIN = "protoreader_plugin" @@ -37,10 +36,8 @@ if current_os == "Windows": PROTOC_NAME = "protoc.exe" PROTOCREADER_PLUGIN = "protoreader_plugin.exe" PROTOC = os.path.join(PROJECT_TOP, sys.argv[2], TAIL_DIR, PROTOC_NAME) -OPT_PLUGIN_PROTOREADER_PATH = os.path.join( - PROJECT_TOP, sys.argv[2], TAIL_DIR, PROTOCREADER_PLUGIN) -OPT_PLUGIN_PROTOREADER = "--plugin=protoc-gen-plugin=" + \ - os.path.join(PROJECT_TOP, sys.argv[2], TAIL_DIR, PROTOCREADER_PLUGIN) +OPT_PLUGIN_PROTOREADER_PATH = os.path.join(PROJECT_TOP, sys.argv[2], TAIL_DIR, PROTOCREADER_PLUGIN) +OPT_PLUGIN_PROTOREADER = "--plugin=protoc-gen-plugin=" + os.path.join(PROJECT_TOP, sys.argv[2], TAIL_DIR, PROTOCREADER_PLUGIN) PLUGINOUT = "--plugin_out=wrapper_namespace=ProtoReader" PARAMS = sys.argv[1:] @@ -52,8 +49,7 @@ PARAMS_ALL = f"{PARAMS_SRC}" if not sys.argv[4].startswith("--plugin"): if os.path.isfile(OPT_PLUGIN_PROTOREADER_PATH): - cmd = [PROTOC, OPT_PLUGIN_PROTOREADER, - f"{PLUGINOUT}:{sys.argv[5]}", *PARAMS_ALL.split()] + cmd=[PROTOC, OPT_PLUGIN_PROTOREADER, f"{PLUGINOUT}:{sys.argv[5]}", *PARAMS_ALL.split()] print("执行参数:--------------- ", cmd, " --------------------------") subprocess.run(cmd) subprocess.run([PROTOC, *PARAMS_ALL.split()]) diff --git a/trace_streamer/build/sync_base.sh b/trace_streamer/build/sync_base.sh index 05ef98614..f5aa24340 100644 --- a/trace_streamer/build/sync_base.sh +++ b/trace_streamer/build/sync_base.sh @@ -12,13 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. set -e -echo $SCRIPT_PATH + +function init_vars() { + TARGET_PATH="" + PROJ_PATH="" + SCRIPT_PATH=$(dirname "$(readlink -f "$0")") +} + function help() { echo "Usage: $1 [-p ]" echo " -p , set the sync target path." echo " -h Show the help info." exit } + function parser_param() { while [[ $# -gt 0 ]]; do case "$1" in @@ -33,6 +40,7 @@ function parser_param() { esac done } + function check_target_path() { if [ -z "$TARGET_PATH" ]; then echo "target path is empty!" @@ -42,4 +50,6 @@ function check_target_path() { } function set_cur_proj_path() { PROJ_PATH=$(dirname "$(readlink -f "$0")") -} \ No newline at end of file +} +init_vars +echo $SCRIPT_PATH\ \ No newline at end of file diff --git a/trace_streamer/src/rpc/ffrt_converter.h b/trace_streamer/src/rpc/ffrt_converter.h index 7d06d3aee..c45ef9246 100644 --- a/trace_streamer/src/rpc/ffrt_converter.h +++ b/trace_streamer/src/rpc/ffrt_converter.h @@ -64,7 +64,7 @@ private: void ClassifySchedSwitchData(const size_t index, std::unordered_map> &traceMap); int FindIntNumberAfterStr(const size_t index, const string &str); std::string FindSubStrAfterStr(const size_t index, const string &str); - std::string GetLabel(const std::string &mark); + std::string GetLabel(const std::string &line); void ConvertFfrtThreadToFfrtTask(); void ProcessMarkWithSchedSwitch(const int tid, int &prio, const size_t index); bool ProcessMarkWithFFRT(const int index, int &prio, int32_t &gid, const ThreadInfo &threadInfo); diff --git a/trace_streamer/test/unittest/pbreader_parser/pbreader_ffrt_parser_test.cpp b/trace_streamer/test/unittest/pbreader_parser/pbreader_ffrt_parser_test.cpp index a00d58a27..fa65495b2 100644 --- a/trace_streamer/test/unittest/pbreader_parser/pbreader_ffrt_parser_test.cpp +++ b/trace_streamer/test/unittest/pbreader_parser/pbreader_ffrt_parser_test.cpp @@ -17,6 +17,7 @@ #include #include "export_test.h" #include "ffrt_profiler_config.pb.h" +#include "ffrt_profiler_result.pb.h" #include "pbreader_parser.h" #include "trace_streamer_selector.h" @@ -59,7 +60,7 @@ public: }; /** * @tc.name: SetFfrtSrcClockid - * @tc.desc: Set Ffrt Src Clockid + * @tc.desc: Set ffrt src clockid * @tc.type: FUNC */ HWTEST_F(PbreaderFfrtParserTest, SetFfrtSrcClockid, TestSize.Level1) @@ -74,7 +75,7 @@ HWTEST_F(PbreaderFfrtParserTest, SetFfrtSrcClockid, TestSize.Level1) } /** * @tc.name: ParserAll - * @tc.desc: Parser All + * @tc.desc: Parser ffrt all data * @tc.type: FUNC */ HWTEST_F(PbreaderFfrtParserTest, ParserAll, TestSize.Level1) @@ -83,5 +84,54 @@ HWTEST_F(PbreaderFfrtParserTest, ParserAll, TestSize.Level1) const std::string ffrtBinPath = "../../test/resource/pbreader_ffrt.htrace"; EXPECT_TRUE(ParseTraceFile(selector_, ffrtBinPath)); } +/** + * @tc.name: Parser + * @tc.desc: Parser ffrt comm and trace data + * @tc.type: FUNC + */ +HWTEST_F(PbreaderFfrtParserTest, Parser, TestSize.Level1) +{ + TS_LOGI("test45-3"); + std::string buf; + bool haveSplitSeg = false; + PbreaderDataSegment dataSeg; + auto tid = gettid(); + auto pid = getpid(); + // case 1: for ffrt comm result + FfrtProfilerResult ffrtCommResult; + auto commResultEvent = ffrtCommResult.add_ffrt_event(); + commResultEvent->set_pid(pid); + commResultEvent->set_tid(tid); + commResultEvent->set_process_name("PbreaderFfrtParserTest"); + commResultEvent->set_thread_name("PbreaderFfrtParserTest"); + ffrtCommResult.SerializeToString(&buf); + dataSeg.seg = std::make_shared(buf); + dataSeg.protoData = + ProtoReader::BytesView(reinterpret_cast(dataSeg.seg->data()), dataSeg.seg->size()); + EXPECT_TRUE(ffrtDetailParser_->taskNameIndexMap_.Empty()); + ffrtDetailParser_->Parser(dataSeg, haveSplitSeg); + EXPECT_TRUE(!ffrtDetailParser_->taskNameIndexMap_.Empty()); + // case 2: for ffrt trace result + struct timespec currentTime; + clock_gettime(CLOCK_BOOTTIME, ¤tTime); + auto cpu = 0; + FfrtProfilerResult ffrtTraceResult; + auto ffrtTraceEvent = ffrtTraceResult.add_ffrt_event(); + ffrtTraceEvent->set_pid(pid); + ffrtTraceEvent->set_tid(tid); + ffrtTraceEvent->set_tv_sec(currentTime.tv_sec); + ffrtTraceEvent->set_tv_nsec(currentTime.tv_nsec); + ffrtTraceEvent->mutable_trace()->set_cpu(cpu); + ffrtTraceEvent->mutable_trace()->set_trace_type("B"); + ffrtTraceEvent->mutable_trace()->set_label("onSubmit"); + ffrtTraceResult.SerializeToString(&buf); + dataSeg.seg = std::make_shared(buf); + dataSeg.protoData = + ProtoReader::BytesView(reinterpret_cast(dataSeg.seg->data()), dataSeg.seg->size()); + EXPECT_TRUE(ffrtDetailParser_->eventParser_->htraceEventList_.empty()); + ffrtDetailParser_->Parser(dataSeg, haveSplitSeg); + EXPECT_TRUE(!ffrtDetailParser_->eventParser_->htraceEventList_.empty()); +} + } // namespace TraceStreamer } // namespace SysTuning diff --git a/trace_streamer/test/unittest/table/table_test.cpp b/trace_streamer/test/unittest/table/table_test.cpp index ae8f8726d..07fd1f85e 100644 --- a/trace_streamer/test/unittest/table/table_test.cpp +++ b/trace_streamer/test/unittest/table/table_test.cpp @@ -1164,7 +1164,7 @@ HWTEST_F(TableTest, StatTableTest, TestSize.Level1) TS_LOGI("test31-37"); std::string sqlSelect = "select * from stat"; stream_.traceDataCache_->GetStatAndInfo(); - EXPECT_EQ(stream_.traceDataCache_->SearchDatabase(sqlSelect, false), 455); + EXPECT_EQ(stream_.traceDataCache_->SearchDatabase(sqlSelect, false), 460); } /** * @tc.name: SymbolsTableTest -- Gitee