diff --git a/trace_streamer/doc/app_startup.md b/trace_streamer/doc/app_startup.md index 1056b351f21ba28deeb5426c0581487973fb75c7..90d181a09cbd018656d2e09b7d6e833db6a656d6 100644 --- a/trace_streamer/doc/app_startup.md +++ b/trace_streamer/doc/app_startup.md @@ -17,7 +17,7 @@ Application Launching:在callstack表中查找包含"H:virtual void OHOS::AppE UI Ability Launching:在callstack表中查找包含"H:void OHOS::AppExecFwk::MainThread::HandleLaunchAbility(const std::shared_ptr `` &)##"字符的数据,即为启动的第5阶段,在这个阶段会上报包名和拉起该应用的ipid。如数据中缺少此阶段,可视为应用未启动。 -UI Ability OnForeground:在callstack表中查找包含"H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##"字符的数据,即为启动的第6阶段,该阶段会上报ipid,同一个应用UIAbilityLaunching(加载UIAbility)阶段和当前阶段上报的ipid相同。 +UI Ability OnForeground:在callstack表中查找包含"H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##"字符的数据,或"H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction"的数据,即为启动的第6阶段,该阶段会上报ipid,同一个应用UIAbilityLaunching(加载UIAbility)阶段和当前阶段上报的ipid相同。 后两个阶段的计算方式如下: diff --git a/trace_streamer/gn/BUILD.gn b/trace_streamer/gn/BUILD.gn index 31c35eeae503e8ad9a37cc82122ac6ddfa8435ab..ee1e0524eeb50f16bee31d7f4a0dda62468d8062 100644 --- a/trace_streamer/gn/BUILD.gn +++ b/trace_streamer/gn/BUILD.gn @@ -95,8 +95,6 @@ config("default") { if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { cflags += [ "-D HAVE_LIBUNWIND" ] } - - cflags += [ "-D USE_VTABLE" ] if (use_wasm) { cflags += [ "-D IS_WASM", @@ -104,7 +102,6 @@ config("default") { "-D target_cpu_x64", "-D target_cpu_x86_64", "-DHAVE_CONFIG_H", - "-DNDEBUG", "-DCC_IS_CLANG", "-D__x86_64__", ] @@ -131,6 +128,9 @@ config("default") { libs += [ "ws2_32" ] cflags += [ "-Wno-attributes" ] } + if (is_linux) { + cflags += [ "-D is_linux" ] + } if (with_ebpf_help_table) { cflags += [ "-D WITH_EBPF_HELP" ] } @@ -168,7 +168,6 @@ config("release") { "-pie", ] } - defines = [ "NDEBUG" ] } config("shared_library") { @@ -241,6 +240,9 @@ config("ts_config") { libs = [ "wsock32" ] libs += [ "ws2_32" ] } + if (is_linux) { + cflags += [ "-D is_linux=1" ] + } if (!use_wasm && !is_win && !is_mac && !is_test && !is_mingw) { cflags += [ "-D HAVE_LIBUNWIND" ] } diff --git a/trace_streamer/pare_third_party.sh b/trace_streamer/pare_third_party.sh index 19cf58cc43d9a22e064cbe364e72e32fe1d373ab..78dc1e8f451cdceb0cf6e52c67390ee3da619a46 100755 --- a/trace_streamer/pare_third_party.sh +++ b/trace_streamer/pare_third_party.sh @@ -97,7 +97,10 @@ fi if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then rm -rf hiviewdfx_faultloggerd perf_include/hiviewdfx/faultloggerd mkdir -p perf_include/hiviewdfx/faultloggerd/interfaces/innerkits - git clone --depth=1 git@gitee.com:openharmony/hiviewdfx_faultloggerd.git + git clone git@gitee.com:openharmony/hiviewdfx_faultloggerd.git + cd hiviewdfx_faultloggerd + git reset --hard b7e7ae4340a39db64d2cdf5f8fdb96cdb368f6a7 + cd .. mv hiviewdfx_faultloggerd/common/ perf_include/hiviewdfx/faultloggerd mv hiviewdfx_faultloggerd/interfaces/common/ perf_include/hiviewdfx/faultloggerd/interfaces mv hiviewdfx_faultloggerd/interfaces/nonlinux/ perf_include/hiviewdfx/faultloggerd/interfaces @@ -120,11 +123,24 @@ if [ ! -d "perf_include/hiviewdfx/faultloggerd" ];then $sed -i '/!realpath(path, realPath)/s/!realpath(path, realPath)/false/g' perf_include/hiviewdfx/faultloggerd/common/dfxutil/dfx_util.cpp $sed -i '/#include "dfx_util.h"/a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_mmap.cpp $sed -i '/#include /a #include "utilities.h"' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_mmap.h + $sed -i '/#if is_ohos && !is_mingw/s/#if is_ohos && !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h + $sed -i '/#if is_ohos && !is_mingw/s/#if is_ohos && !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp + $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf.h + $sed -i '/#if is_ohos/s/#if is_ohos/#if true/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp $sed -i '/#ifndef is_ohos_lite/s/#ifndef is_ohos_lite/#if false/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp + $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/dfx_elf.cpp + $sed -i '/#if !is_mingw/s/#if !is_mingw/#if is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf_define.h + $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include/dfx_elf_parser.h + $sed -i '/#define DFX_NONLINUX_DEFINE_H/a #ifndef is_linux' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h + $sed -i '/#if is_mingw/s/#if is_mingw/#ifndef is_linux/g' perf_include/hiviewdfx/faultloggerd/interfaces/common/byte_order.h + $sed -i '$a #endif' perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux/dfx_nonlinux_define.h fi if [ ! -f "hiperf/BUILD.gn" ];then rm -rf hiperf developtools_hiperf - git clone --depth=1 git@gitee.com:openharmony/developtools_hiperf.git + git clone git@gitee.com:openharmony/developtools_hiperf.git + cd developtools_hiperf + git reset --hard 9d9322fcd0a83ab409f26b3c6dfaea2bb8d42628 + cd .. if [ -d "developtools_hiperf" ];then mv developtools_hiperf hiperf $cp ../prebuilts/patch_hiperf/BUILD.gn ../third_party/hiperf/BUILD.gn diff --git a/trace_streamer/sdk/demo_sdk/sdk/sdk_data_parser.cpp b/trace_streamer/sdk/demo_sdk/sdk/sdk_data_parser.cpp index 4c4dd01442f370aec74e543f134b2a8004891388..710db92e32e980c4458856c79086382a5706f06e 100644 --- a/trace_streamer/sdk/demo_sdk/sdk/sdk_data_parser.cpp +++ b/trace_streamer/sdk/demo_sdk/sdk/sdk_data_parser.cpp @@ -112,11 +112,7 @@ int32_t SDKDataParser::UpdateJson() // 创建对应的表 int32_t SDKDataParser::CreateTableByJson() { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "meta"); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_meta"); -#endif // 创建对应的表 CreateCounterObjectTable(counterObjectTableName_); CreateCounterTable(counterTableName_); @@ -128,44 +124,28 @@ int32_t SDKDataParser::CreateTableByJson() // 根据Json配置创建couter object表 int32_t SDKDataParser::CreateCounterObjectTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // 根据Json配置创建couter表 int32_t SDKDataParser::CreateCounterTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // 根据Json配置创建slice object表 int32_t SDKDataParser::CreateSliceObjectTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // 根据Json配置创建slice表 int32_t SDKDataParser::CreateSliceTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } diff --git a/trace_streamer/sdk/demo_sdk/trace_data/trace_data_db.cpp b/trace_streamer/sdk/demo_sdk/trace_data/trace_data_db.cpp index c3665bbb70adc3a6a35e63e34e96b0fef7b41d0a..95d9102d511e01889e90abd71f45790c4eebb8b4 100644 --- a/trace_streamer/sdk/demo_sdk/trace_data/trace_data_db.cpp +++ b/trace_streamer/sdk/demo_sdk/trace_data/trace_data_db.cpp @@ -90,22 +90,12 @@ int32_t TraceDataDB::ExportDatabase(const std::string& outputName) ExecuteSql(attachSql); for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { -#ifndef USE_VTABLE - if (*itor == "_meta" && !exportMetaTable_) { - continue; - } else { - std::string exportSql("CREATE TABLE systuning_export." + (*itor).substr(1, -1) + " AS SELECT * FROM " + - *itor); - ExecuteSql(exportSql); - } -#else if (*itor == "meta" && !exportMetaTable_) { continue; } else { std::string exportSql("CREATE TABLE systuning_export." + (*itor) + " AS SELECT * FROM " + *itor); ExecuteSql(exportSql); } -#endif } std::string createArgsView = "create view systuning_export.args_view AS select A.argset, V2.data as keyName, A.id, D.desc, (case when " @@ -126,12 +116,6 @@ void TraceDataDB::Prepare() return; } pared_ = true; -#ifndef USE_VTABLE - for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { - std::string exportSql("CREATE TABLE " + (*itor).substr(1, -1) + " AS SELECT * FROM " + *itor); - ExecuteSql(exportSql); - } -#endif std::string createArgsView = "create view args_view AS select A.argset, V2.data as keyName, A.id, D.desc, (case when " "A.datatype==1 then V.data else A.value end) as strValue from args as A left join data_type as D on " diff --git a/trace_streamer/sdk/dubai_sdk/sdk/sdk_data_parser.cpp b/trace_streamer/sdk/dubai_sdk/sdk/sdk_data_parser.cpp index ca120b78613f0bb9266232f898ffce9bf24c940c..d4dec1b2a3135902ce4d6b59e141d6b8dca446a1 100644 --- a/trace_streamer/sdk/dubai_sdk/sdk/sdk_data_parser.cpp +++ b/trace_streamer/sdk/dubai_sdk/sdk/sdk_data_parser.cpp @@ -112,11 +112,7 @@ int32_t SDKDataParser::UpdateJson() // create a corresponding table int32_t SDKDataParser::CreateTableByJson() { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "meta"); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_meta"); -#endif // create a corresponding table CreateCounterObjectTable(counterObjectTableName_); CreateCounterTable(counterTableName_); @@ -128,44 +124,28 @@ int32_t SDKDataParser::CreateTableByJson() // create a couter object table based on the JSON configuration int32_t SDKDataParser::CreateCounterObjectTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // Create a couter table based on the JSON configuration int32_t SDKDataParser::CreateCounterTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // Create a slice object table based on the JSON configuration int32_t SDKDataParser::CreateSliceObjectTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } // Create a slice table based on the JSON configuration int32_t SDKDataParser::CreateSliceTable(const std::string& tableName) { -#ifdef USE_VTABLE TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, tableName); -#else - TableBase::TableDeclare(*(traceDataCache_->db_), traceDataCache_, "_" + tableName); -#endif return 0; } diff --git a/trace_streamer/sdk/dubai_sdk/trace_data/trace_data_db.cpp b/trace_streamer/sdk/dubai_sdk/trace_data/trace_data_db.cpp index c3665bbb70adc3a6a35e63e34e96b0fef7b41d0a..95d9102d511e01889e90abd71f45790c4eebb8b4 100644 --- a/trace_streamer/sdk/dubai_sdk/trace_data/trace_data_db.cpp +++ b/trace_streamer/sdk/dubai_sdk/trace_data/trace_data_db.cpp @@ -90,22 +90,12 @@ int32_t TraceDataDB::ExportDatabase(const std::string& outputName) ExecuteSql(attachSql); for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { -#ifndef USE_VTABLE - if (*itor == "_meta" && !exportMetaTable_) { - continue; - } else { - std::string exportSql("CREATE TABLE systuning_export." + (*itor).substr(1, -1) + " AS SELECT * FROM " + - *itor); - ExecuteSql(exportSql); - } -#else if (*itor == "meta" && !exportMetaTable_) { continue; } else { std::string exportSql("CREATE TABLE systuning_export." + (*itor) + " AS SELECT * FROM " + *itor); ExecuteSql(exportSql); } -#endif } std::string createArgsView = "create view systuning_export.args_view AS select A.argset, V2.data as keyName, A.id, D.desc, (case when " @@ -126,12 +116,6 @@ void TraceDataDB::Prepare() return; } pared_ = true; -#ifndef USE_VTABLE - for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { - std::string exportSql("CREATE TABLE " + (*itor).substr(1, -1) + " AS SELECT * FROM " + *itor); - ExecuteSql(exportSql); - } -#endif std::string createArgsView = "create view args_view AS select A.argset, V2.data as keyName, A.id, D.desc, (case when " "A.datatype==1 then V.data else A.value end) as strValue from args as A left join data_type as D on " diff --git a/trace_streamer/src/base/index_map.h b/trace_streamer/src/base/index_map.h index 6b8b63f5d3c8945be68decbf4f481adfba0d5761..870e9cf219183481df1673028cb6a646dcf8d285 100644 --- a/trace_streamer/src/base/index_map.h +++ b/trace_streamer/src/base/index_map.h @@ -78,36 +78,44 @@ public: rowIndexBak_.clear(); switch (op) { case SQLITE_INDEX_CONSTRAINT_EQ: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != value; }, - [&](TableRowId id) -> bool { return dataQueue[id] == value; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != value; }, + [&](TableRowId id) -> bool { return dataQueue[id] == value; }); break; case SQLITE_INDEX_CONSTRAINT_NE: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == value; }, - [&](TableRowId id) -> bool { return dataQueue[id] != value; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == value; }, + [&](TableRowId id) -> bool { return dataQueue[id] != value; }); break; case SQLITE_INDEX_CONSTRAINT_ISNULL: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }, - [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }, + [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_ISNOTNULL: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }, - [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }, + [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_GT: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] <= value; }, - [&](TableRowId id) -> bool { return dataQueue[id] > value; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] <= value; }, + [&](TableRowId id) -> bool { return dataQueue[id] > value; }); break; case SQLITE_INDEX_CONSTRAINT_GE: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] < value; }, - [&](TableRowId id) -> bool { return dataQueue[id] >= invalidValue; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] < value; }, + [&](TableRowId id) -> bool { return dataQueue[id] >= invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_LE: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] > value; }, - [&](TableRowId id) -> bool { return dataQueue[id] < invalidValue; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] > value; }, + [&](TableRowId id) -> bool { return dataQueue[id] < invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_LT: - ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] >= value; }, - [&](TableRowId id) -> bool { return dataQueue[id] < invalidValue; }); + ProcessData( + dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] >= value; }, + [&](TableRowId id) -> bool { return dataQueue[id] < invalidValue; }); break; default: break; diff --git a/trace_streamer/src/base/log.cpp b/trace_streamer/src/base/log.cpp index 7d167a90cb4f5f1678b59e23518ddce9873b89d1..7705fe4047cd257bfa6da2a5a1eb1ddda0a60789 100644 --- a/trace_streamer/src/base/log.cpp +++ b/trace_streamer/src/base/log.cpp @@ -15,3 +15,24 @@ #include "log.h" bool g_cleanMode = false; +enum LogLevel g_curLogLevel = LOG_OFF; + +bool SetLogLevel(std::string level) +{ + if (level == "D" || level == "DEBUG") { + g_curLogLevel = LOG_DEBUG; + } else if (level == "I" || level == "INFO") { + g_curLogLevel = LOG_INFO; + } else if (level == "W" || level == "WARN") { + g_curLogLevel = LOG_WARN; + } else if (level == "E" || level == "ERROR") { + g_curLogLevel = LOG_ERROR; + } else if (level == "F" || level == "FATAL") { + g_curLogLevel = LOG_FATAL; + } else if (level == "O" || level == "OFF") { + g_curLogLevel = LOG_OFF; + } else { + return false; + } + return true; +} diff --git a/trace_streamer/src/base/log.h b/trace_streamer/src/base/log.h index 1641f2e0b49f1d7973701f1847ca02294013583a..00b750549d52939c31a1111ddbacfa0db8c268c7 100644 --- a/trace_streamer/src/base/log.h +++ b/trace_streamer/src/base/log.h @@ -26,30 +26,22 @@ __builtin_trap(); \ __builtin_unreachable(); \ } while (0) -enum LogLevel { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL }; -const enum LogLevel CURRENT_LOG_LEVEL = LOG_DEBUG; -extern bool g_cleanMode; -#define LOGWITHLEVEL(level, motify, fmt, ...) \ - do { \ - if (level >= CURRENT_LOG_LEVEL) { \ - if (!g_cleanMode) { \ - fprintf(stdout, "[-%c][%s][%d]: " fmt "\n", motify, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ - } \ - if (level == LOG_FATAL) { \ - TS_CRASH; \ - } \ - } \ +enum LogLevel { LOG_DEBUG = 0, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL, LOG_OFF }; +extern enum LogLevel g_curLogLevel; +bool SetLogLevel(std::string level); +#define LOGWITHLEVEL(level, motify, fmt, ...) \ + do { \ + if (level >= g_curLogLevel) { \ + fprintf(stdout, "[-%c][%s][%d]: " fmt "\n", motify, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + if (level == LOG_FATAL) { \ + TS_CRASH; \ + } \ + } \ } while (0) #define TS_LOGE(fmt, ...) LOGWITHLEVEL(LOG_ERROR, 'E', fmt, ##__VA_ARGS__) #define TS_LOGF(fmt, ...) LOGWITHLEVEL(LOG_FATAL, 'F', fmt, ##__VA_ARGS__) -#ifdef NDEBUG -#define TS_LOGI(fmt, ...) LOGWITHLEVEL(LOG_DEBUG, 'I', fmt, ##__VA_ARGS__) -#define TS_LOGD(format, ...) -#define TS_ASSERT(x) -#define TS_LOGW(fmt, ...) LOGWITHLEVEL(LOG_WARN, 'W', fmt, ##__VA_ARGS__) -#else #define TS_LOGD(fmt, ...) LOGWITHLEVEL(LOG_DEBUG, 'D', fmt, ##__VA_ARGS__) -#define TS_LOGI(fmt, ...) LOGWITHLEVEL(LOG_DEBUG, 'I', fmt, ##__VA_ARGS__) +#define TS_LOGI(fmt, ...) LOGWITHLEVEL(LOG_INFO, 'I', fmt, ##__VA_ARGS__) #define TS_LOGW(fmt, ...) LOGWITHLEVEL(LOG_WARN, 'W', fmt, ##__VA_ARGS__) #define TS_ASSERT(x) \ @@ -59,8 +51,6 @@ extern bool g_cleanMode; } \ } while (0) -#endif - #define TS_CHECK_TRUE_RET(expression, retval, ...) \ do { \ if (!(expression)) { \ diff --git a/trace_streamer/src/filter/app_start_filter.cpp b/trace_streamer/src/filter/app_start_filter.cpp index 83c0601b252f316056d5b24d5b6fef27f45a4834..356ac1037465d170107d3dca9006503cf14b4c80 100644 --- a/trace_streamer/src/filter/app_start_filter.cpp +++ b/trace_streamer/src/filter/app_start_filter.cpp @@ -179,7 +179,7 @@ void APPStartupFilter::ParserAppStartup() if (!ProcAbilityLaunchData(nameString, i)) { continue; } - } else if (StartWith(nameString, uiOnForegroundCmd_)) { + } else if (StartWith(nameString, uiOnForegroundFirstCmd_) || StartWith(nameString, uiOnForegroundSecCmd_)) { ProcForegroundData(i); } } diff --git a/trace_streamer/src/filter/app_start_filter.h b/trace_streamer/src/filter/app_start_filter.h index 560f7373e5791c129d1eeab37d6376120bee8eaf..87364c5551e53ce4e67d5ea3a2d005e54bf01b4b 100644 --- a/trace_streamer/src/filter/app_start_filter.h +++ b/trace_streamer/src/filter/app_start_filter.h @@ -86,10 +86,10 @@ private: "sptr &)##"; const std::string uiLaunchCmd_ = "H:void OHOS::AppExecFwk::MainThread::HandleLaunchAbility(const std::shared_ptr &)##"; - const std::string uiOnForegroundCmd_ = + const std::string uiOnForegroundFirstCmd_ = "H:void OHOS::AbilityRuntime::FAAbilityThread::HandleAbilityTransaction(const OHOS::AbilityRuntime::Want &, " - "const " - "OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##"; + "const OHOS::AbilityRuntime::LifeCycleStateInfo &, sptr)##"; + const std::string uiOnForegroundSecCmd_ = "H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction"; const std::string dlopenCmd_ = "dlopen:"; }; } // namespace TraceStreamer diff --git a/trace_streamer/src/filter/frame_filter.cpp b/trace_streamer/src/filter/frame_filter.cpp index 49ec7c0abd5d37ee1eeba9670a1c620f235b8482..1953c59f67d1a6cda5c5fe9aad718b11c761e2ae 100644 --- a/trace_streamer/src/filter/frame_filter.cpp +++ b/trace_streamer/src/filter/frame_filter.cpp @@ -56,11 +56,11 @@ bool FrameFilter::MarkRSOnDoCompositionEvent(uint64_t ts, uint32_t itid) { auto frame = vsyncRenderSlice_.find(itid); if (frame == vsyncRenderSlice_.end()) { - TS_LOGW("BeginOnDoCompositionEvent find for itid:%u failed, ts:%" PRIu64 "", itid, ts); + TS_LOGD("BeginOnDoCompositionEvent find for itid:%u failed, ts:%" PRIu64 "", itid, ts); return false; } if (!frame->second.size()) { - TS_LOGW("BeginOnDoCompositionEvent find for itid:%u failed", itid); + TS_LOGD("BeginOnDoCompositionEvent find for itid:%u failed", itid); return false; } auto lastFrameSlice = frame->second.back(); @@ -72,11 +72,11 @@ bool FrameFilter::BeginRSTransactionData(uint64_t ts, uint32_t itid, uint32_t fr { auto frame = vsyncRenderSlice_.find(itid); if (frame == vsyncRenderSlice_.end()) { - TS_LOGW("BeginRSTransactionData find for itid:%u failed", itid); + TS_LOGD("BeginRSTransactionData find for itid:%u failed", itid); return false; } if (!frame->second.size()) { - TS_LOGW("BeginRSTransactionData find for itid:%u failed", itid); + TS_LOGD("BeginRSTransactionData find for itid:%u failed", itid); return false; } frame->second.begin()->get()->frameNum_ = franeNum; @@ -96,16 +96,13 @@ bool FrameFilter::BeginProcessCommandUni(uint64_t ts, { auto frame = vsyncRenderSlice_.find(itid); if (frame == vsyncRenderSlice_.end()) { - TS_LOGW("BeginProcessCommandUni find for itid:%u failed", itid); return false; } if (!frame->second.size()) { - TS_LOGW("BeginProcessCommandUni find for itid:%u failed", itid); return false; } auto lastFrameSlice = frame->second.back(); if (lastFrameSlice->vsyncEnd_) { - TS_LOGW("BeginProcessCommandUni finished for vsyncId:%u", lastFrameSlice->vsyncId_); return false; } std::vector fromSlices = {}; @@ -113,14 +110,10 @@ bool FrameFilter::BeginProcessCommandUni(uint64_t ts, for (auto& it : frames) { auto sourceFrameMap = dstRenderSlice_.find(it.sourceItid); if (sourceFrameMap == dstRenderSlice_.end()) { - // error - TS_LOGE("BeginProcessCommandUni find for itid:%u framenum:%u failed", it.sourceItid, it.frameNum); continue; } auto srcFrame = sourceFrameMap->second.find(it.frameNum); if (srcFrame == sourceFrameMap->second.end()) { - // error - TS_LOGE("BeginProcessCommandUni find for itid:%u framenum:%u failed", it.sourceItid, it.frameNum); continue; } fromSlices.push_back(srcFrame->second.get()->frameSliceRow_); @@ -190,11 +183,11 @@ bool FrameFilter::StartFrameQueue(uint64_t ts, uint32_t itid) { auto frame = vsyncRenderSlice_.find(itid); if (frame == vsyncRenderSlice_.end()) { - TS_LOGW("StartFrameQueue find for itid:%u failed", itid); + TS_LOGD("StartFrameQueue find for itid:%u failed", itid); return false; } if (!frame->second.size()) { - TS_LOGW("StartFrameQueue find for itid:%u failed", itid); + TS_LOGD("StartFrameQueue find for itid:%u failed", itid); return false; } auto firstFrameSlice = frame->second.front(); diff --git a/trace_streamer/src/filter/native_hook_filter.cpp b/trace_streamer/src/filter/native_hook_filter.cpp index c18081621792a45e80affa8c37b09654f58cac32..6f117b53502a22e6d83dcec28ed09483d571fbba 100644 --- a/trace_streamer/src/filter/native_hook_filter.cpp +++ b/trace_streamer/src/filter/native_hook_filter.cpp @@ -66,6 +66,7 @@ void NativeHookFilter::ParseConfigInfo(ProtoReader::BytesView& protoData) void NativeHookFilter::AppendStackMaps(uint32_t ipid, uint32_t stackid, std::vector& frames) { uint64_t ipidWithStackIdIndex = 0; + // the last element is ipid for this batch of frames/ips if (isSingleProcData_) { frames.emplace_back(SINGLE_PROC_IPID); ipidWithStackIdIndex = stackid; @@ -308,7 +309,7 @@ void NativeHookFilter::ParseFreeEvent(uint64_t timeStamp, const ProtoReader::Byt traceDataCache_->GetNativeHookData()->UpdateEndTimeStampAndDuration(row, timeStamp); freeHeapSize = traceDataCache_->GetNativeHookData()->MemSizes()[row]; } else { - TS_LOGD("func addr:%lu is empty", freeEventReader.addr()); + TS_LOGD("func addr:%" PRIu64 " is empty", freeEventReader.addr()); streamFilters_->statFilter_->IncreaseStat(TRACE_NATIVE_HOOK_FREE, STAT_EVENT_DATA_INVALID); return; } @@ -427,7 +428,7 @@ void NativeHookFilter::ParseMunmapEvent(uint64_t timeStamp, const ProtoReader::B addrToMmapEventRow_.erase(mUnmapAddr); traceDataCache_->GetNativeHookData()->UpdateEndTimeStampAndDuration(row, timeStamp); } else { - TS_LOGD("func addr:%lu is empty", mUnmapAddr); + TS_LOGD("func addr:%" PRIu64 " is empty", mUnmapAddr); streamFilters_->statFilter_->IncreaseStat(TRACE_NATIVE_HOOK_MUNMAP, STAT_EVENT_DATA_INVALID); return; } diff --git a/trace_streamer/src/filter/offline_symbolization_filter.cpp b/trace_streamer/src/filter/offline_symbolization_filter.cpp index 4a5cbc0fe9f5fdb6aeac0646b314f31298222b24..f3b0fbe2c956d5f16dc5c436b10c8b352a162ff9 100644 --- a/trace_streamer/src/filter/offline_symbolization_filter.cpp +++ b/trace_streamer/src/filter/offline_symbolization_filter.cpp @@ -108,7 +108,7 @@ std::shared_ptr OfflineSymbolizationFilter::OfflineSymbolizationByIp( if (symbolTable == nullptr) { // find matching SymbolTable failed, but filePathId is availiable ipidToIpToFrameInfo_.Insert(ipid, ip, frameInfo); - TS_LOGD("find matching filePathId failed, ipid = %" PRIu64 ", ip = %lu, filePathId = %u", ipid, ip, + TS_LOGD("find matching filePathId failed, ipid = %" PRIu64 ", ip = %" PRIu64 ", filePathId = %u", ipid, ip, frameInfo->filePathId_); return frameInfo; } diff --git a/trace_streamer/src/filter/offline_symbolization_filter.h b/trace_streamer/src/filter/offline_symbolization_filter.h index 0cf5803a59e85d71cd712108c593daa5f51b6cc7..3743a2fd75bc902d2c94e72ffa51b01ac3e193f7 100644 --- a/trace_streamer/src/filter/offline_symbolization_filter.h +++ b/trace_streamer/src/filter/offline_symbolization_filter.h @@ -15,7 +15,7 @@ #ifndef OFFLINE_SYMBOLIZATION_FILTER_H #define OFFLINE_SYMBOLIZATION_FILTER_H -#if is_mingw +#ifndef is_linux #include "dfx_nonlinux_define.h" #else #include diff --git a/trace_streamer/src/filter/slice_filter.cpp b/trace_streamer/src/filter/slice_filter.cpp index 6d8859648d10df5f9c396b898c1b82b080f6b696..c2f3a00de33a764d979a30f8eff92364edc8fbf9 100644 --- a/trace_streamer/src/filter/slice_filter.cpp +++ b/trace_streamer/src/filter/slice_filter.cpp @@ -365,7 +365,6 @@ size_t SliceFilter::CompleteSlice(uint64_t timeStamp, SlicesStack& stack = stackInfo.sliceStack; CloseUnMatchedSlice(timeStamp, stack, internalTid); if (stack.empty()) { - TS_LOGE("a slice end do not match a slice start event"); callEventDisMatchCount++; return SIZE_MAX; } diff --git a/trace_streamer/src/main.cpp b/trace_streamer/src/main.cpp index 5f4015239c9b2a186014c3de386013e4dbee1a10..2f4b478eba53270d448732166c77909e9e0c5b91 100644 --- a/trace_streamer/src/main.cpp +++ b/trace_streamer/src/main.cpp @@ -69,7 +69,7 @@ void ExportStatusToLog(const std::string& dbPath, TraceParserStatus status) } void ShowHelpInfo(const char* argv) { - TS_LOGI( + printf( "trace analyze tool, it can transfer a bytrace/htrace file into a " "SQLite database and save result to a local file trace_streamer.log.\n" "Usage: %s FILE -e sqlite_out.pb\n" @@ -79,13 +79,18 @@ void ShowHelpInfo(const char* argv) " -c command line mode.\n" " -d dump perf readable text.\n" " -h start HTTP server.\n" + " -l , --level=\n" + " Show specific level/levels logs with format: level1,level2,level3\n" + " Long level string coule be: DEBUG/INFO/WARN/ERROR/FATAL/OFF.\n" + " Short level string coule be: D/I/W/E/F/O.\n" + " Default level is OFF.\n" " -s separate arkts-plugin data, and save it in current dir with default filename.\n" " -p Specify the port of HTTP server, default is 9001.\n" " -q select sql from file.\n" " -m Perform operations that query metrics through linux,supports querying multiple metrics items.For " "example:-m x,y,z.\n" " -i show information.\n" - " -v show version.", + " -v show version.\n", argv, argv); } void PrintInformation() @@ -131,14 +136,14 @@ bool ReadAndParser(SysTuning::TraceStreamer::TraceStreamerSelector& ta, int fd) if (!ta.ParseTraceDataSegment(std::move(buf), static_cast(rsize), false, isFinish)) { return false; }; - printf("\rLoadingFile:\t%.2f MB\r", static_cast(g_loadSize) / 1E6); + TS_LOGI("\rLoadingFile:\t%.2f MB\r", static_cast(g_loadSize) / 1E6); } ta.WaitForParserEnd(); auto endTime = (std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch())) .count(); - (void)fprintf(stdout, "\nParserDuration:\t%u ms\n", static_cast(endTime - startTime)); - (void)fprintf(stdout, "ParserSpeed:\t%.2f MB/s\n", (g_loadSize / (endTime - startTime) / 1E3)); + TS_LOGI("\nParserDuration:\t%u ms", static_cast(endTime - startTime)); + TS_LOGI("ParserSpeed:\t%.2f MB/s", (g_loadSize / (endTime - startTime) / 1E3)); return true; } bool SetFileSize(const std::string& traceFilePath) @@ -199,20 +204,20 @@ int ExportDatabase(TraceStreamerSelector& ts, const std::string& sqliteFilePath) metaData->SetParserToolVersion(g_traceStreamerVersion); metaData->SetParserToolPublishDateTime(g_traceStreamerPublishVersion); metaData->SetTraceDataSize(g_loadSize); - fprintf(stdout, "ExportDatabase begin...\n"); + TS_LOGI("ExportDatabase begin...\n"); if (ts.ExportDatabase(sqliteFilePath)) { fprintf(stdout, "ExportDatabase failed\n"); ExportStatusToLog(sqliteFilePath, TRACE_PARSER_ABNORMAL); return 1; } - fprintf(stdout, "ExportDatabase end\n"); + TS_LOGI("ExportDatabase end\n"); } auto endTime = (std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch())) .count(); endTime += 1; // for any exception of endTime == startTime - fprintf(stdout, "ExportDuration:\t%u ms\n", static_cast(endTime - startTime)); - fprintf(stdout, "ExportSpeed:\t%.2f MB/s\n", (g_loadSize / (endTime - startTime)) / 1E3); + TS_LOGI("ExportDuration:\t%u ms\n", static_cast(endTime - startTime)); + TS_LOGI("ExportSpeed:\t%.2f MB/s\n", (g_loadSize / (endTime - startTime)) / 1E3); return 0; } @@ -261,7 +266,7 @@ int CheckArgs(int argc, char** argv, TraceExportOption& traceExportOption, HttpO } else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--command")) { traceExportOption.interactiveState = true; continue; - } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--command")) { + } else if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--dump")) { TS_CHECK_TRUE_RET(CheckArgc(argc, argv, ++i), 1); traceExportOption.perfReadableTextFilePath = std::string(argv[i]); continue; @@ -271,6 +276,13 @@ int CheckArgs(int argc, char** argv, TraceExportOption& traceExportOption, HttpO continue; } else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--info")) { PrintInformation(); + } else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--level")) { + TS_CHECK_TRUE_RET(CheckArgc(argc, argv, ++i), 1); + if (!SetLogLevel(std::string(argv[i]))) { + ShowHelpInfo(argv[0]); + return 1; + } + continue; } else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--s")) { traceExportOption.separateFile = true; continue; diff --git a/trace_streamer/src/parser/ebpf_parser/BUILD.gn b/trace_streamer/src/parser/ebpf_parser/BUILD.gn index 8e40c87b5ecf8e75fb331bf0c6668c9a76b50da5..5bb61778bccca89b2aeb9b15cce485de1e9b8742 100644 --- a/trace_streamer/src/parser/ebpf_parser/BUILD.gn +++ b/trace_streamer/src/parser/ebpf_parser/BUILD.gn @@ -61,12 +61,17 @@ ohos_source_set("ebpf_parser_src") { } } public_deps = [ "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/memory_data:memory_data_reader" ] - if (is_win || is_mac || is_mingw) { - include_dirs += [ - "${THIRD_PARTY}/perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux", - "${THIRD_PARTY}/perf_include/linux", - ] - } + include_dirs += [ + "${THIRD_PARTY}/perf_include/hiviewdfx/faultloggerd/interfaces/nonlinux", + "${THIRD_PARTY}/perf_include/linux", + "${THIRD_PARTY}/hiperf/include", + "${THIRD_PARTY}/perf_include/hiviewdfx/faultloggerd/interfaces/innerkits/unwinder/include", + "${THIRD_PARTY}/perf_include/hiviewdfx/faultloggerd/interfaces/common", + "${THIRD_PARTY}/hiperf/include/nonlinux/linux", + "${THIRD_PARTY}/perf_include/hiviewdfx/faultloggerd/common/dfxutil", + "${THIRD_PARTY}/hiperf/include/nonlinux/", + "${THIRD_PARTY}/perf_include/libbpf", + ] } group("ebpf_parser") { diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_base.cpp b/trace_streamer/src/parser/ebpf_parser/ebpf_base.cpp index 0297c10161c3063c8e87315abad923676df091b4..95d3ce70f87d2a83ce6de32a894344d38bbb05a7 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_base.cpp +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_base.cpp @@ -18,7 +18,7 @@ namespace SysTuning { namespace TraceStreamer { EbpfBase::EbpfBase(TraceDataCache* dataCache, const TraceStreamerFilters* ctx) : EventParserBase(dataCache, ctx), - pidAndIpToSymbolAndFilePathIndex_(SymbolAndFilePathIndex(false)), + pidAndIpToEbpfSymbolInfo_(EbpfSymbolInfo(false)), filePathIndexAndStValueToSymAddr_(nullptr), pidAndipsToCallId_(INVALID_UINT64) { @@ -26,7 +26,7 @@ EbpfBase::EbpfBase(TraceDataCache* dataCache, const TraceStreamerFilters* ctx) EbpfBase::~EbpfBase() { pidAndipsToCallId_.Clear(); - pidAndIpToSymbolAndFilePathIndex_.Clear(); + pidAndIpToEbpfSymbolInfo_.Clear(); filePathIndexToPidAndIpMap_.clear(); filePathIndexAndStValueToSymAddr_.Clear(); } @@ -47,11 +47,11 @@ void EbpfBase::ParseCallStackData(const uint64_t* userIpsAddr, uint16_t count, u uint64_t depth = 0; for (auto i = count - 1; i >= 0; i--) { if (userIpsAddr[i] > MIN_USER_IP) { - auto symbolAndFilePathIndex = GetSymbolAndFilePathIndex(pid, userIpsAddr[i]); + auto ebpfSymbolInfo = GetEbpfSymbolInfo(pid, userIpsAddr[i]); auto ipIndex = ConvertToHexTextIndex(userIpsAddr[i]); ipStrIndexToIpMap_.insert(std::make_pair(ipIndex, userIpsAddr[i])); - traceDataCache_->GetEbpfCallStack()->AppendNewData( - callId, depth, ipIndex, symbolAndFilePathIndex.symbolIndex, symbolAndFilePathIndex.filePathIndex); + traceDataCache_->GetEbpfCallStack()->AppendNewData(callId, depth, ipIndex, ebpfSymbolInfo.symbolIndex, + ebpfSymbolInfo.filePathIndex, ebpfSymbolInfo.vaddr); depth++; } } @@ -59,9 +59,9 @@ void EbpfBase::ParseCallStackData(const uint64_t* userIpsAddr, uint16_t count, u callIdToPid_.insert(std::make_pair(callId, pid)); } -SymbolAndFilePathIndex EbpfBase::GetSymbolAndFilePathIndex(uint32_t pid, uint64_t ip) +EbpfSymbolInfo EbpfBase::GetEbpfSymbolInfo(uint32_t pid, uint64_t ip) { - auto value = pidAndIpToSymbolAndFilePathIndex_.Find(pid, ip); + auto value = pidAndIpToEbpfSymbolInfo_.Find(pid, ip); if (value.flag) { return value; } @@ -115,24 +115,24 @@ void EbpfBase::UpdateFilePathIndexToPidAndIpMap(DataIndex filePathIndex, uint32_ } } -SymbolAndFilePathIndex EbpfBase::GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip) +EbpfSymbolInfo EbpfBase::GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip) { - SymbolAndFilePathIndex symbolAndFilePathIndex(false); + EbpfSymbolInfo ebpfSymbolInfo(false); // Follow the rules of front closing and rear opening, [start, end) if (ip < reader_->maxKernelAddr_ && ip >= reader_->minKernelAddr_) { - symbolAndFilePathIndex = reader_->GetSymbolNameIndexFromElfSym(ip); - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - UpdateFilePathIndexToPidAndIpMap(symbolAndFilePathIndex.filePathIndex, pid, ip); - return symbolAndFilePathIndex; + ebpfSymbolInfo = reader_->GetSymbolNameIndexFromElfSym(ip); + pidAndIpToEbpfSymbolInfo_.Insert(pid, ip, ebpfSymbolInfo); + UpdateFilePathIndexToPidAndIpMap(ebpfSymbolInfo.filePathIndex, pid, ip); + return ebpfSymbolInfo; } auto& pidAndStartAddrToMapsAddr = reader_->GetPidAndStartAddrToMapsAddr(); auto startToMapsAddr = pidAndStartAddrToMapsAddr.Find(pid); if (!startToMapsAddr) { - symbolAndFilePathIndex.flag = true; - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - UpdateFilePathIndexToPidAndIpMap(symbolAndFilePathIndex.filePathIndex, pid, ip); - return symbolAndFilePathIndex; + ebpfSymbolInfo.flag = true; + pidAndIpToEbpfSymbolInfo_.Insert(pid, ip, ebpfSymbolInfo); + UpdateFilePathIndexToPidAndIpMap(ebpfSymbolInfo.filePathIndex, pid, ip); + return ebpfSymbolInfo; } uint64_t vmStart = INVALID_UINT64; @@ -145,31 +145,32 @@ SymbolAndFilePathIndex EbpfBase::GetSymbolNameIndexFromElfSym(uint32_t pid, uint if (ip < end->second->end) { vmStart = end->first; vmOffset = end->second->offset; - symbolAndFilePathIndex.filePathIndex = + ebpfSymbolInfo.filePathIndex = traceDataCache_->GetDataIndex(reinterpret_cast((end->second) + 1)); } } - symbolAndFilePathIndex.flag = true; - if (symbolAndFilePathIndex.filePathIndex == INVALID_INT64) { - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - UpdateFilePathIndexToPidAndIpMap(symbolAndFilePathIndex.filePathIndex, pid, ip); - return symbolAndFilePathIndex; + ebpfSymbolInfo.flag = true; + if (ebpfSymbolInfo.filePathIndex == INVALID_INT64) { + pidAndIpToEbpfSymbolInfo_.Insert(pid, ip, ebpfSymbolInfo); + UpdateFilePathIndexToPidAndIpMap(ebpfSymbolInfo.filePathIndex, pid, ip); + return ebpfSymbolInfo; } - auto itor = reader_->GetElfPathIndexToElfAddr().find(symbolAndFilePathIndex.filePathIndex); + auto itor = reader_->GetElfPathIndexToElfAddr().find(ebpfSymbolInfo.filePathIndex); if (itor == reader_->GetElfPathIndexToElfAddr().end()) { - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - UpdateFilePathIndexToPidAndIpMap(symbolAndFilePathIndex.filePathIndex, pid, ip); - return symbolAndFilePathIndex; + pidAndIpToEbpfSymbolInfo_.Insert(pid, ip, ebpfSymbolInfo); + UpdateFilePathIndexToPidAndIpMap(ebpfSymbolInfo.filePathIndex, pid, ip); + return ebpfSymbolInfo; } uint64_t symVaddr = ip - vmStart + vmOffset + itor->second->textVaddr - itor->second->textOffset; + ebpfSymbolInfo.vaddr = symVaddr; auto symbolIndex = GetSymbolNameIndexFromSymVaddr(itor->second, symVaddr); if (symbolIndex != INVALID_UINT64) { - symbolAndFilePathIndex.symbolIndex = symbolIndex; + ebpfSymbolInfo.symbolIndex = symbolIndex; } - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - UpdateFilePathIndexToPidAndIpMap(symbolAndFilePathIndex.filePathIndex, pid, ip); - return symbolAndFilePathIndex; + pidAndIpToEbpfSymbolInfo_.Insert(pid, ip, ebpfSymbolInfo); + UpdateFilePathIndexToPidAndIpMap(ebpfSymbolInfo.filePathIndex, pid, ip); + return ebpfSymbolInfo; } DataIndex EbpfBase::ConvertToHexTextIndex(uint64_t number) @@ -191,70 +192,24 @@ void EbpfBase::UpdateFilePathIndexAndStValueToSymAddrMap(T* firstSymbolAddr, con } } } -bool EbpfBase::EBPFReloadElfSymbolTable(std::shared_ptr>> elfSymbolTables) +bool EbpfBase::EBPFReloadElfSymbolTable(const std::vector>& symbolsFiles) { - std::set> resymbolizationPidAndIps; - for (auto elfSymbolTable : *elfSymbolTables) { - auto filePathIndex = elfSymbolTable->filePathIndex; - if (!filePathIndexToPidAndIpMap_.count(filePathIndex)) { - TS_LOGI("ebpf do not support resymbolizaiton use %s", - traceDataCache_->GetDataFromDict(filePathIndex).c_str()); - continue; - } - - uint32_t pid = INVALID_UINT32; - uint64_t ip = INVALID_UINT64; - auto pidAndIpSet = filePathIndexToPidAndIpMap_.at(filePathIndex); - for (auto itor = pidAndIpSet->begin(); itor != pidAndIpSet->end(); itor++) { - std::tie(pid, ip) = *itor; - // only userspace ips need re symbolization - if (ip >= reader_->minKernelAddr_ && ip < reader_->maxKernelAddr_) { + auto ebpfCallStackDate = traceDataCache_->GetEbpfCallStack(); + auto size = ebpfCallStackDate->Size(); + auto filePathIndexs = ebpfCallStackDate->FilePathIds(); + auto vaddrs = ebpfCallStackDate->Vaddrs(); + for (const auto& symbolsFile : symbolsFiles) { + auto filePathIndex = traceDataCache_->GetDataIndex(symbolsFile->filePath_); + for (size_t row = 0; row < size; row++) { + if (filePathIndexs[row] != filePathIndex) { continue; } - // delete symbolization result - pidAndIpToSymbolAndFilePathIndex_.Erase(pid, ip); - // update pids and ips which needs resymbolization - resymbolizationPidAndIps.insert(std::make_tuple(pid, ip)); - } - // Update Symbolized Auxiliary Data - auto symEntrySize = elfSymbolTable->symEntSize; - auto size = elfSymbolTable->symTable.size() / symEntrySize; - if (symEntrySize == ELF32_SYM) { - UpdateFilePathIndexAndStValueToSymAddrMap( - reinterpret_cast(elfSymbolTable->symTable.data()), size, filePathIndex); - } else { - UpdateFilePathIndexAndStValueToSymAddrMap( - reinterpret_cast(elfSymbolTable->symTable.data()), size, filePathIndex); - } - if (filePathIndexToImportSymbolTableMap_.count(filePathIndex)) { - filePathIndexToImportSymbolTableMap_.at(filePathIndex) = elfSymbolTable; - } else { - filePathIndexToImportSymbolTableMap_.emplace(std::make_pair(filePathIndex, elfSymbolTable)); - } - } - OfflineSymbolization(resymbolizationPidAndIps); - // Update Resymbolization Results - auto ebpfCallStack = traceDataCache_->GetEbpfCallStack(); - for (auto i = 0; i < ebpfCallStack->Size(); i++) { - auto ipStrIndex = ebpfCallStack->Ips()[i]; - if (!ipStrIndexToIpMap_.count(ipStrIndex)) { - continue; - } - auto ip = ipStrIndexToIpMap_.at(ipStrIndex); - auto callId = ebpfCallStack->CallChainIds()[i]; - if (callId == INVALID_UINT32) { - continue; - } - if (!callIdToPid_.count(callId)) { - continue; - } - auto pid = callIdToPid_.at(callId); - auto symbolAndFilePathIndex = pidAndIpToSymbolAndFilePathIndex_.Find(pid, ip); - if (!symbolAndFilePathIndex.flag) { - continue; + auto dfxSymbol = symbolsFile->GetSymbolWithVaddr(vaddrs[row]); + if (dfxSymbol.IsValid()) { + auto symbolIndex = traceDataCache_->GetDataIndex(dfxSymbol.GetName()); + ebpfCallStackDate->UpdateEbpfSymbolInfo(row, symbolIndex); + } } - ebpfCallStack->UpdateSymbolAndFilePathIndex(i, symbolAndFilePathIndex.symbolIndex, - symbolAndFilePathIndex.filePathIndex); } return true; } @@ -266,79 +221,5 @@ void EbpfBase::GetSymbolStartIndex(T* elfSym, uint32_t& symbolStart, uint64_t sy symbolStart = elfSym->st_name; } } -void EbpfBase::OfflineSymbolization(std::set>& pidAndIps) -{ - uint32_t pid = INVALID_UINT32; - uint64_t ip = INVALID_UINT64; - for (auto itor = pidAndIps.begin(); itor != pidAndIps.end(); itor++) { - SymbolAndFilePathIndex symbolAndFilePathIndex(false); - std::tie(pid, ip) = *itor; - auto startToMapsAddr = reader_->GetPidAndStartAddrToMapsAddr().Find(pid); - if (!startToMapsAddr) { - continue; - } - uint64_t vmStart = INVALID_UINT64; - uint64_t vmOffset = INVALID_UINT64; - auto end = startToMapsAddr->upper_bound(ip); - auto length = std::distance(startToMapsAddr->begin(), end); - DataIndex filePathIndex = INVALID_DATAINDEX; - if (length > 0) { - end--; - // Follow the rules of front closing and rear opening, [start, end) - if (ip < end->second->end) { - vmStart = end->first; - vmOffset = end->second->offset; - filePathIndex = traceDataCache_->GetDataIndex(reinterpret_cast((end->second) + 1)); - } - } - symbolAndFilePathIndex.flag = true; - symbolAndFilePathIndex.filePathIndex = filePathIndex; - if (!filePathIndexToImportSymbolTableMap_.count(filePathIndex)) { - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - TS_LOGD("can not find matching symbol table!"); - continue; - } - auto& symbolTable = filePathIndexToImportSymbolTableMap_.at(filePathIndex); - // Calculate virtual address - uint64_t symVaddr = ip - vmStart + vmOffset + symbolTable->textVaddr - symbolTable->textOffset; - // pase sym_table to Elf32_Sym or Elf64_Sym array decided by sym_entry_size. - auto symEntLen = symbolTable->symEntSize; - auto startValueToSymAddrMap = filePathIndexAndStValueToSymAddr_.Find(filePathIndex); - if (!startValueToSymAddrMap) { - // find matching SymbolTable failed, but symVaddr is availiable - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - // find symbolTable failed!!! - TS_LOGD("find symbolTalbe failed!!!"); - continue; - } - // Traverse array, st_value <= symVaddr and symVaddr <= st_value + st_size. then you can get st_name - auto endItor = startValueToSymAddrMap->upper_bound(symVaddr); - length = std::distance(startValueToSymAddrMap->begin(), endItor); - uint32_t symbolStart = INVALID_UINT32; - if (length > 0) { - endItor--; - if (symEntLen == ELF32_SYM) { - GetSymbolStartIndex(reinterpret_cast(endItor->second), symbolStart, symVaddr); - } else { - GetSymbolStartIndex(reinterpret_cast(endItor->second), symbolStart, symVaddr); - } - } - if (symbolStart == INVALID_UINT32 || symbolStart >= symbolTable->strTable.size()) { - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - // find symbolStart failed, but some data is availiable. - TS_LOGD("symbolStart is : %lu invaliable!!!", symbolStart); - continue; - } - auto mangle = symbolTable->strTable.c_str() + symbolStart; - auto demangle = GetDemangleSymbolIndex(mangle); - symbolAndFilePathIndex.symbolIndex = traceDataCache_->GetDataIndex(demangle); - if (demangle != mangle) { - free(demangle); - } - pidAndIpToSymbolAndFilePathIndex_.Insert(pid, ip, symbolAndFilePathIndex); - } - filePathIndexAndStValueToSymAddr_.Clear(); - filePathIndexToImportSymbolTableMap_.clear(); -} } // namespace TraceStreamer } // namespace SysTuning diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_base.h b/trace_streamer/src/parser/ebpf_parser/ebpf_base.h index d9c2af724d73c297b00f71844bf49476b25ec29a..fc429679acc0910ccd8e2297c7be48073b622362 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_base.h +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_base.h @@ -23,35 +23,36 @@ #include "event_parser_base.h" #include "string_help.h" #include "string_to_numerical.h" +#include "symbols_file.h" #include "ts_common.h" namespace SysTuning { namespace TraceStreamer { using namespace SysTuning::base; using namespace SysTuning::EbpfStdtype; +using namespace OHOS::Developtools::HiPerf; class EbpfBase : virtual public EventParserBase { public: EbpfBase(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); ~EbpfBase(); bool InitEbpfDataParser(EbpfDataReader* reader); - bool EBPFReloadElfSymbolTable(std::shared_ptr>> elfSymbolTables); + bool EBPFReloadElfSymbolTable(const std::vector>& symbolsFiles); protected: void ParseCallStackData(const uint64_t* userIpsAddr, uint16_t count, uint32_t pid, uint32_t callId); DataIndex GetSymbolNameIndexFromSymVaddr(const ElfEventFixedHeader* elfHeaderAddr, uint64_t symVaddr); - SymbolAndFilePathIndex GetSymbolAndFilePathIndex(uint32_t pid, uint64_t ip); - SymbolAndFilePathIndex GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip); + EbpfSymbolInfo GetEbpfSymbolInfo(uint32_t pid, uint64_t ip); + EbpfSymbolInfo GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip); void UpdateFilePathIndexToPidAndIpMap(DataIndex filePathIndex, uint32_t pid, uint64_t ip); DataIndex ConvertToHexTextIndex(uint64_t number); template void UpdateFilePathIndexAndStValueToSymAddrMap(T* firstSymbolAddr, const int size, uint32_t filePathIndex); template void GetSymbolStartIndex(T* elfSym, uint32_t& symbolStart, uint64_t symVaddr); - void OfflineSymbolization(std::set>& pidAndIps); ClockId clockId_ = INVALID_UINT32; std::hash hashFun_; EbpfDataReader* reader_ = nullptr; - DoubleMap pidAndIpToSymbolAndFilePathIndex_; + DoubleMap pidAndIpToEbpfSymbolInfo_; std::map>>> filePathIndexToPidAndIpMap_ = {}; std::map ipStrIndexToIpMap_ = {}; std::map callIdToPid_ = {}; diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.cpp b/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.cpp index 4a1b9d0706ec5b623312b2b6f0ef75585e23b74b..c31f6854f75cba2201d07f81f790f92270594b58 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.cpp +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.cpp @@ -338,26 +338,28 @@ QuatraMap& EbpfDataReader::Ge return tracerEventToStrIndex_; } -SymbolAndFilePathIndex EbpfDataReader::GetSymbolNameIndexFromElfSym(uint64_t ip) +EbpfSymbolInfo EbpfDataReader::GetSymbolNameIndexFromElfSym(uint64_t ip) { - SymbolAndFilePathIndex symbolAndFilePathIndex(false); + EbpfSymbolInfo ebpfSymbolInfo(false); auto end = kernelSymbolMap_.upper_bound(ip); auto length = std::distance(kernelSymbolMap_.begin(), end); if (length > 0) { end--; // Follow the rules of front closing and rear opening, [start, end) if (ip < end->first + end->second.size) { - symbolAndFilePathIndex.flag = true; - symbolAndFilePathIndex.symbolIndex = end->second.name; - symbolAndFilePathIndex.filePathIndex = kernelFilePath_; + ebpfSymbolInfo.flag = true; + ebpfSymbolInfo.symbolIndex = end->second.name; + ebpfSymbolInfo.filePathIndex = kernelFilePath_; } else { - TS_LOGD("failed for ip:%lu, kernelip:%lu, size:%lu", ip, end->first, end->second.size); + TS_LOGD("failed for ip:%" PRIu64 ", kernelip:%" PRIu64 + ", size:%" PRIu64 "", + ip, end->first, end->second.size); } } - if (!symbolAndFilePathIndex.flag) { - TS_LOGD("failed for ip:%lu", ip); + if (!ebpfSymbolInfo.flag) { + TS_LOGD("failed for ip:%" PRIu64 "", ip); } - return symbolAndFilePathIndex; + return ebpfSymbolInfo; } const DoubleMap& EbpfDataReader::GetPidAndStartAddrToMapsAddr() const { diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.h b/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.h index 52375b315871d32d89c0224d092ad233ed1bed1d..20ad38a35d4c6286753e6692b8c5338137522ca2 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.h +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_data_reader.h @@ -15,7 +15,7 @@ #ifndef EBPF_DATA_READER_H #define EBPF_DATA_READER_H -#if is_mingw +#ifndef is_linux #include "dfx_nonlinux_define.h" #else #include @@ -46,7 +46,7 @@ public: const DoubleMap& GetElfAddrAndStartValueToSymAddr() const; const std::map& GetElfPathIndexToElfAddr() const; QuatraMap& GetTracerEventToStrIndexMap(); - SymbolAndFilePathIndex GetSymbolNameIndexFromElfSym(uint64_t ip); + EbpfSymbolInfo GetSymbolNameIndexFromElfSym(uint64_t ip); private: bool ReadEbpfData(); diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp index cc6975acd796e88a32f3eb71008c99c7e502fdce..e14c3c7163abd0065b04c3b888de8946cfe77537 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp @@ -30,7 +30,7 @@ void EbpfSplitter::SetSpliteTimeRange(uint64_t splitFileMinTs, uint64_t splitFil { splitFileMinTs_ = splitFileMinTs; splitFileMaxTs_ = splitFileMaxTs; - TS_LOGE("splitFileMinTs_ = %llu, splitFileMaxTs_ = %llu", splitFileMinTs_, splitFileMaxTs_); + TS_LOGI("splitFileMinTs_ = %" PRIu64 ", splitFileMaxTs_ = %" PRIu64 "", splitFileMinTs_, splitFileMaxTs_); } bool EbpfSplitter::SplitEbpfHeader(std::deque& dequeBuffer) { diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h index 99c81528746d2963cd9219b8a76ed31ace5d0158..a795b3578dbb07ee1d05ac64f8e4c98a125655e6 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h @@ -15,7 +15,7 @@ #ifndef EBPF_SPLITTER_H #define EBPF_SPLITTER_H -#if is_mingw +#ifndef is_linux #include "dfx_nonlinux_define.h" #else #include diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_stdtype.h b/trace_streamer/src/parser/ebpf_parser/ebpf_stdtype.h index a3b6f3a86ab4076ed2eadc77d0df4ea1f015f0ec..14e950df54b38d75118f1d89a363fa76f5d12784 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_stdtype.h +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_stdtype.h @@ -14,7 +14,7 @@ */ #ifndef EBPF_DATA_STD_TYPE_H #define EBPF_DATA_STD_TYPE_H -#if is_mingw +#ifndef is_linux #include "dfx_nonlinux_define.h" #else #include @@ -168,12 +168,13 @@ const std::map ebpfToTSClockType_ = { {EBPF_CLOCK_MONOTONIC_RAW, TS_MONOTONIC_RAW}, }; -struct SymbolAndFilePathIndex { - SymbolAndFilePathIndex() {} - explicit SymbolAndFilePathIndex(bool invalidValue) : flag(invalidValue) {} +struct EbpfSymbolInfo { + EbpfSymbolInfo() {} + explicit EbpfSymbolInfo(bool invalidValue) : flag(invalidValue) {} bool flag = false; DataIndex symbolIndex = INVALID_UINT64; DataIndex filePathIndex = INVALID_UINT64; + DataIndex vaddr = INVALID_UINT64; }; // file system event type enum FUC_SUB_TYPE { diff --git a/trace_streamer/src/parser/htrace_pbreader_parser/htrace_parser.cpp b/trace_streamer/src/parser/htrace_pbreader_parser/htrace_parser.cpp index d1d4dfb1141656978920b96969637d21b401d3ae..e0edb2d22a881616fcab1f0aa3427acbc7e99993 100644 --- a/trace_streamer/src/parser/htrace_pbreader_parser/htrace_parser.cpp +++ b/trace_streamer/src/parser/htrace_pbreader_parser/htrace_parser.cpp @@ -85,6 +85,10 @@ bool HtraceParser::ReparseSymbolFilesAndResymbolization(std::string& symbolsPath htraceNativeHookParser_->NativeHookReloadElfSymbolTable(symbolsFiles_); parseStatus = true; } + if (traceDataCache_->GetEbpfCallStack()->Size() > 0) { + ebpfDataParser_->EBPFReloadElfSymbolTable(symbolsFiles_); + parseStatus = true; + } symbolsFiles_.clear(); return parseStatus; } diff --git a/trace_streamer/src/parser/print_event_parser.cpp b/trace_streamer/src/parser/print_event_parser.cpp index 901ea13f8cd4c45645c942db4652f2063ebd727f..1e1bb5c7301f4ca216639b6bd8c04a9e71110848 100644 --- a/trace_streamer/src/parser/print_event_parser.cpp +++ b/trace_streamer/src/parser/print_event_parser.cpp @@ -361,10 +361,8 @@ void PrintEventParser::HandleFrameSliceEndEvent(uint64_t ts, uint64_t pid, uint6 auto iTid = streamFilters_->processFilter_->GetInternalTid(tid); auto pos = std::find(vsyncSliceIds_.begin(), vsyncSliceIds_.end(), callStackRow); if (pos != vsyncSliceIds_.end()) { - TS_LOGD("ts:%" PRIu64 ", RenderSliceEnd:%" PRIu64 ", callStackRow:%zu", ts, tid, callStackRow); if (!streamFilters_->frameFilter_->EndVsyncEvent(ts, iTid)) { streamFilters_->statFilter_->IncreaseStat(TRACE_VSYNC, STAT_EVENT_NOTMATCH); - TS_LOGW("ts:%" PRIu64 ", RenderSliceEnd:%" PRIu64 ", callStackRow:%zu failed", ts, tid, callStackRow); } vsyncSliceIds_.erase(pos); } diff --git a/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp b/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp index 3059c3ded842436588155e99929209f2f9d71bd9..c8ad2ccbf39119d212dcee2c5ee1c6af91811e0d 100644 --- a/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp +++ b/trace_streamer/src/parser/rawtrace_parser/cpu_detail_parser.cpp @@ -316,7 +316,7 @@ bool CpuDetailParser::BinderTractionAllocBufEvent(const RawTraceEventInfo& event streamFilters_->statFilter_->IncreaseStat(TRACE_EVENT_BINDER_TRANSACTION_ALLOC_BUF, STAT_EVENT_RECEIVED); streamFilters_->binderFilter_->TransactionAllocBuf(event.msgPtr->timestamp(), eventTid_, allocBufMsg.data_size(), allocBufMsg.offsets_size()); - TS_LOGD("dataSize:%lu, offsetSize:%lu", allocBufMsg.data_size(), allocBufMsg.offsets_size()); + TS_LOGD("dataSize:%" PRIu64 ", offsetSize:%" PRIu64 "", allocBufMsg.data_size(), allocBufMsg.offsets_size()); return true; } bool CpuDetailParser::BinderTractionReceivedEvent(const RawTraceEventInfo& event) const diff --git a/trace_streamer/src/rpc/rpc_server.cpp b/trace_streamer/src/rpc/rpc_server.cpp index 46601265c738b72953b5ad41896fbbde3e2764c2..f61e4b160ff4a158ca05976c2d3d9259a1ce62c2 100644 --- a/trace_streamer/src/rpc/rpc_server.cpp +++ b/trace_streamer/src/rpc/rpc_server.cpp @@ -330,9 +330,6 @@ bool RpcServer::ParseDataOver(const uint8_t* data, size_t len, ResultCallBack re metaData->SetTraceType((ts_->DataType() == TRACE_FILETYPE_H_TRACE) ? "proto-based-trace" : "txt-based-trace"); TS_LOGI("RPC ParseDataOver, has parsed len %zu", lenParseData_); ts_->WaitForParserEnd(); -#ifndef USE_VTABLE - ts_->Clear(); -#endif if (resultCallBack) { resultCallBack("ok\r\n", SEND_FINISH); } diff --git a/trace_streamer/src/trace_data/trace_data_cache.cpp b/trace_streamer/src/trace_data/trace_data_cache.cpp index 1d61306bb306ba6c8d7d0d514e6c6866913a21eb..5637f671be133fb348c845f8deb983b95df5e1c0 100644 --- a/trace_streamer/src/trace_data/trace_data_cache.cpp +++ b/trace_streamer/src/trace_data/trace_data_cache.cpp @@ -128,7 +128,6 @@ void TraceDataCache::InitDB() if (dbInited_) { return; } -#ifdef USE_VTABLE TableBase::TableDeclare(*db_, this, "animation"); TableBase::TableDeclare(*db_, this, "dynamic_frame"); TableBase::TableDeclare(*db_, this, "process"); @@ -223,100 +222,6 @@ void TraceDataCache::InitDB() TableBase::TableDeclare(*db_, this, "perf_callchain"); TableBase::TableDeclare(*db_, this, "perf_thread"); TableBase::TableDeclare(*db_, this, "perf_files"); -#else - TableBase::TableDeclare(*db_, this, "_animation"); - TableBase::TableDeclare(*db_, this, "_dynamic_frame"); - TableBase::TableDeclare(*db_, this, "_process"); - TableBase::TableDeclare(*db_, this, "_sched_slice"); - TableBase::TableDeclare(*db_, this, "_callstack"); - TableBase::TableDeclare(*db_, this, "_thread"); - TableBase::TableDeclare(*db_, this, "_thread_state"); - TableBase::TableDeclare(*db_, this, "_thread_filter"); - TableBase::TableDeclare(*db_, this, "_process_filter"); - TableBase::TableDeclare(*db_, this, "_measure_filter"); - TableBase::TableDeclare(*db_, this, "_irq"); - TableBase::TableDeclare(*db_, this, "_data_dict"); - TableBase::TableDeclare(*db_, this, "_raw"); - TableBase::TableDeclare(*db_, this, "_symbols"); - TableBase::TableDeclare(*db_, this, "_data_type"); - TableBase::TableDeclare(*db_, this, "_hidump"); - TableBase::TableDeclare(*db_, this, "_native_hook"); - TableBase::TableDeclare(*db_, this, "_native_hook_frame"); - TableBase::TableDeclare(*db_, this, "_native_hook_statistic"); - TableBase::TableDeclare(*db_, this, "_span_join"); - - // no id - TableBase::TableDeclare(*db_, this, "_device_info"); - TableBase::TableDeclare(*db_, this, "_instant"); - TableBase::TableDeclare(*db_, this, "_measure"); - TableBase::TableDeclare(*db_, this, "_sys_mem_measure"); - TableBase::TableDeclare(*db_, this, "_process_measure"); - TableBase::TableDeclare(*db_, this, "_trace_range"); - TableBase::TableDeclare(*db_, this, "_stat"); - TableBase::TableDeclare(*db_, this, "_syscall"); - TableBase::TableDeclare(*db_, this, "_meta"); - TableBase::TableDeclare(*db_, this, "_log"); - TableBase::TableDeclare(*db_, this, "_network"); - - // id is not real id - TableBase::TableDeclare(*db_, this, "_cpu_measure_filter"); - TableBase::TableDeclare(*db_, this, "_measure_filter"); - TableBase::TableDeclare(*db_, this, "_process_measure_filter"); - TableBase::TableDeclare(*db_, this, "_clock_event_filter"); - TableBase::TableDeclare(*db_, this, "_clk_event_filter"); - TableBase::TableDeclare(*db_, this, "_task_pool"); - TableBase::TableDeclare(*db_, this, "_js_heap_files"); - TableBase::TableDeclare(*db_, this, "_js_heap_edges"); - TableBase::TableDeclare(*db_, this, "_js_heap_info"); - TableBase::TableDeclare(*db_, this, "_js_heap_location"); - TableBase::TableDeclare(*db_, this, "_js_heap_nodes"); - TableBase::TableDeclare(*db_, this, "_js_heap_sample"); - TableBase::TableDeclare(*db_, this, "_js_heap_string"); - TableBase::TableDeclare(*db_, this, "_js_heap_trace_function_info"); - TableBase::TableDeclare(*db_, this, "_js_heap_trace_node"); - TableBase::TableDeclare(*db_, this, "_js_cpu_Perfiler_Node"); - TableBase::TableDeclare(*db_, this, "_js_cpu_Perfiler_Sample"); - TableBase::TableDeclare(*db_, this, "_js_config"); - TableBase::TableDeclare(*db_, this, "_args"); - TableBase::TableDeclare(*db_, this, "_sys_event_filter"); - TableBase::TableDeclare(*db_, this, "_diskio"); - TableBase::TableDeclare(*db_, this, "_cpu_usage"); - TableBase::TableDeclare(*db_, this, "_live_process"); - TableBase::TableDeclare(*db_, this, "_file_system_sample"); - TableBase::TableDeclare(*db_, this, "_ebpf_callstack"); - TableBase::TableDeclare(*db_, this, "_paged_memory_sample"); - TableBase::TableDeclare(*db_, this, "_smaps"); - TableBase::TableDeclare(*db_, this, "_bio_latency_sample"); - TableBase::TableDeclare(*db_, this, "_datasource_clockid"); - TableBase::TableDeclare(*db_, this, "_clock_snapshot"); - TableBase::TableDeclare(*db_, this, "_frame_slice"); - TableBase::TableDeclare(*db_, this, "_frame_maps"); - TableBase::TableDeclare(*db_, this, "_gpu_slice"); - TableBase::TableDeclare(*db_, this, "_app_startup"); - TableBase::TableDeclare(*db_, this, "_static_initalize"); - TableBase::TableDeclare(*db_, this, "_memory_ashmem"); - TableBase::TableDeclare(*db_, this, "_memory_dma"); - TableBase::TableDeclare(*db_, this, "_memory_process_gpu"); - TableBase::TableDeclare(*db_, this, "_memory_window_gpu"); - TableBase::TableDeclare(*db_, this, "_memory_cpu"); - TableBase::TableDeclare(*db_, this, "_memory_profile"); - TableBase::TableDeclare(*db_, this, "_memory_rs_image"); -#if WITH_EBPF_HELP - TableBase::TableDeclare(*db_, this, "_ebpf_process_maps"); - TableBase::TableDeclare(*db_, this, "_ebpf_elf"); - TableBase::TableDeclare(*db_, this, "_ebpf_elf_symbol"); -#endif - TableBase::TableDeclare(*db_, this, "_app_name"); - TableBase::TableDeclare(*db_, this, "_hisys_event_measure"); - TableBase::TableDeclare(*db_, this, "_hisys_all_event"); - TableBase::TableDeclare(*db_, this, "_device_state"); - TableBase::TableDeclare(*db_, this, "_trace_config"); - TableBase::TableDeclare(*db_, this, "_perf_report"); - TableBase::TableDeclare(*db_, this, "_perf_sample"); - TableBase::TableDeclare(*db_, this, "_perf_callchain"); - TableBase::TableDeclare(*db_, this, "_perf_thread"); - TableBase::TableDeclare(*db_, this, "_perf_files"); -#endif dbInited_ = true; } bool TraceDataCache::AnimationTraceEnabled() const @@ -385,7 +290,7 @@ int32_t TraceDataCache::ExportPerfReadableText(const std::string& outputName, TS_CHECK_TRUE(ftruncate(fd, 0) != -1, 1, "Failed to ftruncate file: %s, err:%s", outputName.c_str(), strerror(errno)); #endif - fprintf(stdout, "ExportPerfReadableText begin...\n"); + TS_LOGI("ExportPerfReadableText begin...\n"); uint8_t curTimePrecision = 6; std::string buffLine; for (uint64_t row = 0; row < perfSample_.Size(); ++row) { @@ -422,7 +327,7 @@ int32_t TraceDataCache::ExportPerfReadableText(const std::string& outputName, #endif buffLine.clear(); } - fprintf(stdout, "ExportPerfReadableText end...\n"); + TS_LOGI("ExportPerfReadableText end...\n"); return 0; } void TraceDataCache::ExportPerfCallChaninText(uint32_t callChainId, std::string& buffLine) diff --git a/trace_streamer/src/trace_data/trace_data_db.cpp b/trace_streamer/src/trace_data/trace_data_db.cpp index 2c8c58a6ac5cd8a37f464bc645c79fe6b4ebdced..ec1bc1908fbfd239efb5522819c3cc4be2ed4e07 100644 --- a/trace_streamer/src/trace_data/trace_data_db.cpp +++ b/trace_streamer/src/trace_data/trace_data_db.cpp @@ -118,22 +118,12 @@ int32_t TraceDataDB::ExportDatabase(const std::string& outputName, ResultCallBac ExecuteSql(attachSql); for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { -#ifndef USE_VTABLE - if (*itor == "_meta" && !exportMetaTable_) { - continue; - } else { - std::string exportSql("CREATE TABLE systuning_export." + (*itor).substr(1, -1) + " AS SELECT * FROM " + - *itor); - ExecuteSql(exportSql); - } -#else if (*itor == "meta" && !exportMetaTable_) { continue; } else { std::string exportSql("CREATE TABLE systuning_export." + (*itor) + " AS SELECT * FROM " + *itor); ExecuteSql(exportSql); } -#endif } std::string createArgsView = "create view systuning_export.args_view AS select A.argset, V2.data as keyName, A.id, D.desc, (case when " @@ -160,12 +150,6 @@ void TraceDataDB::Prepare() return; } pared_ = true; -#ifndef USE_VTABLE - for (auto itor = internalTables_.begin(); itor != internalTables_.end(); itor++) { - std::string exportSql("CREATE TABLE " + (*itor).substr(1, -1) + " AS SELECT * FROM " + *itor); - ExecuteSql(exportSql); - } -#endif ExecuteSql( "update thread set ipid = \ (select id from process where \ diff --git a/trace_streamer/src/trace_data/trace_stdtype.cpp b/trace_streamer/src/trace_data/trace_stdtype.cpp index 034696740d244ba286dd3016ff63faebf2e0f471..ca5ca005db1f3626e8bd0e7d4ed45c8c59cc91e6 100644 --- a/trace_streamer/src/trace_data/trace_stdtype.cpp +++ b/trace_streamer/src/trace_data/trace_stdtype.cpp @@ -1651,24 +1651,25 @@ size_t EbpfCallStackData::AppendNewData(uint32_t callChainId, uint32_t depth, DataIndex ip, DataIndex symbolId, - DataIndex filePathId) + DataIndex filePathId, + uint64_t vaddr) { callChainIds_.emplace_back(callChainId); depths_.emplace_back(depth); ips_.emplace_back(ip); symbolIds_.emplace_back(symbolId); filePathIds_.emplace_back(filePathId); + vaddrs_.emplace_back(vaddr); ids_.emplace_back(Size()); return Size() - 1; } -void EbpfCallStackData::UpdateSymbolAndFilePathIndex(size_t row, DataIndex symbolId, DataIndex filePathId) +void EbpfCallStackData::UpdateEbpfSymbolInfo(size_t row, DataIndex symbolId) { if (row >= Size()) { TS_LOGE("The updated row does not exist!"); return; } symbolIds_[row] = symbolId; - filePathIds_[row] = filePathId; } const std::deque& EbpfCallStackData::CallChainIds() const { @@ -1690,6 +1691,10 @@ const std::deque& EbpfCallStackData::FilePathIds() const { return filePathIds_; } +const std::deque& EbpfCallStackData::Vaddrs() const +{ + return vaddrs_; +} #if WITH_EBPF_HELP size_t EbpfProcessMaps::AppendNewData(uint64_t start, uint64_t end, diff --git a/trace_streamer/src/trace_data/trace_stdtype.h b/trace_streamer/src/trace_data/trace_stdtype.h index c54894ca79ddc4f99a2f3840854a6cb7873e2324..d21ed6654e820e04dceacbb690092414a0b490bc 100644 --- a/trace_streamer/src/trace_data/trace_stdtype.h +++ b/trace_streamer/src/trace_data/trace_stdtype.h @@ -1377,13 +1377,19 @@ private: }; class EbpfCallStackData : public CacheBase { public: - size_t AppendNewData(uint32_t callChainId, uint32_t depth, DataIndex ip, DataIndex symbolId, DataIndex filePathId); - void UpdateSymbolAndFilePathIndex(size_t row, DataIndex symbolId, DataIndex filePathId); + size_t AppendNewData(uint32_t callChainId, + uint32_t depth, + DataIndex ip, + DataIndex symbolId, + DataIndex filePathId, + uint64_t vaddr); + void UpdateEbpfSymbolInfo(size_t row, DataIndex symbolId); const std::deque& CallChainIds() const; const std::deque& Depths() const; const std::deque& Ips() const; const std::deque& SymbolIds() const; const std::deque& FilePathIds() const; + const std::deque& Vaddrs() const; void Clear() override { CacheBase::Clear(); @@ -1391,6 +1397,7 @@ public: depths_.clear(); symbolIds_.clear(); filePathIds_.clear(); + vaddrs_.clear(); } private: @@ -1399,6 +1406,7 @@ private: std::deque ips_ = {}; std::deque symbolIds_ = {}; std::deque filePathIds_ = {}; + std::deque vaddrs_ = {}; }; class PagedMemorySampleData : public CacheBase { public: diff --git a/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp b/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp index 0a56304ba64f6ab4e62290ae0c943c8826c08a4a..80e267898b972606f1ef1b0fc483a1262c7e3016 100644 --- a/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp +++ b/trace_streamer/src/trace_streamer/trace_streamer_selector.cpp @@ -278,7 +278,7 @@ void TraceStreamerSelector::EnableFileSave(bool enabled) void TraceStreamerSelector::SetCleanMode(bool cleanMode) { - g_cleanMode = true; + g_curLogLevel = LOG_OFF; } int32_t TraceStreamerSelector::ExportDatabase(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack) @@ -420,7 +420,6 @@ bool TraceStreamerSelector::ReadSqlFileAndPrintResult(const std::string& sqlOper if (!LoadQueryFile(sqlOperator, sqlStrings)) { return false; } - system("clear"); for (auto& str : sqlStrings) { SearchDatabase(str, true); } @@ -428,7 +427,6 @@ bool TraceStreamerSelector::ReadSqlFileAndPrintResult(const std::string& sqlOper } bool TraceStreamerSelector::ParserAndPrintMetrics(const std::string& metrics) { - system("clear"); auto metricsName = SplitStringToVec(metrics, ","); for (const auto& itemName : metricsName) { std::string result = SearchDatabase(MetricsSqlQuery(itemName));